Script Structure

SXQL script is a sequence of statements, which can be:

Syntax

Statements in SXQL script must be terminated with semicolon (”;”).

Statement can be written on several lines to increase readability. The line feeds are ignored by interpreter.

Declaration statements can be written in any order, i.e it has no effect on the sequence of execution, which is determined solely by their actual dependencies.

Two comment styles are supported for inserting comments:

1. C style (or multi-line):

   /*
   comment
   */

2. C++ style (or single line):

    // comment

Declarations

From query processing standpoint it is important to know beforehand (i.e at compile time) if the statement returns tuple stream or any of SpectX data type. Therefore it is required to specify type of variable at declaration.

Formal syntax of a declaration consist of variable assigned to statement, where variable has respective type identifier assigned:

1. Statements returning single units (i.e not a stream) of SpectX data type:

'$'variable_name '=' expression ';'

2. Variables assigned to statements returning tuple stream:

'@'variable_name '=' { LIST | PARSE | DUAL | GREP | VALUE | query statement } [ ... ] ';'

(For advanced use there is actually third type of variable as well, for using with Pipetask UDF).

variable_name must begin with a letter. Variable names beginning with underscore are reserved for built-in system variables. Subsequent characters can be letters, numbers or underscore:

[a-zA-Z][a-zA-Z0-9_]*

variable_name must be unique in the scope of a script. That includes also variables from included scripts.

Example 1:

1
2
3
4
5
6
7
// declaration of tuple stream producer
@integers =
  dual(10)          //select 10 records from built-in data generator
    .select(i);     //select integer values from record

// define a simple STRING constant:
$myConstant = 5;

Execution

An SXQL script gets executed by calling tuple stream producer. This is also referred as root action statement. A tuple stream producer may be either tuple stream creation command or reference to declared (or included) tuple stream type variable:

{ LIST | PARSE | DUAL | GREP | VALUE | @tuple_stream_reference } ';'

Example 2: executing declarations of example1.

1
2
3
4
INCLUDE 'example1.sx';

@integers.select(i * $myConstant);      //using pipe style, or
//select i * $myConstant from @integers;  //uncomment if you want to use sql style

There can be only one root action statement in a script. Other declared streams and expressions may depend on root action, in which case they are executed in their respective dependency order.

Execution of a script takes place in the following sequence:

  1. INIT() function is executed if present.
  2. The execution statement dependency tree is constructed
  3. Statements are executed in the order dictated by the dependency tree