AlloyDB Execute

Overview

You can use this Snap to execute arbitrary SQL.
Note: This Snap works only with single queries.


Limitations

Does not support $$ as an escape character for enclosing string input, as $ is a reserved character for variable substitution in SnapLogic.

Behavior changes

  • The following are the behavior changes caused by the JDBC driver upgrade for PostgreSQL Snap Pack and Google AlloyDB Snap Pack
  • Some error messages will now include the data type for certain values, for example:
    • Old: "...where (badId = 1) was aborted:..."

    • New:
      "...where (badId = ('1'::numeric)) was
          aborted:..."
  • There are some minor text changes to a few of the error messages, for example:
    • Old:
      "Hint: No operator matches the given name and argument
            types."
    • New:
      "Hint: No operator matches the given name and argument
          type(s)."

Snap views

View Description Examples of upstream and downstream Snaps
Input

If the input view is defined, then the WHERE clause can substitute incoming values for a given expression.

Valid JSON paths that are defined in the WHERE clause for queries or statements are substituted with values from an incoming document. If the document is missing a value to be substituted into the query or statement documents, it is written to the error view.

Output The executed query result. If a SELECT query is executed, the query's results are merged into the incoming document and any existing keys will have their values overwritten. On the other hand, the original document is written if there are no results from the query.
Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are:

  • Stop Pipeline Execution Stops the current pipeline execution when an error occurs.
  • Discard Error Data and Continue Ignores the error, discards that record, and continues with the remaining records.
  • Route Error Data to Error View Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap settings

Legend:
  • Expression icon (): Allows using pipeline parameters to set field values dynamically (if enabled). SnapLogic Expressions are not supported. If disabled, you can provide a static value.
  • SnapGPT (): Generates SnapLogic Expressions based on natural language using SnapGPT. Learn more.
  • Suggestion icon (): Populates a list of values dynamically based on your Snap configuration. You can select only one attribute at a time using the icon. Type into the field if it supports a comma-separated list of values.
  • Upload : Uploads files. Learn more.
Learn more about the icons in the Snap settings dialog.
Field / Field set Type Description
Label String

Required. Specify a unique name for the Snap. Modify this to be more appropriate, especially if more than one of the same Snaps is in the pipeline.

Default value: AlloyDB Execute

Example: AlloyDB Execute
SQL Statement String/Expression Required. Specify the SQL statement to execute on the server. We recommend you to add a single query in the SQL Statement field.
Note: Scenarios to successfully execute your SQL statements

You must understand the following scenarios to successfully execute your SQL statements:

Scenario 1: Executing SQL statements without expressionsIf the expression toggle of the SQL statement field is not selected:
  • The SQL statement must not be within quotes.

  • The $<variable_name> parts of the SQL statement are expressions. In the below example, $id and $book.

  • Additionally, the JSON path (e.g. $myName) is allowed only in the WHERE clause.

If the SQL statement starts with SELECT (case-insensitive), the Snap regards it as a select-type query and executes once per input document. If not, it regards it as write-type query and executes in batch mode.INSERT into SnapLogic.book (id, book) VALUES ($id,$book)

Scenario 2: Executing SQL queries with expressions Enable the expression toggle of the SQL statement field is selected:
  • The SQL statement must be within quotes.

  • The + $<variable_name> + parts of the SQL statement are expressions, and must not be within quotes. In the example below, $tablename.

  • The $<variable_name> parts of the SQL statement is bind parameter and must be within quotes. In the below example, $id and $book.

Note: Table name and column names must not be provided as bind parameters. Only values can be provided as bind parameters.
Example:
Query type Dropdown list/Expression Select the type of query for your SQL statement (Read or Write).

When Auto is selected, the Snap tries to determine the query type automatically.If the execution result of the query is not as expected, you can change the query type to Read or Write.

Default value: Auto

Example: Read

Pass through Checkbox Select this checkbox to pass the input document to the output view under the key original.
Note: This field applies only to queries with the SELECT statement.

Default status: Selected

Ignore empty result Checkbox Select this checkbox to not write any document to the output view when a SELECT operation does not produce any result. If this checkbox is not selected and the Pass-through checkbox is selected, the input document is passed through to the output view.

Default status: Deselected

Number of Retries Integer/Expression Specify the maximum number of retry attempts the Snap must make in case of network failure.
When you set the Number of retries to more than 0, the Snap generates duplicate records when the connection is not established. To prevent duplicate records, we recommend that you follow one of the following:
  • Set the Number of retries to 0 (default value) to prevent duplicate records from being passed downstream while executing a pipeline.

  • Use a Primary key to prevent records from being inserted into the database.

  • Use an Upsert instead of an Insert statement.

Default value: 0

Example: 3

Retry Interval (Seconds) Integer/Expression Specify the time interval between two successive retry requests. A retry happens only when the previous attempt results in an exception.

Default value: 1

Example: 10

Auto Commit Dropdown list Choose one of the following options to override the state of the Auto commiton the account.
  • True - The Snap executes with auto-commit enabled regardless of the value set for Auto commit in the Account used by the Snap.
  • False - The Snap executes with auto-commit disabled regardless of the value set for Auto commit in the Account used by the Snap.
  • Use account setting - The Snap executes with the Auto commit property value inherited by the Account used by the Snap.

Note: Auto commit may be enabled for certain use cases if the AlloyDB JDBC driver is used in either the Redshift, AlloyDB, or generic JDBC Snap. However, the JDBC driver may cause out of memory issues when SELECT statements are executed. In such cases, Auto Commit in the Snap should be set to False and the Fetch size in the Account settings can be increased for optimal performance.
Note: Behavior of DML Queries in Database Execute Snap when auto-commit is false
  • DDL queries used in the Database Execute Snap will be committed by the Database itself, regardless of the Auto-commit setting.

  • When Auto commit is set to false for the DML queries, the commit is called at the end of the Snap's execution.

  • The Auto commit must be true in a scenario where the downstream Snap depends on the data processed on an upstream Database Execute Snap containing a DML query.

  • When the Auto commit is set to Use account setting on the Snap, the account level commit needs to be enabled.

Default value: Use account setting

Example: True

Snap execution Dropdown list
Choose 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.

Default value: Execute only

Example: Validate & Execute