Cassandra - Execute

On this Page

Snap type:

Write


Description:

This Snap allows you to execute arbitrary Cassandra query language (CQL) supported by JDBC.

This Snap works only with single queries.

You can drop your database with it, so be careful.


Valid JSON paths that are defined in the where clause for queries/statements will be substituted with values from an incoming document. Documents will be written to the error view if the document is missing a value to be substituted into the query/statement.

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.

  • Expected upstream Snaps: Snaps that will either input data into Cassandra Execute, merge information with Cassandra, or required to precede execution before Cassandra execution.
  • Expected downstream Snaps: Snaps that will use information gained from Cassandra or that is dependent on Cassandra having executed prior.

Snaps in this Snap Pack display an exception (raised by the JDBC driver) when you query a map column that has a timestamp as the key.

Example

  1. Create a table containing a map whose key is a timestamp:
    CREATE COLUMNFAMILY t (userid text PRIMARY KEY, todo map<timestamp, text>);

  2. Insert values into the newly-created table.
    INSERT INTO t (userid, todo) VALUES ('a', {'2013-09-22T12:01:00.000+0000': 'text'});

  3. Once the insert operation succeeds, query the map column:
    SELECT userid, todo FROM t;


    The Snap displays the following exception:

    com.datastax.driver.core.exceptions.CodecNotFoundException:
    Codec not found for requested operation: [timestamp <-> java.sql.Timestamp]

The Cassandra Execute Snap is for simple DML (SELECT, INSERT, UPDATE, DELETE) type statements. 
Prerequisites:

Validated Cassandra account, verified network connectivity to Cassandra server and port, and the Cassandra server running.

Support and limitations:
  • Works in Ultra Tasks.
  • The Cassandra-Execute Snap using Apache Cassandra V3 does not support $$ as an escape character for enclosing string input, as $ is a reserved character for variable substitution in SnapLogic.
  • The Cassandra Snap Pack does not support the following data types introduced in Apache Cassandra V3.x, as the underlying SnapLogic JDBC driver is designed to work with Apache Cassandra V2.1:

    • DateRange

    • Duration

    • Geo-spatial data types such as Point, Polygon and LineString

Account: 

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

Views:
InputThis Snap has at most one document input view. If the input view is defined, then the where clause can substitute incoming values for a given expression.
OutputThis Snap has at most one document output view. If an output view is available and an update/insert/merge/delete statement was executed, then the original document that was used to create the statement will be output with the status of the statement executed.
Error

This Snap has at most one document error view and produces zero or more documents in the view.
Note: 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.
SQL statement

Required. Specifies the SQL statement to execute on the server.

We recommend you to add a single query in the SQL Statement field.

Cassandra Snaps do not support batch operations, which is why this field does not support SQL bind variables in it. There are two possible scenarios that you encounter when working with SQL statements in SnapLogic. You must understand the following scenarios to successfully execute your SQL statements:

Scenario 1: Executing SQL statements without expressions
If 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.

Examples:



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

  • emp=$emp

Additionally, the JSON path 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.

Scenario 2: Executing SQL queries with expressions 
If 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.

Examples:

 
 

  • "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 within these values to escape the single quote through these queries.

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'


Known issue: When the SQL statement property is an expression, the Pipeline parameters are shown in the suggest, but not the input schema. 

Default value: [None] 

This Snap does not allow you to inject SQL, such as select * from people where $columnName = "abc".

Only values can be substituted since it uses prepared statements for execution, which, for example, results in select * from people where address = ?.

