Vertica - Multi Execute

In this article

Snap type:

Write

Description:

This Snap allows you to execute multiple SQL statements for each document. Each set of statements is executed as one transaction (per document).
The Snap will substitute values from an incoming document into the SQL statement if it finds a JSONPath substring in the statement. If a substitution value is missing in the incoming document then the document will be written to an error view.

  • Multiple documents cannot be executed as part of one transaction; the relationship is one transaction per document.
  • The account being used must have auto commit set to false, otherwise the Snap will fail with a configuration exception. You can drop your database with it, so be careful.


Expected downstream Snaps
: The Snap will output one document for every document retrieved, hence any document processing Snap can be used downstream. Each output document will provide information about the statements that were executed. Expected upstream Snaps: A Mapper Snap, which transforms the input data into the exact structure that is needed by each statement of the Snap.

Expected input: Document that conforms to variables needed for each statement.

Expected output: Document which provides information about the status of the execution, each statement is represented as an execution_<index>, where <index> is the row number in the Executions table. For convenience, each execution_<index> will provide the statement that was executed and the input data that was used to execute the statement.
 

Prerequisites:

N/A

Support and limitations:

Works in Ultra Task Pipelines.

Account: 

This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See Configuring Vertica Accounts for information on setting up this type of account.

Views:
InputThis Snap has exactly one input view.
OutputThis Snap has at most one output view.
Error

This Snap has at most one error view and produces zero or more documents in the view.

Database Write Snaps output all records of a batch (as configured in your account settings) to the error view if the write fails during batch processing.


Settings

Label


Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline.

Executions

Required. A list of statements that are executed as one transaction.

  Path


A JSONPath that returns a list or object from the input document.

Example: jsonPath($, "$ADJUSTMENTS[*]")

SQL Statement

A SQL statement that uses the result of the path as part of the statement substitution.

Examples: 

  • Insert into ADJUSTMENTS VALUES ($BUS_AREA_CD, $CR_FG, $FUNC_AREA_CD, $LGCL_DEL_FG, $MAIN_MCC_FG, $PR_EFF_DT, $SO_ADJ_AM, $SO_ADJ_CD)

Without using expressions

  • email = 'you@example.com' or email = $email 
  • emp=$emp

Using expressions

  • "EMPNO=$EMPNO and ENAME=$EMPNAME"
  • "emp='" + $emp + "'"
  • "EMPNO=" + $EMPNO + " and ENAME='" + $EMPNAME+ "'"

Caution

Using expressions that join strings together to create SQL queries or conditions has a potential SQL injection risk and hence unsafe. Ensure that you understand all implications and risks involved before using concatenation of strings with '=' Expression enabled. 

Single quotes in values must be escaped

