Query Scripts

SpectX Query Language (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 record stream or single value data. Therefore the type of variable must be specified at declaration.

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

1. Statements returning single value data:

'$'variable_name '=' expression ';'

2. Variables assigned to statements returning record 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).

A 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_]*

A variable_name must be unique in the scope of all executing scripts. NB! As included scripts are also in the scope you must choose .

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 a statement producing a record stream - an execution statement. This can be either record stream creation command or reference to declared (or included) stream type variable:

{ LIST | PARSE | DUAL | GREP | VALUE | @record_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 execution statement in a script. Other declared streams and expressions may depend on it, 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 dependency tree is constructed
  3. Statements are executed in the order dictated by the dependency tree