Definitioncore
Continuous query
Also called standing query.
A query that is registered once and runs over unbounded input streams, producing new results as data arrives.
A continuous query is a query that a user registers once and that the system then evaluates again and again, or incrementally, while its input keeps growing; its answer at time depends only on the input that has arrived by time . The page gives the definition and its two common output semantics. The CQL stream model is one precise semantics for continuous queries over streams and relations, built from windows and relation-to-stream operators, and the Dataflow model is a programming model for continuous computations over out-of-order data with event time, triggers and accumulation modes. The sliding window model is different again: it is a model of computation for algorithms that summarize the last items in small memory, and it does not define a query language.
Definition
Input. Fix a discrete, ordered time domain . The input of a continuous query is a set of relations whose contents change only by appends, or, equivalently, a set of unbounded streams of timestamped tuples. Write for the finite instance that has arrived by time : for each input, the bag of tuples with a timestamp of at most . The input is append-only: if , then .
Query. A continuous query is a query over finite instances, for example a query of the relational algebra or of SQL, together with a time at which it is registered. It is not evaluated once. Instead, it defines an answer for each , and the system must deliver that answer, or the changes to it, as time advances. Babcock et al. (2002) contrast it with a one-time query, which is evaluated once on a snapshot and then forgotten, and they separate predefined continuous queries, registered before the data arrives, from ad hoc ones, registered later.
Output semantics. Two semantics are in common use.
- Snapshot semantics. . The answer at time is what the query would return if it were run as a one-time query on the input so far. A materialized view that the system keeps up to date has this semantics, and the CQL stream model uses it at each instant.
- Cumulative semantics (Terry et al. 1992). . The query is run, in concept, at every instant, and the answers of all runs are merged with set union. A tuple that was in the answer once stays in it.
Monotone queries. A query is monotone if implies . Queries of selection, projection, join and union are monotone; queries with set difference, negation or aggregation are in general not.
Proposition (theorem). If the input is append-only and is monotone, then for each , and for .
Proof. For , append-only input gives , and monotonicity gives . So each term of the union is a subset of the term for , and the union equals that term. The second claim follows because .
So for a monotone query the two semantics agree, the answer only grows, and the system can deliver it as a stream of new tuples: at each time, it sends . This is why Terry et al. restrict the queries of the Tapestry system to monotone ones and evaluate each query in an incremental form that finds only the new answers since the previous run. For a query that is not monotone, an answer that was delivered can become wrong later, and the output must be able to say so: by sending the full new answer, as an Rstream in CQL, or by sending deletions, as a Dstream in CQL or a retraction in the Dataflow model.
Late data. The definition assumes that a tuple with timestamp is known to the system at time . In Tapestry this holds by construction, because the database gives each tuple its timestamp when the tuple is appended. When timestamps come from the source (event time), a tuple can arrive after the system has already given an answer for its time. Such a tuple is late. The definition alone says nothing about late data. A system must either wait, with a watermark or punctuation that says when the input up to is complete, or correct an answer that it delivered. The Dataflow model makes this choice explicit.
Examples and non-examples
A monotone continuous query. Sensors send readings (time, sensor, temperature): (1, s1, 28), (2, s2, 31), (3, s1, 33), (4, s3, 29), (5, s2, 35). The query selects the readings with a temperature above 30.
| new tuples sent at | ||
|---|---|---|
| 1 | empty | none |
| 2 | (2, s2, 31) | (2, s2, 31) |
| 3 | (2, s2, 31), (3, s1, 33) | (3, s1, 33) |
| 4 | (2, s2, 31), (3, s1, 33) | none |
| 5 | (2, s2, 31), (3, s1, 33), (5, s2, 35) | (5, s2, 35) |
At each time, the cumulative answer equals , as the proposition says, and the output is an append-only stream.
A query that is not monotone. On the same input, returns the sensor with the highest reading so far. The snapshot answers are s1, s2, s1, s1 and s2 at times 1 to 5. The cumulative answer is {s1} at time 1 and {s1, s2} from time 2 on, so under the cumulative semantics the query returns every sensor that was ever the maximum. Under the snapshot semantics the answer at time 3 replaces s2 with s1, and an output stream must retract s2. The two semantics give different results.
An aggregate. counts the readings. The snapshot answers are 1, 2, 3, 4 and 5. The count of 1 is wrong from time 2 on, so the output cannot be a stream of appends of final results. This is the reason that stream systems put aggregates over time-based windows or count-based windows: an aggregate over a window that has closed can be delivered once and then never changes.
Non-examples.
- A one-time SQL query on a snapshot of the database. It runs once, and later appends do not change its delivered answer.
- A query rerun by hand each night on a full copy of the data, if the user takes only the last result. Each run is a one-time query; nothing defines a relation between the runs.
- A sliding window algorithm that keeps an estimate of a count over the last items. It answers a fixed function of the last items with bounded memory, which is a computational model, not a query language. A continuous query with a window can use such an algorithm as an operator.
Related definitions
- CQL stream model: streams and time-varying relations, with window operators from streams to relations and the operators Istream, Dstream and Rstream from relations to streams. It gives snapshot semantics at each instant and can express the Tapestry semantics (Arasu, Babu and Widom 2006, Section 11.2).
- Dataflow model: windows in event time, triggers in processing time, and the accumulation modes that relate the successive answers for one window.
- Materialized view and incremental view maintenance: a view kept up to date under inserts and deletes, which is a continuous query with snapshot semantics over a database that can also delete.
- Event-time watermark and stream punctuation: the signals that tell a continuous query that its input up to a time is complete.
- Complex event processing: continuous queries whose answers are patterns of events in order, not relations.
- Streaming model and sliding window model: the models of computation for one pass over a stream with small memory.
References
- 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 definition of continuous semantics over an append-only database, the restriction to monotone queries and their incremental evaluation in the Tapestry system
- Models and issues in data stream systems, the section on queries (one-time against continuous queries, predefined against ad hoc queries) and the discussion of unbounded memory, blocking operators and windows
- 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 2 (the Tapestry semantics as the union of one-time queries over snapshots) and Section 11.2 (Tapestry queries expressed in CQL)
Where this leads
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 56TPJP Edit this page History Report an error Markdown