Reference

Grammar Reference

This grammar is intentionally product-oriented rather than a complete parser specification. It reflects the syntax covered by tests.

Guide

This grammar is intentionally product-oriented rather than a complete parser specification. It reflects the syntax covered by tests.

Identifiers and Field Paths

text
identifier      ::= letter_or_underscore (letter_or_digit_or_underscore)*
field_path      ::= identifier ("." identifier)*
alias           ::= identifier | "[" path_segments "]" | quoted_identifier

Examples:

sql
value
input.field1.field2
server.region
[user].country
[metrics.avg]

SELECT

text
select_query ::=
    SELECT projection_list
    INTO output_name
    FROM input_name [TIMESTAMP BY field_path]
    [WHERE condition]
    [GROUP BY grouping_list]
    [HAVING condition]
text
projection_list ::= "*" | projection ("," projection)*
projection      ::= field_path [AS alias]
                  | scalar_expression AS alias
                  | aggregate_expression AS alias
                  | string_literal AS alias

Conditions

text
condition ::=
    comparison
  | condition AND condition
  | condition OR condition
  | field_path LIKE string_literal
  | field_path NOT LIKE string_literal
  | field_path BETWEEN literal AND literal
  | field_path NOT BETWEEN literal AND literal
  | field_path IN "(" literal_list ")"
  | field_path NOT IN "(" literal_list ")"
  | field_path IS NULL
  | field_path IS NOT NULL

Comparison operators:

text
= <> != > >= < <= !< !>

Aggregates

text
aggregate_expression ::=
    COUNT(*)
  | AVG(field_path)
  | MIN(field_path)
  | MAX(field_path)
  | STDDEV(field_path)
  | PERCENTILE(field_path, numeric_literal)
  | MEDIAN(field_path)
  | MAD(field_path)
  | REGRESSION_SLOPE(field_path, field_path)
  | REGRESSION_INTERCEPT(field_path, field_path)

`STDDEV`, `PERCENTILE`, `MEDIAN`, `MAD`, and regression functions are tested in `WINDOW BY ... COMPUTE`. `COUNT`, `AVG`, `MIN`, and `MAX` are tested in regular aggregation and windowed aggregation.

Durations and Windows

text
duration        ::= Duration(unit, value)
offset          ::= Offset(unit, value)
tumbling_window ::= TumblingWindow(duration [, offset])

Tested duration units include:

text
millisecond, second, minute, hour

Windowed aggregation:

text
GROUP BY [field_path, ... ,] TumblingWindow(Duration(unit, value)[, Offset(unit, value)])

Window compute:

text
WINDOW BY [field_path, ... ,] TumblingWindow(Duration(unit, value)[, Offset(unit, value)])
COMPUTE alias = aggregate_expression_or_aggregate_derived_expression [, ...]

ML windows:

text
WINDOW BY TumblingWindow(Duration(unit, value))
WINDOW BY SlidingWindow(Duration(unit, value))
WINDOW BY HoppingWindow(Duration(unit, value), Duration(unit, value))

WITH Scripts

text
script ::=
    [WITH with_definition ("," with_definition)*]
    output_statement (";" output_statement)* [";"]

with_definition ::= scope_name AS "(" select_query ")"
output_statement ::= SELECT projection_list INTO output_name FROM scope_or_input ...

MATCH_RECOGNIZE

text
match_query ::=
    SELECT projection_list
    INTO output_name
    FROM input_name TIMESTAMP BY field_path
    MATCH_RECOGNIZE "("
        [PARTITION BY field_path ("," field_path)*]
        LIMIT Duration(unit, value)
        MEASURES measure_list
        ONE ROW PER MATCH
        AFTER MATCH SKIP TO NEXT ROW
        PATTERN "(" pattern_expression ")"
        DEFINE define_list
    ")" AS alias
text
pattern_expression ::= variable [quantifier]
                     | pattern_expression pattern_expression
                     | pattern_expression "|" pattern_expression
                     | "(" pattern_expression ")"

quantifier ::= "*" | "+" | "?" | "{" n "}" | "{" n "," "}" | "{" n "," m "}" | "{" "," m "}"

Temporal ML

text
ml_query ::=
    SELECT projection_list
    INTO output_name
    FROM input_name AS alias TIMESTAMP BY alias.field
    [ALIGN JOIN input_name AS alias TIMESTAMP BY alias.field
        ON alias.field = alias.field
        WITHIN Duration(unit, value)]*
    ANCHOR alias
    [PARTITION BY field_path (, field_path)*]
    WINDOW BY ml_window
    FEATURES feature_assignment (, feature_assignment)*
    LABELS label_assignment (, label_assignment)*
    MODEL model_name = TRAIN ONLINE_CLASSIFIER()
        LABELS label_name (, label_name)*
        [WITH "(" model_parameter_assignment (, model_parameter_assignment)* ")"]
    COMPUTE ml_compute_assignment (, ml_compute_assignment)*
    [WHERE condition]
text
feature_assignment ::= name = field_path
                     | name = diff(field_path)
                     | name = avg(field_path)
                     | name = mean(field_path)
                     | name = count(field_path)
                     | name = stddev(field_path)
                     | name = zscore(field_path)

label_assignment ::= name = condition
                   | name = future(condition, Duration(unit, value))

ml_compute_assignment ::= name = CLASSIFY(model_name)
                        | name = PROBABILITY(model_name)
                        | name = PROBABILITY(model_name, label_name)