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.

Synopsis

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

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:

    1. window_type ::= TUMBLING some_interval
    2. | HOPPING some_interval some_interval
    3. | SESSION some_interval
  • search_condition is actually a boolean expression:

    1. search_condition ::= [NOT] predicate [ <AND | OR> predicate [, ...] ]
    2. predicate ::= expression comp_op expression
    3. comp_op ::= = | <> | > | < | >= | <=

Examples

  • A simple query:

    1. SELECT * FROM my_stream EMIT CHANGES;
  • Filtering rows:

    1. SELECT temperature, humidity FROM weather WHERE temperature > 10 AND humidity < 75 EMIT CHANGES;
  • Joining streams:

    1. SELECT stream1.temperature, stream2.humidity FROM stream1 INNER JOIN stream2 WITHIN (INTERVAL 5 SECOND) ON stream1.humidity = stream2.humidity EMIT CHANGES;
  • Grouping records:

    1. SELECT COUNT(*) FROM weather GROUP BY cityId, TUMBLING (INTERVAL 10 SECOND) EMIT CHANGES;