Temporal Table Function
Unlike a versioned table, temporal table functions can only be defined on top of append-only streams — it does not support changelog inputs. Additionally, a temporal table function cannot be defined in pure SQL DDL.
Temporal table functions can be defined on top of append-only streams using the Table API. The table is registered with one or more key columns, and a time attribute used for versioning.
Suppose we have an append-only table of currency rates that we would like to register as a temporal table function.
Java
TemporalTableFunction rates = tEnv
.from("currency_rates").
.createTemporalTableFunction("update_time", "currency");
Scala
Temporal Table Function Join
Once defined, a temporal table function is used as a standard table function. Append-only tables (left input/probe side) can join with a temporal table (right input/build side), i.e., a table that changes over time and tracks its changes, to retrieve the value for a key as it was at a particular point in time.
SELECT * FROM orders;
order_time amount currency
========== ====== =========
10:30 1 USD
10:32 50 Yen
10:52 3 Euro
11:04 5 USD
Given these tables, we would like to convert orders to a common currency — USD.
SQL
Java
Table result = orders
.select($("(o_amount * r_rate).sum as amount"));