waratah_temporal/lib.rs
1//! Waratah temporal plugin: native temporal literals (already storage terms),
2//! the O-axis dyadic temporal index, SPARQL comparison-FILTER rewrites, and
3//! the `tf:*` (timefuncs) custom functions.
4//!
5//! One crate implements the [`waratah_compute::plugin`] hooks — write
6//! ([`TemporalWritePlugin`]), plan ([`TemporalPlannerPlugin`]), and execute
7//! ([`TemporalExecutorPlugin`]) — so ingest and query constants cannot
8//! diverge. No `EncodePlugin` is registered: temporal terms (`xsd:dateTime`,
9//! `xsd:date`, `xsd:gYear`, `xsd:gYearMonth`, …) are storage-native already;
10//! the write hook only derives O-axis postings from them.
11//!
12//! Register at compute startup via [`register`]: the binary composes geo +
13//! temporal onto ONE [`waratah_compute::PluginHost`] and installs the
14//! composed set exactly once (`PluginHost::install_process_wide`) — the
15//! `tf:*` custom functions (unindexed fallback, ground evaluation) land on
16//! the same process custom-function map BEFORE any query is lowered. The
17//! registries are first-install-wins, so a second self-install is a silent
18//! no-op; [`install`] remains only as a single-plugin test shim.
19//!
20//! Tier summary (see `ARCH.md`):
21//! - **Tier 0 — comparison rewrite** ([`plan`]): `FILTER(?t >= const)` /
22//! range pairs over temporal-typed consts → `Join(temporal_scan, inner,
23//! ?t)`. The scan's partition-side reject is a conservative superset; the
24//! executor re-evaluates the stripped comparison exactly (XSD partial
25//! order, timezone rules, the `gYear` family extension) so rows are kept
26//! exactly as the unindexed FILTER would.
27//! - **Tier 1 — the index**: dyadic postings under the term's (budgeted)
28//! covering; instants post one exact leaf. Built by [`write`], served by
29//! the partition, trusted from the rebuild epoch (absent = untrusted; the
30//! compute auto-rebuild stamps it at startup).
31//! - **Tier 2 — `tf:*`**: the timefuncs relations as ground custom functions
32//! now; the OWL-Time structure-join rewrite is the follow-on.
33
34#![warn(missing_docs)]
35
36mod exec;
37mod plan;
38mod write;
39
40/// Stable plugin id carried by every CustomOp the temporal plugin mints.
41pub const PLUGIN_ID: &str = "temporal";
42
43/// The `tf:` namespace (timefuncs; the local names this crate adds beyond
44/// the vocabulary's eight were placed here with the author's permission).
45pub const TF_NAMESPACE: &str = "https://w3id.org/timefuncs/";
46
47pub use exec::{
48 TemporalExecutorPlugin, TemporalScanPayload, eval_tf_function, tf_custom_functions,
49};
50pub use plan::{TEMPORAL_SCAN_OP_ID, TemporalPlannerPlugin};
51pub use write::{TemporalWritePlugin, ingest_coverer_config, set_coverer_config};
52
53use waratah_compute::plugin::{PluginHost, RegisteredPlugin};
54
55/// Register the temporal plugin bundle + the `tf:*` custom functions on
56/// `host` (the composition point every plugin crate shares; the binary then
57/// installs the composed host exactly once, BEFORE any `QueryEngine` is
58/// constructed). Duplicate function IRIs propagate to the caller — a
59/// conflicting plugin set is a deployment error and must fail at the
60/// composition site, not silently no-op at install.
61pub fn register(host: &mut PluginHost) -> Result<(), waratah_compute::ComputeError> {
62 // The temporal plugin claims no datatypes (its terms are storage-native),
63 // so the plugin registration itself cannot conflict.
64 host.register(RegisteredPlugin {
65 id: PLUGIN_ID,
66 write: Some(std::sync::Arc::new(TemporalWritePlugin)),
67 encode: None,
68 planner: Some(std::sync::Arc::new(TemporalPlannerPlugin)),
69 executor: Some(std::sync::Arc::new(TemporalExecutorPlugin)),
70 })?;
71 host.register_functions(tf_custom_functions())
72}
73
74/// Test convenience: install ONLY the temporal plugin + `tf:*` custom
75/// functions on the process registries (first install wins; one guarded host
76/// install per process, so repeat calls are no-ops). Production composes via
77/// [`register`] + one [`waratah_compute::PluginHost::install_process_wide`]
78/// — a second plugin's self-install would otherwise be a silent no-op.
79/// Still BEFORE any `QueryEngine` is constructed.
80pub fn install() {
81 static INSTALLED: std::sync::OnceLock<()> = std::sync::OnceLock::new();
82 INSTALLED.get_or_init(|| {
83 let mut host = PluginHost::new();
84 register(&mut host).expect("tf IRIs are distinct from the builtin casts");
85 host.install_process_wide();
86 });
87}