Variables and Expressions - full360/sneaql GitHub Wiki

Variables

SneaQL supports two types of variables:

  • session variables - defined by you during the run of your transform
  • environment variables - values passed into your transform at invocation time
Session Variables

Session variables can be created by way of the assign and assign_result tags. The assign tag specifies the variable name and an initial value:

/*-assign var_name 23-*/

Once the variable is initialized, you can use it either in expressions or in SQL text by preceding the variable name with a colon:

/*-execute_if :var_name > 0-*/
insert into tablename (int_field) values (:var_name);

Note that if you want to reference a string variable in your SQL script you will need to enclose it in quotes (or whatever string enclosing character your RDBMS uses):

/*-execute_if :var_name > 0-*/
insert into tablename (varchar_field) values (':var_name');
Environment Variables

Environment variables are passed into SneaQL from the outside, either through shell variables, a sneaql.env file, or another mechanism configured by your devops team (such as passing them into the Docker container using biscuit).

Environment variables in SneaQL are referenced by preceding the variable name with :env_ as shown below:

/*-execute-*/
insert into tablename(varchar_field) values (':env_HOSTNAME');

A few notes about environment variables:

  • Read-only, you can not set them from inside your SneaQL transform.
  • Names are case sensitive.

Expressions

An expression can be one of the following:

  1. a string constant (note that it must be a single, contigious string. MyName_Here
  2. an integer constant 23
  3. a float constant 23.5
  4. a reference to a predefined variable with the name preceded by a colon as per the dynamic SQL standard :variable_name

Expressions are always evaluated immediately before they are used (as opposed to being evaluated at the time the SQL script is loaded).

Comparisons

Several commands take action based upon the result of a comparison between two expressions.

  • Expressions are evaluated for their values immediately before the comparison
  • Values are converted to the appropriate data type before comparison.