Any relational database (RDBMS) treats single quotes (') as special symbols. So, single quotes in the data or values passed through a DML query may cause the Snap to fail when the query is executed. Ensure that you pass two consecutive single quotes in place of one single quote within the values to escape the single quote.

For example:

If String To pass this valueUse
Has no single quotes
Schaum Series
'Schaum Series'
Contains single quotes
O'Reilly's Publication
'O''Reilly''s Publication'
Number of retries

The maximum number of times that the process must be retried before displaying an error.

Example: 2

Default value: 0

Retry interval (seconds)

The maximum resting time in seconds between subsequent retries.

Example: 2

Default value: 1

Snap Execution

Select one of the three modes in which the Snap executes. Available options are:

  • Validate & Execute: Performs limited execution of the Snap, and generates a data preview during Pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during Pipeline runtime.
  • Execute only: Performs full execution of the Snap during Pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.


Examples


Example Input

[
  {
    "ORDER_DETAIL": { "SO_LN_ITM_NR": "000010", "SO_DTL_CRT_DT": "2014-02-12", "SO_DTL_CLOSE_DT": "2014-02-12", "FXD_VALU_DT": "2014-02-12", "ORD_LN_CNCL_DT": "" },
    "ADJUSTMENTS": [ { "SO_ADJ_CD": "ZNAJ", "SO_ADJ_AM": "0.00", "LGCL_DEL_FG": "N", "CR_FG": "N", "MAIN_MCC_FG": "", "BUS_AREA_CD": "9600", "FUNC_AREA_CD": "A051", "PR_EFF_DT": "" }, { "SO_ADJ_CD": "ZNAK", "SO_ADJ_AM": "0.00", "LGCL_DEL_FG": "N", "CR_FG": "N", "MAIN_MCC_FG": "", "BUS_AREA_CD": "9600", "FUNC_AREA_CD": "A051", "PR_EFF_DT": "" } ] }
]

In row one we select the adjustments; given the input, it returns a list of objects. The insert statement will then create a batch for every object in the list and execute it. In row two we select the order detail; given the input, it returns one object. The insert statement will then execute one statement using the order detail object.

The statement can use variables that are the result of the path execution. As an example, the below is the result of jsonPath($, "$ADJUSTMENTS[*]):
 {
        "SO_ADJ_CD": "ZNAJ",
        "SO_ADJ_AM": "0.00",
        "LGCL_DEL_FG": "N",
        "CR_FG": "N",
        "MAIN_MCC_FG": "",
        "BUS_AREA_CD": "9600",
        "FUNC_AREA_CD": "A051",
        "PR_EFF_DT": ""
      },
      {
        "SO_ADJ_CD": "ZNAK",
        "SO_ADJ_AM": "0.00",
        "LGCL_DEL_FG": "N",
        "CR_FG": "N",
        "MAIN_MCC_FG": "",
        "BUS_AREA_CD": "9600",
        "FUNC_AREA_CD": "A051",
        "PR_EFF_DT": ""
      }

The statement then refers to the variables of the result using, for example, $BUS_AREA_CD, not as one would assume the whole path to the variable in the context of the input document. jsonPath($, "$ADJUSTMENTS[*].BUS_AREA_CD), instead the context is the result of the path evaluation.

A successful execution of all statements will issue a commit of the transaction. Any failure of any of the statements will cause the rollback of all issues operations for the given input document.

A successful output:

[
  {
    "execution_1": { "status": "success", "sqlStatement": "Insert into ORDER_DETAIL VALUES (?, ?, ?, ?, ?)", "successfulDocuments": [ { "message": "success", "status": 1, "original": { "SO_LN_ITM_NR": "000010", "SO_DTL_CRT_DT": "2014-02-12", "SO_DTL_CLOSE_DT": "2014-02-12", "FXD_VALU_DT": "2014-02-12", "ORD_LN_CNCL_DT": "" } } ] },
    "execution_0": { "status": "success", "sqlStatement": "Insert into ADJUSTMENTS VALUES (?, ?, ?, ?, ?, ?, ?, ?)", "successfulDocuments": [ { "message": "success", "status": 2, "original": { "SO_ADJ_CD": "ZNAJ", "SO_ADJ_AM": "0.00", "LGCL_DEL_FG": "N", "CR_FG": "N", "MAIN_MCC_FG": "", "BUS_AREA_CD": "9600", "FUNC_AREA_CD": "A051", "PR_EFF_DT": "" } }, { "message": "success", "status": 2, "original": { "SO_ADJ_CD": "ZNAK", "SO_ADJ_AM": "0.00", "LGCL_DEL_FG": "N", "CR_FG": "N", "MAIN_MCC_FG": "", "BUS_AREA_CD": "9600", "FUNC_AREA_CD": "A051", "PR_EFF_DT": "" } } ] } }
]

One output document is written per input document. The output document provides executions, each reflecting the execution of one row. The index of the execution_<index> represents the index of the statement in the Executions table.
Each execution provides information about the statement execution. In the above case, all statements were successful. Original shows the data that was used as part of the statement execution (not the input document, but the data of the path evaluation).
The SQL statement shows the statement that was executed.

In an unsuccessful case, one can enable the error view to gain a better understanding of what went wrong:

[
  {
    "execution_1": { "status": "failed", "sqlStatement": "Insert into wrongname VALUES (?, ?, ?, ?, ?)", "errorDocuments": [ { "error": "Failed to flush batch.", "reason": "Table 'integration.wrongname' doesn't exist", "original": { "SO_LN_ITM_NR": "000010", "SO_DTL_CRT_DT": "2014-02-12", "SO_DTL_CLOSE_DT": "2014-02-12", "FXD_VALU_DT": "2014-02-12", "ORD_LN_CNCL_DT": "" }, "resolution": "Please address the issue reported by the database.", "stacktrace": "org.jooq.exception.DataAccessException: SQL [Insert into wrongname VALUES (?, ?, ?, ?, ?)]; Table 'integration.wrongname' doesn't exist\n...." } ] },
    "execution_0": { "status": "success", "sqlStatement": "Insert into ADJUSTMENTS VALUES (?, ?, ?, ?, ?, ?, ?, ?)", "successfulDocuments": [ { "message": "success", "status": 2, "original": { "SO_ADJ_CD": "ZNAJ", "SO_ADJ_AM": "0.00", "LGCL_DEL_FG": "N", "CR_FG": "N", "MAIN_MCC_FG": "", "BUS_AREA_CD": "9600", "FUNC_AREA_CD": "A051", "PR_EFF_DT": "" } }, { "message": "success", "status": 2, "original": { "SO_ADJ_CD": "ZNAK", "SO_ADJ_AM": "0.00", "LGCL_DEL_FG": "N", "CR_FG": "N", "MAIN_MCC_FG": "", "BUS_AREA_CD": "9600", "FUNC_AREA_CD": "A051", "PR_EFF_DT": "" } } ] } }
]


Here we see that execution_1 of the current input document failed. The reason and resolution are provided, as well as the stack trace for debugging purpose.

Download the sample pipeline.

 It depends on tables that need to be created by the user manually. The template by itself can not be executed successfully.

Snap Pack History

 Click to view/expand
Release Snap Pack VersionDateType  Updates
4.27main12833 Stable

Enhanced the Vertica - Execute Snap to invoke stored procedures.

4.26main11181 StableUpgraded with the latest SnapLogic Platform release.
4.25main9554
 
StableUpgraded with the latest SnapLogic Platform release.
4.24main8556
Stable

Enhanced the Vertica - Select Snap to return only the selected output fields or columns in the output schema (second output view) using the Fetch Output Fields In Schema check box. If the Output Fields field is empty all the columns are visible. 

4.23main7430
 
StableUpgraded with the latest SnapLogic Platform release.
4.22main6403
 
StableUpgraded with the latest SnapLogic Platform release.

4.21 Patch

421patches6272 Latest

Fixed the issue where Snowflake SCD2 Snap generates two output documents despite no changes to Cause-historization fields with DATE, TIME and TIMESTAMP Snowflake data types, and with Ignore unchanged rows field selected.

4.21 Patch

421patches6144 Latest

Fixed the following issues with DB Snaps:

  • The connection thread waits indefinitely causing the subsequent connection requests to become unresponsive.
  • Connection leaks occur during Pipeline execution.

4.21 Patch

MULTIPLE8841 Latest

Fixed the connection issue in Database Snaps by detecting and closing open connections after the Snap execution ends. 

4.21snapsmrc542

 

StableUpgraded with the latest SnapLogic Platform release.
4.20snapsmrc535
 
StableUpgraded with the latest SnapLogic Platform release.

4.19 Patch

vertica8415 Latest

Fixed an issue with the Vertica - Update Snap wherein the Snap is unable to perform operations when:

  • An expression is used in the Update condition property.
  • Input data contain the character '?'.
4.19snaprsmrc528
 
StableUpgraded with the latest SnapLogic Platform release.
4.18snapsmrc523
 
StableUpgraded with the latest SnapLogic Platform release.
4.17ALL7402
 
Latest

Pushed automatic rebuild of the latest version of each Snap Pack to SnapLogic UAT and Elastic servers.

4.17snapsmrc515
 
Latest
  • Fixed an issue with the Vertica Execute Snap wherein the Snap would send the input document to the output view even if the Pass through field is not selected in the Snap configuration. With this fix, the Snap sends the input document to the output view, under the key original, only if you select the Pass through field.
  • Added the Snap Execution field to all Standard-mode Snaps. In some Snaps, this field replaces the existing Execute during preview check box.

4.16 Patch

vertica6820 Latest

Fixed an issue with the Lookup Snap passing data simultaneously to output and error views when some values contained spaces at the end.

4.16snapsmrc508
 
StableUpgraded with the latest SnapLogic Platform release.

4.15 Patch 

db/vertica6339 Latest

Replaced Max idle time and Idle connection test period properties with Max life time and Idle Timeout properties respectively, in the Account configuration. The new properties fix the connection release issues that were occurring due to default/restricted DB Account settings.

4.15snapsmrc500
 
StableUpgraded with the latest SnapLogic Platform release.
4.14snapsmrc490
 
StableUpgraded with the latest SnapLogic Platform release.
4.13

snapsmrc486

 
StableUpgraded with the latest SnapLogic Platform release.
4.12

snapsmrc480

 
StableUpgraded with the latest SnapLogic Platform release.
4.11snapsmrc465
 
StableUpgraded with the latest SnapLogic Platform release.
4.10

snapsmrc414

 
Stable

Added Auto commit property to the Select and Execute Snaps at the Snap level to support overriding of the Auto commit property at the Account level.

4.9snapsmrc405
 
StableUpgraded with the latest SnapLogic Platform release.

4.8.0 Patch

vertica2796 Latest

Potential fix for JDBC deadlock issue.

4.8.0 Patch

vertica2716 Latest

Fixed Vertica Snap Pack rendering dates that are one hour off from the date returned by database query for non-UTC Snaplexes.

4.8

snapsmrc398

 
Stable
  • Info tab added to accounts.
  • Database accounts now invalidate connection pools if account properties are modified and login attempts fail.

4.7.0 Patch

vertica2511 Latest

Fixed NumberOverflow Execption for Integer Datatypes

4.7.0 Patch

vertica2205 Latest

Fixed an issue for database Select Snaps regarding Limit rows not supporting an empty string from a pipeline parameter.

4.7

snapsmrc382

 
StableUpgraded with the latest SnapLogic Platform release.
4.6snapsmrc362
 
Stable

Enhanced Vertica Execute Snap to fully support SQL statements with/without expressions & SQL bind variables.

4.5.1

snapsmrc344

 
LatestUpgraded with the latest SnapLogic Platform release.
4.5

snapsmrc344

 Stable

Resolved an issue in Vertica Bulk Upsert Snap that occurred during loading.

4.4.1N/A LatestUpgraded with the latest SnapLogic Platform release.
4.4N/A StableUpgraded with the latest SnapLogic Platform release.
4.3.2N/A Latest
  • Improved error handling for Vertica Bulk Load Snap.
  • Resolved a syntax error in Vertica Bulk Upsert.
  • Resolved several failures in the Vertica Insert Snap.
  • Resolved a "No column values found" error in Vertica Bulk Load.
  • Resolved a issue in Vertica Insert with Boolean values of "t" and "f" being inserted as null.
N/AN/A NA

Added Vertica Snap Pack: Vertica Multi Execute Snap (Beta) added.

N/AN/A NA

Fix log: Vertica Snap: Could not initialize Snap error is displayed.