1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: Apache-2.0
//! Spatial engine operations dispatched to the Data Plane.
use nodedb_types::{Surrogate, SurrogateBitmap, geometry::Geometry};
/// Spatial predicate type for R-tree index scan.
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
zerompk::ToMessagePack,
zerompk::FromMessagePack,
)]
#[msgpack(c_enum)]
pub enum SpatialPredicate {
/// ST_DWithin: geometry within distance (meters).
DWithin,
/// ST_Contains: query geometry contains document geometry.
Contains,
/// ST_Intersects: query geometry intersects document geometry.
Intersects,
/// ST_Within: document geometry is within query geometry.
Within,
}
/// Spatial engine physical operations.
#[derive(
Debug,
Clone,
PartialEq,
serde::Serialize,
serde::Deserialize,
zerompk::ToMessagePack,
zerompk::FromMessagePack,
)]
pub enum SpatialOp {
/// Insert a geometry into the R-tree index for a document.
///
/// Used by the sync inbound path to replicate spatial data from Lite to Origin.
/// The R-tree and sparse document store are keyed by the hex-encoded
/// `surrogate` (matching direct `INSERT INTO` semantics), so the
/// cross-engine prefilter bitmap intersect works without translation.
Insert {
collection: String,
field: String,
/// Stable global surrogate for the row, assigned on the Control Plane.
surrogate: Surrogate,
/// Typed geometry, deserialised on the Control Plane from wire bytes.
geometry: Geometry,
/// Sync provenance: identifies the originating peer and sequence for idempotency.
#[serde(default)]
provenance: Option<nodedb_types::sync::wire::SyncProvenance>,
},
/// Remove a document's geometry from the R-tree index.
///
/// Used by the sync inbound path. Keyed by the same hex-encoded surrogate
/// used at insert time.
Delete {
collection: String,
field: String,
/// Stable global surrogate for the row.
surrogate: Surrogate,
/// Sync provenance: identifies the originating peer and sequence for idempotency.
#[serde(default)]
provenance: Option<nodedb_types::sync::wire::SyncProvenance>,
},
/// R-tree index scan with spatial predicate and exact refinement.
Scan {
collection: String,
field: String,
predicate: SpatialPredicate,
/// Typed query geometry, parsed and validated on the Control Plane.
query_geometry: Geometry,
/// Distance threshold in meters (for ST_DWithin). 0 for non-distance predicates.
distance_meters: f64,
/// Additional attribute filters applied after spatial candidates.
attribute_filters: Vec<u8>,
limit: usize,
projection: Vec<String>,
/// RLS post-candidate filters.
rls_filters: Vec<u8>,
/// Optional surrogate prefilter injected by a cross-engine sub-plan.
/// When present, only candidates whose surrogate is in this bitmap
/// are returned. `None` = no prefilter; all R-tree candidates pass.
prefilter: Option<SurrogateBitmap>,
},
}