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
1. SELECT <* | expression [ AS field_alias ] [, ...]>
2. FROM stream_name [, ...]
3. [ WHERE search_condition ]
4. [ GROUP BY field_name [, window_type] ]
5. EMIT CHANGES;
Notes
expressioncan be a field name, a constant, or their association, such astemperature,weather.humidity,114514,1 + 2,SUM(productions)and`COUNT(*)`. Note that the last one is a raw column name which is used when a column name contains function names. See Special Characters.some_intervalrepresents a period of time. See Intervals.window_typespecifies the type of time window:
1. window_type ::= TUMBLING some_interval
2. | HOPPING some_interval some_interval
3. | SLIDING 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, stream2 WHERE stream1.humidity = stream2.humidity EMIT CHANGES;
- Grouping records:
1. SELECT COUNT(*) FROM weather GROUP BY cityId, TUMBLING (INTERVAL 10 SECOND) EMIT CHANGES;
