Modeladvanced
CQL stream-relation model
Also called Continuous Query Language, stream-to-relation operators.
Define stream queries by window operators that turn streams into relations, relational operators, and operators that turn relations back into streams.
The CQL stream model, of Arasu, Babu and Widom (2006), gives a precise meaning to a continuous query over streams and relations that change with time: window operators turn a stream into a relation, ordinary relational operators act on the relation at each instant, and the operators Istream, Dstream and Rstream turn a relation back into a stream. A continuous query is the general notion of a query whose answer follows a growing input; CQL is one semantics for it, with snapshot answers at each instant of a single ordered time domain. The Dataflow model differs: it separates event time from processing time, lets input arrive out of order, and makes the time and the form of each output a choice of the user. CQL also differs from the sliding window model, which is a model of computation for small-memory algorithms over the last items and not a query language.
The machine
Time domain. Time is a discrete, ordered domain . A time instant is an element of . The domain models the time of the application, not the wall clock of the system, and the semantics needs only a discrete, ordered domain (Section 4).
Streams. A stream is a possibly infinite bag of elements , where is a tuple of the schema of and is its timestamp. For each , only finitely many elements have timestamp (Definition 1). A base stream is an input; a derived stream is the output of an operator.
Relations. A relation is a map from to finite bags of tuples of its schema. is the instantaneous relation of at (Definition 2). A stored table that is updated now and then is a relation in this sense: its value at is its content after the updates up to .
Operators. There are three classes, and no direct operator from streams to streams.
- Stream-to-relation operators are windows. Each one maps a stream to a relation .
- , a time-based window: . The interval is closed at both ends, so it covers instants.
- is : the elements with timestamp exactly . has : all elements up to .
- , a count-based window: the elements with the largest timestamps at most , or all of them if there are fewer than . If several elements share the timestamp at the boundary, the choice among them is not fixed, so this window can be nondeterministic.
- : split by the values of , take of each part, and take the union.
- : the window of taken at the instant , so the relation changes only once every instants. With this is a tumbling window.
- Relation-to-relation operators are the operators of SQL or the relational algebra, applied at each instant: .
- Relation-to-stream operators. With bag union, bag difference and :
- : the tuples inserted at .
- : the tuples deleted at .
- : the whole relation at every instant.
Queries and their semantics. A CQL query is a composition of these operators, written in SQL with window clauses after each stream in the From clause and an Istream, Dstream or Rstream in the Select clause. When the query result is a relation and no relation-to-stream operator is given, but the relation can only grow, CQL adds Istream by default (Section 6.4). The continuous semantics (Definition 3) is that the result at , a relation or the stream elements with timestamp , depends only on the input elements with timestamp at most and on the relations up to .
When time advances. Time advances from to when all inputs with timestamps up to have been processed. The semantics thus assumes that the system knows when the input of an instant is complete. Section 8 of the paper meets this with heartbeats: a heartbeat with timestamp promises that no later stream element has a timestamp of or less. A heartbeat can come from the system clock (the system stamps elements on arrival, so they are in order by construction), from each source (the query-level heartbeat is the minimum of the source heartbeats), or from a known bound on the delay, as at global time .
Late data. An element that arrives after a heartbeat that covers its timestamp breaks the promise. The model does not give it a meaning: the answers for the instants up to the heartbeat are already final. A heartbeat of the third kind is a heuristic if the bound is only an estimate, and then the system must drop such elements or treat them by a policy outside the model. This is the main difference from the Dataflow model, where late data is a normal case and earlier answers can be refined. Heartbeats are the same idea as an event-time watermark and as a punctuation on the timestamp attribute.
What it counts
The model assigns to each query and each instant one result: the instantaneous relation if the query returns a relation, or the bag of elements with timestamp if it returns a stream. Equality of two queries means equality of these results at every instant, for every input. The model is about meaning, not cost, but the paper and the STREAM system give the memory that each operator needs, its synopsis. With the cost conventions of this area, where is the number of elements in the window:
- keeps the last elements in a queue. Each arrival does one insert and at most one expiry, so the work is worst case per element and the memory is elements.
- keeps the elements of the last instants. Each element is inserted once and expired once, so the work is amortized per element. The memory has no bound in terms of alone, because the model allows any finite number of elements per instant.
- and must compare with , so they keep the previous instantaneous relation or receive their input as a stream of inserts and deletes. The STREAM system does the second: every operator exchanges a stream of insertions and deletions, which it calls a plus-minus stream (Section 12).
- An aggregate over a window, such as over , is maintained in per insert and delete when the aggregate has an inverse. Without an inverse, it needs the methods of sliding window aggregation.
Relation to other models
- Tapestry. A Tapestry query returns at the union of the answers of a one-time query at all instants up to (see continuous query). Section 11.2 shows that this is the CQL query Select Istream(Distinct *) From (Istream()) [Range Unbounded]. Tapestry has no sliding windows and no relation-to-stream operators.
- Materialized views and chronicles. A view defined by a SQL query over relations is the same in CQL. The chronicle data model of Jagadish et al. has streams (chronicles), relations and persistent views, and both of its operator classes are expressible in CQL (Section 11.1).
- Stream-only languages. For each relational operator , define a stream operator , and for each window , define . Section 11.6 shows that the stream-only language obtained this way has essentially the same power as CQL, and that it is close to the language of TelegraphCQ. The authors keep both types because SQL then applies unchanged.
- The Dataflow model. CQL has one time domain and assumes complete input up to each instant. The Dataflow model has event time and processing time, uses a watermark that may be wrong, lets a window emit early, on-time and late results, and defines how later results relate to earlier ones. A CQL window at instant is close to a Dataflow window that fires once when the watermark passes its end, in discarding mode.
- Windows of other pages. with is a hopping window, and with a tumbling window. CQL has no session window; a session window is defined by gaps in the data and not by a fixed interval.
Known results in the model
All results here are theorems in the model, from Sections 6, 10 and 11 of Arasu, Babu and Widom (2006).
Rstream is enough. Istream and Dstream can be written with Rstream, windows and relational operators (Section 6.3). So every query has an equivalent form whose only relation-to-stream operator is Rstream.
Window reduction (Section 10.1). For any list of attributes and any condition , Select Istream() From [Range Unbounded] Where is equivalent to Select Rstream() From [Now] Where . Both return each element of that satisfies , at its own timestamp. More generally, Istream and Rstream give the same stream on any relation with for all . The second form needs no state, so a system should use it.
Filter-window commutativity (Section 10.2). A filter on a stream commutes with a time-based window: . The same does not hold for a tuple-based window in general. For example, with , the filter applied after the window can return nothing when the last element fails , while the window over the filtered stream returns the last element that passes .
Expressiveness (Section 11). Basic CQL, without user-defined functions, aggregates or windows beyond those above, is strictly more expressive than Tapestry, Tribeca, GSQL and materialized views over relations with or without chronicles.
A worked example. The stream has the elements , , , and . The window is , so at it holds the elements with timestamps from to .
| Istream at | Dstream at | |||
|---|---|---|---|---|
| 0 | empty | none | none | empty |
| 1 | a, b | a, b | none | a, b |
| 2 | a, b, c | c | none | c |
| 3 | a, b, c | none | none | empty |
| 4 | c, d | d | a, b | d |
| 5 | d, e | e | c | e |
| 6 | d, e | none | none | empty |
| 7 | e | none | d | empty |
The Rstream of the window repeats the whole relation at each instant, for example and at . Select Rstream(Count(*)) From [Range 2] gives the counts 2, 3, 3, 2, 2, 2 and 1 at to 7. For at , the window holds and one of and , because both have timestamp 1; CQL leaves this choice open. The Istream of and the Rstream of both give and at 1, at 2, at 4 and at 5, as window reduction says.
References
- Arvind Arasu, Shivnath Babu and Jennifer Widom, The CQL continuous query language, semantic foundations and query execution, The VLDB Journal 15(2), 2006, pages 121 to 142, Section 4 (streams and relations, Definitions 1 and 2), Section 5 (the abstract semantics, Definition 3), Section 6 (the window operators of 6.1 and Istream, Dstream and Rstream of 6.3), Section 8 (heartbeats), Section 10 (window reduction and filter-window commutativity), Section 11 (comparison with Tapestry, Tribeca, GSQL and chronicles, and the stream-only language of 11.6) and Section 12 (the STREAM implementation)
- Models and issues in data stream systems, the discussion of windows, blocking operators and the memory needs of continuous queries
- Douglas Terry, David Goldberg, David Nichols and Brian Oki, Continuous queries over append-only databases, Proceedings of ACM SIGMOD 1992, pages 321 to 330, the Tapestry semantics that CQL generalizes
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag MST56H Edit this page History Report an error Markdown