# SELECT (Stream)

Continuously pulls records from the stream(s) specified. It is usually used in an interactive CLI to monitor realtime changes of data. Note that the query writes records to a random-named stream which is hidden from users.

# Synopsis

SELECT <* | expression [ AS field_alias ] [, ...]>
  FROM stream_name_1
       [ join_type JOIN stream_name_2
         WITHIN (some_interval)
         ON stream_name_1.field_1 = stream_name_2.field_2 ]
  [ WHERE search_condition ]
  [ GROUP BY field_name [, window_type] ]
  EMIT CHANGES;
1
2
3
4
5
6
7
8

# Notes

  • expression can be a field name, a constant, or their association, such as temperature, weather.humidity, 114514, 1 + 2 and SUM(productions).
  • some_interval represents a period of time. See Intervals.
  • join_type specifies the type of joining operation. Only INNER is supported yet.
  • window_type specifies the type of time window:
    window_type ::= TUMBLING some_interval
                  | HOPPING  some_interval some_interval
                  | SESSION  some_interval
    
    1
    2
    3
  • search_condition is actually a boolean expression:
    search_condition ::= [NOT] predicate [ <AND | OR> predicate [, ...] ]
    predicate        ::= expression comp_op expression
    comp_op          ::= = | <> | > | < | >= | <=
    
    1
    2
    3

# Examples

  • A simple query:
SELECT * FROM my_stream EMIT CHANGES;
1
  • Filtering rows:
SELECT temperature, humidity FROM weather WHERE temperature > 10 AND humidity < 75 EMIT CHANGES;
1
  • Joining streams:
SELECT stream1.temperature, stream2.humidity FROM stream1 INNER JOIN stream2 WITHIN (INTERVAL 5 SECOND) ON stream1.humidity = stream2.humidity EMIT CHANGES;
1
  • Grouping records:
SELECT COUNT(*) FROM weather GROUP BY cityId, TUMBLING (INTERVAL 10 SECOND) EMIT CHANGES;
1