Chapter 23 · Temporal lookup model
Look up the past
Latest context can rewrite yesterday.
Prerequisite Count the join output.
Select reference-data versions by valid time and explain the history needed for late events.
The question
North moves from West to East at time 10. An order from time 8 arrives after the move. Enriching it with the latest mapping assigns historical sales to East; a valid-time report assigns them to West.
A temporal lookup selects the reference version valid at an event’s chosen timestamp. Our fixture has versions effective at 0 and 10, and uses the greatest effective time less than or equal to the order time. This is a valid-time convention. The time when your system learned about the move is a separate transaction/knowledge-time dimension.
- FactOrder event timeThe question is what was valid then.
- Dimension historyVersions and validityRetain the relevant earlier changes.
- As-of policyLatest valid prior versionCurrent state can answer a different question.
Conceptual diagram. The temporal reference is authored and inspectable. Late dimension updates and retention need explicit policies.
Predict the result
Versions are West from 0 and East from 10. The three event times arrive in the order 5, 12 and 8.
Events arrive with timestamps 5, 12 and 8. Should the final event receive the same region as the second event?
Run the experiment
The editor contains the published example. Select Run with the code unchanged.
Python prepares in the background while you read. First use can download about 84 MiB. Your code runs only when you select Run; each run starts with clean experiment state.
A saved draft is open. Select Restore code to see the published example. Recover draft brings back your draft.
Ctrl+Enter or ⌘+Enter runs the code.
Edits are saved in this browser when storage is available.
Technical error details
Your result
Console output
Troubleshooting
If Python stops responding, restart the environment and try again. Your code and last completed result are kept.
View the published result
The course build ran the published code to generate this output.
{
"trace": [
{
"event_time": 5,
"region": "West"
},
{
"event_time": 12,
"region": "East"
},
{
"event_time": 8,
"region": "West"
}
],
"policy": "as-of event time"
}Read the result
In trace, compare event_time and region for times 5, 12 and 8. The as-of policy picks the last version whose start is at or before the event time. The version for East begins at 10.
Change the experiment
Replace history=True with history=False in the editor. Select Run again. Compare policy and trace. Which earlier events receive today’s East value? With the original as-of policy, which version would an event at time 10 receive?
Runtime, source code and downloads
Runtime and reset details explain what stays ready and what is isolated on each run. Download Python packages the published helpers with the code in your editor.
Browse the sources for Bytewax windows and authored models, Kafka log and group exercises, live Kafka input, checkpoint recovery and processing patterns.
Late data creates a history requirement
If orders may arrive a day late, deleting all old reference versions after an hour makes some correct enrichments impossible. Define a retained-history horizon, missing-version policy and recovery source. Retention is not just a storage optimization; it changes which answers can be reproduced.
Replaying a report needs a version contract
Record the transformation version and reference snapshot or temporal selection policy beside output provenance. A replay using a mutable latest lookup may produce different results even when the source order log is unchanged. That can be intentional, but it should be a named rebuild rather than a mysterious disagreement.
Work, state and recovery costs
Where used, n counts input events, k counts retained distinct keys, r counts overlapping windows per event and z counts output matches. Bounds assume the stated algorithm. Collecting, sorting and displaying results adds work.
| Question | Mechanism and boundary |
|---|---|
| Work | The helper scans v table versions per event for O(nv) work. A sorted history with binary search could use O(n log v) lookups. |
| State | O(v) history plus n output rows. Deleting needed versions changes the answer contract. |
| Movement | The version list is local. A reference table delivered over the network can have its own arrival order. |
| Progress | The helper returns a match for each input using the provided history. An ongoing join would need a rule for when enough history is available. |
| Recovery | Reproducing an old answer requires the same reference versions and time lookup rule. |
Think it through
What extra information is needed to reproduce the report as it was known yesterday, rather than the report corrected with today’s historical knowledge?
Show hints
Hint 1
A version can be valid in the past but arrive in your system later.
Hint 2
An effective timestamp alone does not record when the system learned it.
Hint 3
You need a second timeline or an immutable audit of published decisions.
Show explanation
Preserve knowledge/transaction time or the exact input/version snapshot used for the earlier report. Valid-time history alone reconstructs what the latest knowledge says was true then. It cannot reproduce an earlier decision if historical reference data has since been corrected.
ReferencesFunction documentation and helper source
References open in a new tab; course helpers are documented separately from library APIs.
Temporal joins and version history
temporal_lookup is an authored valid-time lookup. Compare its version selection with the documented temporal-table contract.
Course helper implementation
These are functions written for this course, not additional library APIs. Inspect their parameters, operator calls and authored policies. The source shown is generated from the same Python files packaged with Run and Download Python.
Experiment scope
This is a finite as-of lookup over two versions. It does not implement a Flink temporal join, a bitemporal database or distributed version retention.
Primary reference →