Skip to content

temporal

Boris Glavic edited this page Aug 21, 2019 · 2 revisions

Temporal Queries

GProM also support snapshot semantics, a class of temporal queries which interpret a non-temporal query over a temporal database by showing how the result of the query evolves over time. For example, consider a query that counts the number of items in a warehouse:

SELECT count(*) FROM warehouse;

Interpreted under snapshot semantics over a temporal database the records the content of the warehouse at each point, this query returns how many items are in the warehouse at each point in time.

To evaluate a query under snapshot semantics, you have to wrap it in a SEQUENCED TEMPORAL statement like so:

SEQUENCED TEMPORAL (
    SELECT ...
);

GProM expects the input relation of a snapshot semantics query to associate a time interval with each row that is stored as two attributes (begin and end of the interval). You have specify for every table accessed by the snapshot semantics query the names of these two attributes. For example, if you store time for the warehouse table in attributes time_begin and time_end, then our example query from above would be written as:

SEQUENCED TEMPORAL (
    SELECT count(*)
    FROM warehouse WITH TIME (time_begin, time_end)
);

For example, consider the following GProM session:

Oracle SQL - Postgres:postgres@127.0.0.1:gpromtest$SELECT * FROM warehouse ORDER BY time_begin, time_end;
 item  | time_begin | time_end |
--------------------------------
 cake  | 1          | 2        |
 fruit | 1          | 3        |
 bacon | 1          | 10       |
 eggs  | 8          | 18       |
 bacon | 15         | 20       |
Oracle SQL - Postgres:postgres@127.0.0.1:gpromtest$SEQUENCED TEMPORAL (SELECT count(*) AS x FROM warehouse WITH TIME (time_begin, time_end));
| x | t_b         | t_e        |
--------------------------------
| 0 | -2000000000 |          1 |
| 3 |           1 |          2 |
| 2 |           2 |          3 |
| 1 |           3 |          8 |
| 2 |           8 |         10 |
| 1 |          10 |         15 |
| 2 |          15 |         18 |
| 1 |          18 |         20 |
| 0 |          20 | 2000000000 |