The '$' sign and identifier characters, such as double quotes (“), single quotes ('), or back quotes (`), are reserved characters and should not be used in comments or for purposes other than their originally intended purpose.

Query type

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 


If checked, the input document will be passed through to the output view under the key 'original'. This property applies only to the Execute Snaps with SELECT statement.

Default value: True

Ignore empty result 


If selected, no document will be written to the output view when a SELECT operation does not produce any result. If this property is not selected and the Pass through property is selected, the input document will be passed through to the output view.
Default value: Not selected

Number of retries

Specify the maximum number of retry attempts the Snap must make in case there is a network failure and is unable to read the target file. The request is terminated if the attempts do not result in a response.

  • If the Number of retries value is set to 0 (the default value), the retry option is disabled, and the Snap does not initiate a retry. The pipeline will not attempt to retry the operation in case of a failure—any failure encountered during the database operation will immediately result in the pipeline failing without any retry attempts to recover from the errors.

  • If the Number of retries value is greater than 0, the Snap initiates a download of the target file into a temporary local file. If any error occurs during the download, the Snap waits for the time specified in the Retry interval and then attempts to download the file again from the beginning. After the download is successful, the Snap streams the data from the temporary file to the downstream pipeline. All temporary local files are deleted when they are no longer needed.

Ensure that the local drive has sufficient free disk space to store the temporary local file.

Retry interval (seconds)Number of seconds between retries.

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.

 
 

Troubleshooting


  • Run Cassandra JDBC driver using another JDBC tool to verify syntax and results.

Example


Snap Pack History

 Click to view/expand
Release Snap Pack VersionDateType  Updates
August 2024main27765 StableUpdated and certified against the current Snaplogic Platform release.
May 2024main26341 StableUpdated and certified against the current SnapLogic Platform release.
February 2024436patches25597 -

Upgraded the jOOQ library of the Cassandra Snap Pack from v3.9.1 to v3.17.x.

This upgrade is currently NOT available with the latest distribution. However, you can still consume this patch through 436patches25597. This update is scheduled to be included in the latest distribution release on April 10, 2024, and will be a part of the stable distribution with the GA release on May 8. 2024.

Behavior change:

The jOOQ upgrade for Cassandra Snap Pack done as part of 436patches25597 resulted in the following behavior changes:

  • Previously, when TTL (time to live) was queried using a Select statement without specifying it during data insertion or update, the Cassandra Snaps would display '0'. Now, they return 'null' in such cases.

  • Previously, the null values were stored as ‘0' in the INT datatype columns, now they are stored as 'null’.

February 2024main25112 StableUpdated and certified against the current SnapLogic Platform release.
November 2023main23721 StableUpdated and certified against the current SnapLogic Platform release.

August 2023

main22460

 


Stable

The Cassandra - Execute Snap now includes a new Query type field. When Auto is selected, the Snap tries to determine the query type automatically.

May 2023main21015 StableUpgraded with the latest SnapLogic Platform release.

February 2023

main19844

   

Stable

Upgraded with the latest SnapLogic Platform release.

November 2022main18944 StableUpgraded with the latest SnapLogic Platform release.
August 2022main17386 StableUpgraded with the latest SnapLogic Platform release.
4.29main15993 Stable

Upgraded with the latest SnapLogic Platform release.

4.28main14627 StableUpgraded with the latest SnapLogic Platform release.

4.27

main12833

 

Stable

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

Enhanced the Cassandra - Select Snap to return only the fields (provided in the Output Fields) in the output schema (second output view), through a new checkbox Fetch Output Fields In Schema. If the Output Fields property is empty all the columns are visible.

4.23main7430
 
StableUpgraded with the latest SnapLogic Platform release.
4.22main6403
 
Stable
  • Introduces a new account type Cassandra SSL/TLS Database account. Enhances encryption by ensuring data is transferred securely. 
  • Enhances both the account types to enable expressions for required fields to support dynamic account. 
4.21 Patch421patches6272 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 Patch421patches6144 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 PatchMULTIPLE8841 Latest

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

4.21snapsmrc542

 

Stable

Extended support to Cassandra version 3.11.5.

4.20snapsmrc535
 
StableUpgraded with the latest SnapLogic Platform release.
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 Cassandra 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 db/cassandra6848 Latest

Fixed an issue with the Cassandra Execute Snap wherein output documents were not produced on selecting the Pass through property.

4.16snapsmrc508
 
StableUpgraded with the latest SnapLogic Platform release.
4.15 Patch db/cassandra6329  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
 
Stable

Where clause property updated to support values containing upstream parameters and Pipeline parameters.

4.10

snapsmrc414

 
StableUpgraded with the latest SnapLogic Platform release.
4.9 Patchcassandra3067 Latest

Fixed an issue regarding connection not closed after login failure; Expose autocommit for "Select into" statement in PostgreSQL Execute Snap and Redshift Execute Snap.

4.9snapsmrc405
 
StableUpgraded with the latest SnapLogic Platform release.
4.8 Patchcassandra2751

Potential fix for JDBC deadlock issue.

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 Patchcassandra2197 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.6cassandra1620
 
Stable
  • Resolved an issue in the Cassandra Select Snap unexpectedly failing with a Failure: 0 error.
  • Resolved an issue in the Cassandra Select Snap that caused unexpectedly failure for valid SQL queries.
  • Resolved an an issue in the Cassandra Select Snap that caused correctly configured Snaps to fail while execution.
4.5.1

snapsmrc344

 
StableUpgraded with the latest SnapLogic Platform release.
4.4.1NA StableUpgraded with the latest SnapLogic Platform release.
4.4NA StableUpgraded with the latest SnapLogic Platform release.
4.3.2NA Stable
  • Resolved an issue with Execute and Select Snaps failing when querying table with user-defined types (UDT).
  • Resolved an issue when ordering db column names using TreeMap versus HashMap caused Cassandra's use of emptyString fields to break.