@lix-js/sdk 0.6.0-preview.5 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -4
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +19 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -3
- package/dist/native.d.ts +1 -0
- package/dist/native.js +47 -0
- package/dist/open-lix.d.ts +38 -207
- package/dist/open-lix.js +59 -284
- package/dist/result.d.ts +18 -0
- package/dist/result.js +48 -0
- package/dist/types.d.ts +114 -1
- package/dist/value.d.ts +28 -0
- package/dist/value.js +245 -0
- package/package.json +38 -71
- package/SKILL.md +0 -507
- package/dist/builtin-schemas.d.ts +0 -1
- package/dist/builtin-schemas.js +0 -1
- package/dist/engine-wasm/index.d.ts +0 -87
- package/dist/engine-wasm/index.js +0 -339
- package/dist/engine-wasm/wasm/lix_engine.d.ts +0 -79
- package/dist/engine-wasm/wasm/lix_engine.js +0 -833
- package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
- package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -27
- package/dist/generated/builtin-schemas.d.ts +0 -427
- package/dist/generated/builtin-schemas.js +0 -643
- package/dist/sqlite/index.d.ts +0 -12
- package/dist/sqlite/index.js +0 -359
- package/dist-engine-src/README.md +0 -18
- package/dist-engine-src/src/backend/capabilities.rs +0 -67
- package/dist-engine-src/src/backend/conformance/baseline.rs +0 -1127
- package/dist-engine-src/src/backend/conformance/factory.rs +0 -93
- package/dist-engine-src/src/backend/conformance/failure_tests.rs +0 -608
- package/dist-engine-src/src/backend/conformance/fixtures.rs +0 -26
- package/dist-engine-src/src/backend/conformance/mod.rs +0 -75
- package/dist-engine-src/src/backend/conformance/model.rs +0 -28
- package/dist-engine-src/src/backend/conformance/model_based.rs +0 -257
- package/dist-engine-src/src/backend/conformance/persistence.rs +0 -204
- package/dist-engine-src/src/backend/conformance/projection.rs +0 -21
- package/dist-engine-src/src/backend/conformance/pushdown.rs +0 -24
- package/dist-engine-src/src/backend/conformance/runner.rs +0 -90
- package/dist-engine-src/src/backend/conformance/scan.rs +0 -24
- package/dist-engine-src/src/backend/conformance/write.rs +0 -16
- package/dist-engine-src/src/backend/error.rs +0 -94
- package/dist-engine-src/src/backend/in_memory.rs +0 -670
- package/dist-engine-src/src/backend/mod.rs +0 -39
- package/dist-engine-src/src/backend/predicate.rs +0 -80
- package/dist-engine-src/src/backend/traits.rs +0 -260
- package/dist-engine-src/src/backend/types.rs +0 -239
- package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
- package/dist-engine-src/src/binary_cas/codec.rs +0 -346
- package/dist-engine-src/src/binary_cas/context.rs +0 -139
- package/dist-engine-src/src/binary_cas/kv.rs +0 -1038
- package/dist-engine-src/src/binary_cas/mod.rs +0 -11
- package/dist-engine-src/src/binary_cas/types.rs +0 -121
- package/dist-engine-src/src/branch/context.rs +0 -40
- package/dist-engine-src/src/branch/lifecycle.rs +0 -221
- package/dist-engine-src/src/branch/mod.rs +0 -13
- package/dist-engine-src/src/branch/refs.rs +0 -321
- package/dist-engine-src/src/branch/stage_rows.rs +0 -67
- package/dist-engine-src/src/branch/types.rs +0 -21
- package/dist-engine-src/src/catalog/context.rs +0 -412
- package/dist-engine-src/src/catalog/mod.rs +0 -10
- package/dist-engine-src/src/catalog/schema.rs +0 -4
- package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
- package/dist-engine-src/src/cel/context.rs +0 -86
- package/dist-engine-src/src/cel/error.rs +0 -19
- package/dist-engine-src/src/cel/mod.rs +0 -8
- package/dist-engine-src/src/cel/provider.rs +0 -9
- package/dist-engine-src/src/cel/runtime.rs +0 -167
- package/dist-engine-src/src/cel/value.rs +0 -50
- package/dist-engine-src/src/changelog/bench_support.rs +0 -785
- package/dist-engine-src/src/changelog/change.rs +0 -1
- package/dist-engine-src/src/changelog/codec.rs +0 -497
- package/dist-engine-src/src/changelog/commit.rs +0 -1
- package/dist-engine-src/src/changelog/context.rs +0 -1614
- package/dist-engine-src/src/changelog/mod.rs +0 -29
- package/dist-engine-src/src/changelog/store.rs +0 -163
- package/dist-engine-src/src/changelog/test_support.rs +0 -54
- package/dist-engine-src/src/changelog/types.rs +0 -213
- package/dist-engine-src/src/commit_graph/context.rs +0 -944
- package/dist-engine-src/src/commit_graph/mod.rs +0 -9
- package/dist-engine-src/src/commit_graph/types.rs +0 -89
- package/dist-engine-src/src/commit_graph/walker.rs +0 -786
- package/dist-engine-src/src/common/error.rs +0 -347
- package/dist-engine-src/src/common/fingerprint.rs +0 -3
- package/dist-engine-src/src/common/fs_path.rs +0 -1336
- package/dist-engine-src/src/common/identity.rs +0 -145
- package/dist-engine-src/src/common/json_pointer.rs +0 -67
- package/dist-engine-src/src/common/metadata.rs +0 -40
- package/dist-engine-src/src/common/mod.rs +0 -23
- package/dist-engine-src/src/common/types.rs +0 -105
- package/dist-engine-src/src/common/wire.rs +0 -222
- package/dist-engine-src/src/domain.rs +0 -320
- package/dist-engine-src/src/engine.rs +0 -203
- package/dist-engine-src/src/entity_pk.rs +0 -402
- package/dist-engine-src/src/functions/context.rs +0 -296
- package/dist-engine-src/src/functions/deterministic.rs +0 -113
- package/dist-engine-src/src/functions/mod.rs +0 -18
- package/dist-engine-src/src/functions/provider.rs +0 -130
- package/dist-engine-src/src/functions/state.rs +0 -335
- package/dist-engine-src/src/functions/types.rs +0 -37
- package/dist-engine-src/src/init.rs +0 -692
- package/dist-engine-src/src/json_store/compression.rs +0 -77
- package/dist-engine-src/src/json_store/context.rs +0 -172
- package/dist-engine-src/src/json_store/encoded.rs +0 -15
- package/dist-engine-src/src/json_store/mod.rs +0 -38
- package/dist-engine-src/src/json_store/store.rs +0 -494
- package/dist-engine-src/src/json_store/types.rs +0 -212
- package/dist-engine-src/src/lib.rs +0 -92
- package/dist-engine-src/src/live_state/context.rs +0 -1883
- package/dist-engine-src/src/live_state/mod.rs +0 -21
- package/dist-engine-src/src/live_state/overlay.rs +0 -75
- package/dist-engine-src/src/live_state/reader.rs +0 -23
- package/dist-engine-src/src/live_state/types.rs +0 -231
- package/dist-engine-src/src/live_state/visibility.rs +0 -666
- package/dist-engine-src/src/plugin/archive.rs +0 -438
- package/dist-engine-src/src/plugin/component.rs +0 -183
- package/dist-engine-src/src/plugin/install.rs +0 -619
- package/dist-engine-src/src/plugin/manifest.rs +0 -516
- package/dist-engine-src/src/plugin/materializer.rs +0 -202
- package/dist-engine-src/src/plugin/mod.rs +0 -33
- package/dist-engine-src/src/plugin/plugin_manifest.json +0 -119
- package/dist-engine-src/src/plugin/storage.rs +0 -74
- package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
- package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
- package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
- package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_branch_descriptor.json +0 -34
- package/dist-engine-src/src/schema/builtin/lix_branch_ref.json +0 -48
- package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
- package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
- package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
- package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
- package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
- package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
- package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
- package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
- package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
- package/dist-engine-src/src/schema/builtin/mod.rs +0 -220
- package/dist-engine-src/src/schema/compatibility.rs +0 -787
- package/dist-engine-src/src/schema/definition.json +0 -187
- package/dist-engine-src/src/schema/definition.rs +0 -742
- package/dist-engine-src/src/schema/key.rs +0 -138
- package/dist-engine-src/src/schema/mod.rs +0 -20
- package/dist-engine-src/src/schema/seed.rs +0 -14
- package/dist-engine-src/src/schema/tests.rs +0 -780
- package/dist-engine-src/src/session/context.rs +0 -1059
- package/dist-engine-src/src/session/create_branch.rs +0 -94
- package/dist-engine-src/src/session/execute.rs +0 -681
- package/dist-engine-src/src/session/merge/analysis.rs +0 -108
- package/dist-engine-src/src/session/merge/branch.rs +0 -417
- package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
- package/dist-engine-src/src/session/merge/mod.rs +0 -10
- package/dist-engine-src/src/session/merge/stats.rs +0 -61
- package/dist-engine-src/src/session/mod.rs +0 -30
- package/dist-engine-src/src/session/switch_branch.rs +0 -113
- package/dist-engine-src/src/session/transaction.rs +0 -557
- package/dist-engine-src/src/sql2/bind/classify.rs +0 -102
- package/dist-engine-src/src/sql2/bind/error.rs +0 -5
- package/dist-engine-src/src/sql2/bind/expr.rs +0 -29
- package/dist-engine-src/src/sql2/bind/mod.rs +0 -12
- package/dist-engine-src/src/sql2/bind/public_udf.rs +0 -306
- package/dist-engine-src/src/sql2/bind/read.rs +0 -65
- package/dist-engine-src/src/sql2/bind/statement.rs +0 -2236
- package/dist-engine-src/src/sql2/bind/table.rs +0 -273
- package/dist-engine-src/src/sql2/bind/write.rs +0 -86
- package/dist-engine-src/src/sql2/branch_scope.rs +0 -436
- package/dist-engine-src/src/sql2/catalog/capability.rs +0 -20
- package/dist-engine-src/src/sql2/catalog/entity_surface.rs +0 -296
- package/dist-engine-src/src/sql2/catalog/mod.rs +0 -15
- package/dist-engine-src/src/sql2/catalog/registry.rs +0 -556
- package/dist-engine-src/src/sql2/catalog/schema.rs +0 -88
- package/dist-engine-src/src/sql2/catalog/surface.rs +0 -41
- package/dist-engine-src/src/sql2/change_materialization.rs +0 -122
- package/dist-engine-src/src/sql2/context.rs +0 -317
- package/dist-engine-src/src/sql2/dml.rs +0 -148
- package/dist-engine-src/src/sql2/error.rs +0 -215
- package/dist-engine-src/src/sql2/exec/bound_public_write.rs +0 -1593
- package/dist-engine-src/src/sql2/exec/datafusion.rs +0 -5266
- package/dist-engine-src/src/sql2/exec/fast_write.rs +0 -82
- package/dist-engine-src/src/sql2/exec/mod.rs +0 -24
- package/dist-engine-src/src/sql2/exec/write.rs +0 -661
- package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1485
- package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
- package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
- package/dist-engine-src/src/sql2/history_projection.rs +0 -56
- package/dist-engine-src/src/sql2/history_route.rs +0 -661
- package/dist-engine-src/src/sql2/mod.rs +0 -52
- package/dist-engine-src/src/sql2/optimize/datafusion.rs +0 -1
- package/dist-engine-src/src/sql2/optimize/mod.rs +0 -2
- package/dist-engine-src/src/sql2/optimize/simple_write.rs +0 -116
- package/dist-engine-src/src/sql2/parse/mod.rs +0 -69
- package/dist-engine-src/src/sql2/parse/normalize.rs +0 -1
- package/dist-engine-src/src/sql2/plan/branch_scope.rs +0 -24
- package/dist-engine-src/src/sql2/plan/mod.rs +0 -5
- package/dist-engine-src/src/sql2/plan/predicate.rs +0 -22
- package/dist-engine-src/src/sql2/plan/write.rs +0 -147
- package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -504
- package/dist-engine-src/src/sql2/providers/branch.rs +0 -1206
- package/dist-engine-src/src/sql2/providers/change.rs +0 -445
- package/dist-engine-src/src/sql2/providers/directory.rs +0 -2422
- package/dist-engine-src/src/sql2/providers/directory_history.rs +0 -645
- package/dist-engine-src/src/sql2/providers/entity.rs +0 -1484
- package/dist-engine-src/src/sql2/providers/entity_history.rs +0 -452
- package/dist-engine-src/src/sql2/providers/file.rs +0 -3686
- package/dist-engine-src/src/sql2/providers/file_history.rs +0 -924
- package/dist-engine-src/src/sql2/providers/history.rs +0 -426
- package/dist-engine-src/src/sql2/providers/lix_state.rs +0 -2542
- package/dist-engine-src/src/sql2/providers/mod.rs +0 -508
- package/dist-engine-src/src/sql2/read_only.rs +0 -63
- package/dist-engine-src/src/sql2/record_batch.rs +0 -17
- package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
- package/dist-engine-src/src/sql2/runtime.rs +0 -60
- package/dist-engine-src/src/sql2/session.rs +0 -83
- package/dist-engine-src/src/sql2/storage/constraints.rs +0 -1
- package/dist-engine-src/src/sql2/storage/mod.rs +0 -1
- package/dist-engine-src/src/sql2/test_support/differential.rs +0 -712
- package/dist-engine-src/src/sql2/test_support/generators.rs +0 -354
- package/dist-engine-src/src/sql2/test_support/mod.rs +0 -2
- package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
- package/dist-engine-src/src/sql2/udfs/lix_active_branch_commit_id.rs +0 -53
- package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
- package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
- package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
- package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
- package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
- package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
- package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
- package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
- package/dist-engine-src/src/sql2/udfs/mod.rs +0 -86
- package/dist-engine-src/src/sql2/write_normalization.rs +0 -368
- package/dist-engine-src/src/storage/conformance.rs +0 -399
- package/dist-engine-src/src/storage/context.rs +0 -620
- package/dist-engine-src/src/storage/mod.rs +0 -52
- package/dist-engine-src/src/storage/point.rs +0 -440
- package/dist-engine-src/src/storage/read_scope.rs +0 -67
- package/dist-engine-src/src/storage/reader.rs +0 -867
- package/dist-engine-src/src/storage/scan.rs +0 -784
- package/dist-engine-src/src/storage/spaces.rs +0 -236
- package/dist-engine-src/src/storage/stats.rs +0 -80
- package/dist-engine-src/src/storage/write_set.rs +0 -962
- package/dist-engine-src/src/storage_bench.rs +0 -171
- package/dist-engine-src/src/test_support.rs +0 -450
- package/dist-engine-src/src/tracked_state/bench_support.rs +0 -394
- package/dist-engine-src/src/tracked_state/codec.rs +0 -1183
- package/dist-engine-src/src/tracked_state/commit_root_rebuild.rs +0 -358
- package/dist-engine-src/src/tracked_state/context.rs +0 -2801
- package/dist-engine-src/src/tracked_state/diff.rs +0 -2140
- package/dist-engine-src/src/tracked_state/merge.rs +0 -478
- package/dist-engine-src/src/tracked_state/mod.rs +0 -35
- package/dist-engine-src/src/tracked_state/row_materialization.rs +0 -275
- package/dist-engine-src/src/tracked_state/storage.rs +0 -427
- package/dist-engine-src/src/tracked_state/tree.rs +0 -3063
- package/dist-engine-src/src/tracked_state/types.rs +0 -238
- package/dist-engine-src/src/transaction/bench_support.rs +0 -407
- package/dist-engine-src/src/transaction/commit.rs +0 -1592
- package/dist-engine-src/src/transaction/context.rs +0 -1653
- package/dist-engine-src/src/transaction/mod.rs +0 -24
- package/dist-engine-src/src/transaction/normalization.rs +0 -877
- package/dist-engine-src/src/transaction/prep.rs +0 -37
- package/dist-engine-src/src/transaction/schema_resolver.rs +0 -163
- package/dist-engine-src/src/transaction/staging.rs +0 -1525
- package/dist-engine-src/src/transaction/types.rs +0 -403
- package/dist-engine-src/src/transaction/validation.rs +0 -5766
- package/dist-engine-src/src/untracked_state/codec.rs +0 -615
- package/dist-engine-src/src/untracked_state/context.rs +0 -98
- package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
- package/dist-engine-src/src/untracked_state/mod.rs +0 -15
- package/dist-engine-src/src/untracked_state/storage.rs +0 -898
- package/dist-engine-src/src/untracked_state/types.rs +0 -146
- package/dist-engine-src/src/wasm/mod.rs +0 -60
|
@@ -1,661 +0,0 @@
|
|
|
1
|
-
use std::collections::BTreeMap;
|
|
2
|
-
use std::sync::Arc;
|
|
3
|
-
|
|
4
|
-
use datafusion::common::ScalarValue;
|
|
5
|
-
use datafusion::logical_expr::expr::InList;
|
|
6
|
-
use datafusion::logical_expr::{Expr, Operator};
|
|
7
|
-
use tokio::sync::Mutex;
|
|
8
|
-
|
|
9
|
-
use crate::commit_graph::{CommitGraphChangeHistoryRequest, CommitGraphReader};
|
|
10
|
-
use crate::entity_pk::EntityPk;
|
|
11
|
-
use crate::LixError;
|
|
12
|
-
|
|
13
|
-
use super::SqlJsonReader;
|
|
14
|
-
use crate::sql2::change_materialization::{materialize_located_history_change, MaterializedChange};
|
|
15
|
-
use crate::storage::StorageRead;
|
|
16
|
-
|
|
17
|
-
/// Shared routing state for commit-shaped history SQL surfaces.
|
|
18
|
-
///
|
|
19
|
-
/// History providers differ in how they shape rows, but they should not drift
|
|
20
|
-
/// in how they interpret filters such as `start_commit_id IN (...)`, entity
|
|
21
|
-
/// filters, or depth ranges.
|
|
22
|
-
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
|
23
|
-
pub(crate) struct HistoryRoute {
|
|
24
|
-
pub(crate) start_commit_ids: Vec<String>,
|
|
25
|
-
pub(crate) entity_pks: Vec<String>,
|
|
26
|
-
pub(crate) schema_keys: Vec<String>,
|
|
27
|
-
pub(crate) file_ids: Vec<String>,
|
|
28
|
-
pub(crate) min_depth: Option<i64>,
|
|
29
|
-
pub(crate) max_depth: Option<i64>,
|
|
30
|
-
pub(crate) contradictory: bool,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
impl HistoryRoute {
|
|
34
|
-
pub(crate) fn from_filters(filters: &[Expr], column_style: HistoryColumnStyle) -> Self {
|
|
35
|
-
let mut route = Self::default();
|
|
36
|
-
for filter in filters {
|
|
37
|
-
apply_history_filter(filter, &mut route, column_style);
|
|
38
|
-
}
|
|
39
|
-
route
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/// Returns the part of the route that is safe to apply before a shaped
|
|
43
|
-
/// history provider has built its output rows.
|
|
44
|
-
///
|
|
45
|
-
/// Surface providers such as `lix_file_history` may be caused by different
|
|
46
|
-
/// canonical event schemas than the schema they expose. For those providers,
|
|
47
|
-
/// identity/schema filters must be evaluated against the shaped output row,
|
|
48
|
-
/// not against the canonical event row.
|
|
49
|
-
pub(crate) fn traversal_only(&self) -> Self {
|
|
50
|
-
Self {
|
|
51
|
-
start_commit_ids: self.start_commit_ids.clone(),
|
|
52
|
-
min_depth: self.min_depth,
|
|
53
|
-
max_depth: self.max_depth,
|
|
54
|
-
contradictory: self.contradictory,
|
|
55
|
-
..Self::default()
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/// Returns only the explicit history starts.
|
|
60
|
-
///
|
|
61
|
-
/// Shaped history providers use this for context loading: path/data shaping
|
|
62
|
-
/// often needs ancestor descriptor rows even when the event route is
|
|
63
|
-
/// restricted to a specific depth.
|
|
64
|
-
pub(crate) fn starts_only(&self) -> Self {
|
|
65
|
-
Self {
|
|
66
|
-
start_commit_ids: self.start_commit_ids.clone(),
|
|
67
|
-
contradictory: self.contradictory,
|
|
68
|
-
..Self::default()
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
pub(crate) fn is_contradictory(&self) -> bool {
|
|
73
|
-
self.contradictory
|
|
74
|
-
|| self
|
|
75
|
-
.min_depth
|
|
76
|
-
.zip(self.max_depth)
|
|
77
|
-
.is_some_and(|(min, max)| min > max)
|
|
78
|
-
|| self.min_depth.is_some_and(|depth| depth < 0)
|
|
79
|
-
|| self.max_depth.is_some_and(|depth| depth < 0)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/// Checks filters that refer to the row exposed by a shaped history surface.
|
|
83
|
-
pub(crate) fn matches_surface_row(
|
|
84
|
-
&self,
|
|
85
|
-
schema_key: &str,
|
|
86
|
-
entity_pk: &str,
|
|
87
|
-
file_id: Option<&str>,
|
|
88
|
-
depth: u32,
|
|
89
|
-
) -> bool {
|
|
90
|
-
if self.is_contradictory() {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
if !self.schema_keys.is_empty()
|
|
94
|
-
&& !self
|
|
95
|
-
.schema_keys
|
|
96
|
-
.iter()
|
|
97
|
-
.any(|candidate| candidate == schema_key)
|
|
98
|
-
{
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
if !self.entity_pks.is_empty()
|
|
102
|
-
&& !self
|
|
103
|
-
.entity_pks
|
|
104
|
-
.iter()
|
|
105
|
-
.any(|candidate| candidate == entity_pk)
|
|
106
|
-
{
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
if !self.file_ids.is_empty() {
|
|
110
|
-
let Some(file_id) = file_id else {
|
|
111
|
-
return false;
|
|
112
|
-
};
|
|
113
|
-
if !self.file_ids.iter().any(|candidate| candidate == file_id) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if self
|
|
118
|
-
.min_depth
|
|
119
|
-
.is_some_and(|min_depth| i64::from(depth) < min_depth)
|
|
120
|
-
{
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
if self
|
|
124
|
-
.max_depth
|
|
125
|
-
.is_some_and(|max_depth| i64::from(depth) > max_depth)
|
|
126
|
-
{
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
true
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/// Commit-graph history entry enriched with commit metadata needed by SQL
|
|
134
|
-
/// history surfaces.
|
|
135
|
-
#[derive(Debug, Clone)]
|
|
136
|
-
pub(crate) struct HistoryEntry {
|
|
137
|
-
pub(crate) change: MaterializedChange,
|
|
138
|
-
pub(crate) observed_commit_id: String,
|
|
139
|
-
pub(crate) commit_created_at: String,
|
|
140
|
-
pub(crate) start_commit_id: String,
|
|
141
|
-
pub(crate) depth: u32,
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
pub(crate) const HISTORY_COL_ENTITY_PK: &str = "lixcol_entity_pk";
|
|
145
|
-
pub(crate) const HISTORY_COL_SCHEMA_KEY: &str = "lixcol_schema_key";
|
|
146
|
-
pub(crate) const HISTORY_COL_FILE_ID: &str = "lixcol_file_id";
|
|
147
|
-
pub(crate) const HISTORY_COL_SNAPSHOT_CONTENT: &str = "lixcol_snapshot_content";
|
|
148
|
-
pub(crate) const HISTORY_COL_METADATA: &str = "lixcol_metadata";
|
|
149
|
-
pub(crate) const HISTORY_COL_CHANGE_ID: &str = "lixcol_change_id";
|
|
150
|
-
pub(crate) const HISTORY_COL_OBSERVED_COMMIT_ID: &str = "lixcol_observed_commit_id";
|
|
151
|
-
pub(crate) const HISTORY_COL_COMMIT_CREATED_AT: &str = "lixcol_commit_created_at";
|
|
152
|
-
pub(crate) const HISTORY_COL_START_COMMIT_ID: &str = "lixcol_start_commit_id";
|
|
153
|
-
pub(crate) const HISTORY_COL_DEPTH: &str = "lixcol_depth";
|
|
154
|
-
|
|
155
|
-
pub(crate) struct HistoryViewDescriptor<'a> {
|
|
156
|
-
pub(crate) view_name: &'a str,
|
|
157
|
-
pub(crate) start_commit_column: &'a str,
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
#[derive(Debug, Clone, Copy)]
|
|
161
|
-
pub(crate) enum HistoryColumnStyle {
|
|
162
|
-
Bare,
|
|
163
|
-
Prefixed,
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/// Shaped history views expose delete events as tombstone rows.
|
|
167
|
-
///
|
|
168
|
-
/// If the current event is the descriptor tombstone itself, the provider must
|
|
169
|
-
/// use that tombstone row instead of looking through to an earlier live
|
|
170
|
-
/// descriptor. This keeps one contract across typed entity, file, directory,
|
|
171
|
-
/// and state history: `snapshot_content IS NULL` means projected user/domain
|
|
172
|
-
/// columns are NULL while metadata columns still identify the event.
|
|
173
|
-
pub(crate) fn history_descriptor_event_matches(
|
|
174
|
-
descriptor_entry: &HistoryEntry,
|
|
175
|
-
event_depth: u32,
|
|
176
|
-
event_change_id: &str,
|
|
177
|
-
) -> bool {
|
|
178
|
-
descriptor_entry.depth == event_depth && descriptor_entry.change.id == event_change_id
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
pub(crate) fn parse_history_filter(expr: &Expr, column_style: HistoryColumnStyle) -> Option<()> {
|
|
182
|
-
parse_history_filter_terms(expr, column_style).map(|_| ())
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
pub(crate) fn commit_graph_history_request(
|
|
186
|
-
route: &HistoryRoute,
|
|
187
|
-
schema_keys: Vec<String>,
|
|
188
|
-
) -> Option<CommitGraphChangeHistoryRequest> {
|
|
189
|
-
let schema_keys = effective_schema_keys(route, schema_keys)?;
|
|
190
|
-
Some(CommitGraphChangeHistoryRequest {
|
|
191
|
-
entity_pks: route
|
|
192
|
-
.entity_pks
|
|
193
|
-
.iter()
|
|
194
|
-
.filter_map(|entity_pk| EntityPk::from_json_array_text(entity_pk).ok())
|
|
195
|
-
.collect(),
|
|
196
|
-
schema_keys,
|
|
197
|
-
file_ids: route.file_ids.clone(),
|
|
198
|
-
min_depth: route.min_depth.and_then(nonnegative_u32),
|
|
199
|
-
max_depth: route.max_depth.and_then(nonnegative_u32),
|
|
200
|
-
include_tombstones: true,
|
|
201
|
-
})
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/// Loads reachability-aware commit-graph history once for all SQL history providers.
|
|
205
|
-
///
|
|
206
|
-
/// Providers pass the schema keys they know how to shape. An empty list means
|
|
207
|
-
/// "do not constrain by provider schema"; this is what `lix_state_history` uses.
|
|
208
|
-
pub(crate) async fn load_history_entries<S>(
|
|
209
|
-
descriptor: HistoryViewDescriptor<'_>,
|
|
210
|
-
commit_graph: Arc<Mutex<Box<dyn CommitGraphReader>>>,
|
|
211
|
-
mut json_reader: SqlJsonReader<S>,
|
|
212
|
-
route: &HistoryRoute,
|
|
213
|
-
schema_keys: Vec<String>,
|
|
214
|
-
) -> Result<Vec<HistoryEntry>, LixError>
|
|
215
|
-
where
|
|
216
|
-
S: StorageRead + Clone + Send + Sync + 'static,
|
|
217
|
-
{
|
|
218
|
-
if route.is_contradictory() {
|
|
219
|
-
return Ok(Vec::new());
|
|
220
|
-
}
|
|
221
|
-
if route.start_commit_ids.is_empty() {
|
|
222
|
-
return Err(LixError::new(
|
|
223
|
-
LixError::CODE_HISTORY_FILTER_REQUIRED,
|
|
224
|
-
format!(
|
|
225
|
-
"{} requires a {} filter",
|
|
226
|
-
descriptor.view_name, descriptor.start_commit_column
|
|
227
|
-
),
|
|
228
|
-
)
|
|
229
|
-
.with_hint(format!(
|
|
230
|
-
"Use WHERE {} = lix_active_branch_commit_id() to inspect {} from the active branch head.",
|
|
231
|
-
descriptor.start_commit_column, descriptor.view_name
|
|
232
|
-
)));
|
|
233
|
-
}
|
|
234
|
-
let Some(request) = commit_graph_history_request(route, schema_keys) else {
|
|
235
|
-
return Ok(Vec::new());
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
let mut rows = Vec::new();
|
|
239
|
-
for start_commit_id in &route.start_commit_ids {
|
|
240
|
-
let (entries, reachable_commits) = {
|
|
241
|
-
let mut guard = commit_graph.lock().await;
|
|
242
|
-
let entries = guard
|
|
243
|
-
.change_history_from_commit(start_commit_id, &request)
|
|
244
|
-
.await?;
|
|
245
|
-
let reachable_commits = guard.reachable_commits(start_commit_id).await?;
|
|
246
|
-
(entries, reachable_commits)
|
|
247
|
-
};
|
|
248
|
-
let commit_created_at_by_id = reachable_commits
|
|
249
|
-
.into_iter()
|
|
250
|
-
.map(|reachable| {
|
|
251
|
-
(
|
|
252
|
-
reachable.commit.commit_id.clone(),
|
|
253
|
-
reachable.commit.change.created_at.clone(),
|
|
254
|
-
)
|
|
255
|
-
})
|
|
256
|
-
.collect::<BTreeMap<_, _>>();
|
|
257
|
-
|
|
258
|
-
for entry in entries {
|
|
259
|
-
let change = materialize_located_history_change(&mut json_reader, entry.change).await?;
|
|
260
|
-
rows.push(HistoryEntry {
|
|
261
|
-
commit_created_at: commit_created_at_by_id
|
|
262
|
-
.get(&entry.observed_commit_id)
|
|
263
|
-
.cloned()
|
|
264
|
-
.unwrap_or_else(|| change.created_at.clone()),
|
|
265
|
-
change,
|
|
266
|
-
observed_commit_id: entry.observed_commit_id,
|
|
267
|
-
start_commit_id: entry.start_commit_id,
|
|
268
|
-
depth: entry.depth,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
Ok(rows)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
fn effective_schema_keys(
|
|
277
|
-
route: &HistoryRoute,
|
|
278
|
-
surface_schema_keys: Vec<String>,
|
|
279
|
-
) -> Option<Vec<String>> {
|
|
280
|
-
if surface_schema_keys.is_empty() {
|
|
281
|
-
return Some(route.schema_keys.clone());
|
|
282
|
-
}
|
|
283
|
-
if route.schema_keys.is_empty() {
|
|
284
|
-
return Some(surface_schema_keys);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
let mut effective = Vec::new();
|
|
288
|
-
for schema_key in surface_schema_keys {
|
|
289
|
-
if route.schema_keys.contains(&schema_key) && !effective.contains(&schema_key) {
|
|
290
|
-
effective.push(schema_key);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if effective.is_empty() {
|
|
294
|
-
None
|
|
295
|
-
} else {
|
|
296
|
-
Some(effective)
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
fn parse_history_filter_terms(
|
|
301
|
-
expr: &Expr,
|
|
302
|
-
column_style: HistoryColumnStyle,
|
|
303
|
-
) -> Option<Vec<HistoryFilterTerm>> {
|
|
304
|
-
match expr {
|
|
305
|
-
Expr::BinaryExpr(binary_expr) if binary_expr.op == Operator::And => {
|
|
306
|
-
let mut terms = parse_history_filter_terms(&binary_expr.left, column_style)?;
|
|
307
|
-
terms.extend(parse_history_filter_terms(
|
|
308
|
-
&binary_expr.right,
|
|
309
|
-
column_style,
|
|
310
|
-
)?);
|
|
311
|
-
Some(terms)
|
|
312
|
-
}
|
|
313
|
-
Expr::BinaryExpr(binary_expr) if binary_expr.op == Operator::Or => {
|
|
314
|
-
parse_history_disjunction(binary_expr, column_style)
|
|
315
|
-
}
|
|
316
|
-
Expr::BinaryExpr(binary_expr) => {
|
|
317
|
-
parse_history_binary_filter(binary_expr, column_style).map(|term| vec![term])
|
|
318
|
-
}
|
|
319
|
-
Expr::InList(in_list) => {
|
|
320
|
-
parse_history_in_list_filter(in_list, column_style).map(|term| vec![term])
|
|
321
|
-
}
|
|
322
|
-
_ => None,
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
fn collect_history_route_terms(
|
|
327
|
-
expr: &Expr,
|
|
328
|
-
column_style: HistoryColumnStyle,
|
|
329
|
-
) -> Vec<HistoryFilterTerm> {
|
|
330
|
-
match expr {
|
|
331
|
-
Expr::BinaryExpr(binary_expr) if binary_expr.op == Operator::And => {
|
|
332
|
-
let mut terms = collect_history_route_terms(&binary_expr.left, column_style);
|
|
333
|
-
terms.extend(collect_history_route_terms(
|
|
334
|
-
&binary_expr.right,
|
|
335
|
-
column_style,
|
|
336
|
-
));
|
|
337
|
-
terms
|
|
338
|
-
}
|
|
339
|
-
// OR filters are only safe to route when the entire disjunction is a
|
|
340
|
-
// supported history predicate. Partially routing one side would change
|
|
341
|
-
// SQL semantics before DataFusion can apply the residual filter.
|
|
342
|
-
Expr::BinaryExpr(binary_expr) if binary_expr.op == Operator::Or => {
|
|
343
|
-
parse_history_disjunction(binary_expr, column_style).unwrap_or_default()
|
|
344
|
-
}
|
|
345
|
-
Expr::BinaryExpr(binary_expr) => parse_history_binary_filter(binary_expr, column_style)
|
|
346
|
-
.map(|term| vec![term])
|
|
347
|
-
.unwrap_or_default(),
|
|
348
|
-
Expr::InList(in_list) => parse_history_in_list_filter(in_list, column_style)
|
|
349
|
-
.map(|term| vec![term])
|
|
350
|
-
.unwrap_or_default(),
|
|
351
|
-
_ => Vec::new(),
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
fn parse_history_disjunction(
|
|
356
|
-
binary_expr: &datafusion::logical_expr::BinaryExpr,
|
|
357
|
-
column_style: HistoryColumnStyle,
|
|
358
|
-
) -> Option<Vec<HistoryFilterTerm>> {
|
|
359
|
-
let left = parse_history_filter_terms(&binary_expr.left, column_style)?;
|
|
360
|
-
let right = parse_history_filter_terms(&binary_expr.right, column_style)?;
|
|
361
|
-
let [left] = left.as_slice() else {
|
|
362
|
-
return None;
|
|
363
|
-
};
|
|
364
|
-
let [right] = right.as_slice() else {
|
|
365
|
-
return None;
|
|
366
|
-
};
|
|
367
|
-
merge_history_disjunction_terms(left.clone(), right.clone()).map(|term| vec![term])
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
371
|
-
enum HistoryFilterTerm {
|
|
372
|
-
StartCommitIds(Vec<String>),
|
|
373
|
-
EntityPks(Vec<String>),
|
|
374
|
-
SchemaKeys(Vec<String>),
|
|
375
|
-
FileIds(Vec<String>),
|
|
376
|
-
MinDepth(i64),
|
|
377
|
-
MaxDepth(i64),
|
|
378
|
-
ExactDepth(i64),
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
fn merge_history_disjunction_terms(
|
|
382
|
-
left: HistoryFilterTerm,
|
|
383
|
-
right: HistoryFilterTerm,
|
|
384
|
-
) -> Option<HistoryFilterTerm> {
|
|
385
|
-
match (left, right) {
|
|
386
|
-
(HistoryFilterTerm::StartCommitIds(mut left), HistoryFilterTerm::StartCommitIds(right)) => {
|
|
387
|
-
extend_unique(&mut left, right);
|
|
388
|
-
Some(HistoryFilterTerm::StartCommitIds(left))
|
|
389
|
-
}
|
|
390
|
-
(HistoryFilterTerm::EntityPks(mut left), HistoryFilterTerm::EntityPks(right)) => {
|
|
391
|
-
extend_unique(&mut left, right);
|
|
392
|
-
Some(HistoryFilterTerm::EntityPks(left))
|
|
393
|
-
}
|
|
394
|
-
(HistoryFilterTerm::FileIds(mut left), HistoryFilterTerm::FileIds(right)) => {
|
|
395
|
-
extend_unique(&mut left, right);
|
|
396
|
-
Some(HistoryFilterTerm::FileIds(left))
|
|
397
|
-
}
|
|
398
|
-
(HistoryFilterTerm::SchemaKeys(mut left), HistoryFilterTerm::SchemaKeys(right)) => {
|
|
399
|
-
extend_unique(&mut left, right);
|
|
400
|
-
Some(HistoryFilterTerm::SchemaKeys(left))
|
|
401
|
-
}
|
|
402
|
-
_ => None,
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
fn parse_history_binary_filter(
|
|
407
|
-
binary_expr: &datafusion::logical_expr::BinaryExpr,
|
|
408
|
-
column_style: HistoryColumnStyle,
|
|
409
|
-
) -> Option<HistoryFilterTerm> {
|
|
410
|
-
let Expr::Column(column) = &*binary_expr.left else {
|
|
411
|
-
return None;
|
|
412
|
-
};
|
|
413
|
-
let column_name = canonical_history_column_name(column.name.as_str(), column_style)?;
|
|
414
|
-
let right = &*binary_expr.right;
|
|
415
|
-
match (column_name, &binary_expr.op, right) {
|
|
416
|
-
("start_commit_id", Operator::Eq, Expr::Literal(ScalarValue::Utf8(Some(value)), _))
|
|
417
|
-
| ("schema_key", Operator::Eq, Expr::Literal(ScalarValue::Utf8(Some(value)), _))
|
|
418
|
-
| ("file_id", Operator::Eq, Expr::Literal(ScalarValue::Utf8(Some(value)), _)) => {
|
|
419
|
-
Some(match column_name {
|
|
420
|
-
"start_commit_id" => HistoryFilterTerm::StartCommitIds(vec![value.clone()]),
|
|
421
|
-
"schema_key" => HistoryFilterTerm::SchemaKeys(vec![value.clone()]),
|
|
422
|
-
"file_id" => HistoryFilterTerm::FileIds(vec![value.clone()]),
|
|
423
|
-
_ => unreachable!(),
|
|
424
|
-
})
|
|
425
|
-
}
|
|
426
|
-
("entity_pk", Operator::Eq, Expr::Literal(ScalarValue::Utf8(Some(value)), _)) => {
|
|
427
|
-
canonical_entity_pk_value(value).map(|value| HistoryFilterTerm::EntityPks(vec![value]))
|
|
428
|
-
}
|
|
429
|
-
("depth", Operator::Eq, depth_expr) => {
|
|
430
|
-
scalar_i64_literal(depth_expr).map(HistoryFilterTerm::ExactDepth)
|
|
431
|
-
}
|
|
432
|
-
("depth", Operator::Gt, depth_expr) => {
|
|
433
|
-
scalar_i64_literal(depth_expr).map(|value| HistoryFilterTerm::MinDepth(value + 1))
|
|
434
|
-
}
|
|
435
|
-
("depth", Operator::GtEq, depth_expr) => {
|
|
436
|
-
scalar_i64_literal(depth_expr).map(HistoryFilterTerm::MinDepth)
|
|
437
|
-
}
|
|
438
|
-
("depth", Operator::Lt, depth_expr) => {
|
|
439
|
-
scalar_i64_literal(depth_expr).map(|value| HistoryFilterTerm::MaxDepth(value - 1))
|
|
440
|
-
}
|
|
441
|
-
("depth", Operator::LtEq, depth_expr) => {
|
|
442
|
-
scalar_i64_literal(depth_expr).map(HistoryFilterTerm::MaxDepth)
|
|
443
|
-
}
|
|
444
|
-
_ => None,
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
fn parse_history_in_list_filter(
|
|
449
|
-
in_list: &InList,
|
|
450
|
-
column_style: HistoryColumnStyle,
|
|
451
|
-
) -> Option<HistoryFilterTerm> {
|
|
452
|
-
if in_list.negated {
|
|
453
|
-
return None;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
let Expr::Column(column) = in_list.expr.as_ref() else {
|
|
457
|
-
return None;
|
|
458
|
-
};
|
|
459
|
-
let column_name = canonical_history_column_name(column.name.as_str(), column_style)?;
|
|
460
|
-
let values = in_list
|
|
461
|
-
.list
|
|
462
|
-
.iter()
|
|
463
|
-
.map(string_literal)
|
|
464
|
-
.collect::<Option<Vec<_>>>()?;
|
|
465
|
-
if values.is_empty() {
|
|
466
|
-
return None;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
match column_name {
|
|
470
|
-
"start_commit_id" => Some(HistoryFilterTerm::StartCommitIds(values)),
|
|
471
|
-
"entity_pk" => canonical_entity_pk_values(values).map(HistoryFilterTerm::EntityPks),
|
|
472
|
-
"schema_key" => Some(HistoryFilterTerm::SchemaKeys(values)),
|
|
473
|
-
"file_id" => Some(HistoryFilterTerm::FileIds(values)),
|
|
474
|
-
_ => None,
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
fn apply_history_filter(expr: &Expr, route: &mut HistoryRoute, column_style: HistoryColumnStyle) {
|
|
479
|
-
for term in collect_history_route_terms(expr, column_style) {
|
|
480
|
-
match term {
|
|
481
|
-
HistoryFilterTerm::StartCommitIds(values) => {
|
|
482
|
-
route.contradictory |=
|
|
483
|
-
apply_conjunctive_values_filter(&mut route.start_commit_ids, values)
|
|
484
|
-
}
|
|
485
|
-
HistoryFilterTerm::EntityPks(values) => {
|
|
486
|
-
route.contradictory |=
|
|
487
|
-
apply_conjunctive_values_filter(&mut route.entity_pks, values)
|
|
488
|
-
}
|
|
489
|
-
HistoryFilterTerm::SchemaKeys(values) => {
|
|
490
|
-
route.contradictory |=
|
|
491
|
-
apply_conjunctive_values_filter(&mut route.schema_keys, values)
|
|
492
|
-
}
|
|
493
|
-
HistoryFilterTerm::FileIds(values) => {
|
|
494
|
-
route.contradictory |= apply_conjunctive_values_filter(&mut route.file_ids, values)
|
|
495
|
-
}
|
|
496
|
-
HistoryFilterTerm::ExactDepth(value) => {
|
|
497
|
-
route.min_depth = Some(value);
|
|
498
|
-
route.max_depth = Some(value);
|
|
499
|
-
}
|
|
500
|
-
HistoryFilterTerm::MinDepth(value) => {
|
|
501
|
-
route.min_depth = Some(route.min_depth.map_or(value, |current| current.max(value)));
|
|
502
|
-
}
|
|
503
|
-
HistoryFilterTerm::MaxDepth(value) => {
|
|
504
|
-
route.max_depth = Some(route.max_depth.map_or(value, |current| current.min(value)));
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
fn apply_conjunctive_values_filter(bucket: &mut Vec<String>, incoming_values: Vec<String>) -> bool {
|
|
511
|
-
let mut values = Vec::new();
|
|
512
|
-
extend_unique(&mut values, incoming_values);
|
|
513
|
-
if values.is_empty() {
|
|
514
|
-
return true;
|
|
515
|
-
}
|
|
516
|
-
if bucket.is_empty() {
|
|
517
|
-
extend_unique(bucket, values);
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
bucket.retain(|existing| values.contains(existing));
|
|
522
|
-
bucket.is_empty()
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
fn canonical_entity_pk_values(values: Vec<String>) -> Option<Vec<String>> {
|
|
526
|
-
values
|
|
527
|
-
.into_iter()
|
|
528
|
-
.map(|value| canonical_entity_pk_value(&value))
|
|
529
|
-
.collect()
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
fn canonical_entity_pk_value(value: &str) -> Option<String> {
|
|
533
|
-
EntityPk::from_json_array_text(value)
|
|
534
|
-
.ok()?
|
|
535
|
-
.as_json_array_text()
|
|
536
|
-
.ok()
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
fn canonical_history_column_name(name: &str, column_style: HistoryColumnStyle) -> Option<&str> {
|
|
540
|
-
match (column_style, name) {
|
|
541
|
-
(HistoryColumnStyle::Bare, "start_commit_id")
|
|
542
|
-
| (HistoryColumnStyle::Prefixed, "lixcol_start_commit_id") => Some("start_commit_id"),
|
|
543
|
-
(HistoryColumnStyle::Bare, "entity_pk")
|
|
544
|
-
| (HistoryColumnStyle::Prefixed, "lixcol_entity_pk") => Some("entity_pk"),
|
|
545
|
-
(HistoryColumnStyle::Bare, "schema_key")
|
|
546
|
-
| (HistoryColumnStyle::Prefixed, "lixcol_schema_key") => Some("schema_key"),
|
|
547
|
-
(HistoryColumnStyle::Bare, "file_id")
|
|
548
|
-
| (HistoryColumnStyle::Prefixed, "lixcol_file_id") => Some("file_id"),
|
|
549
|
-
(HistoryColumnStyle::Bare, "depth") | (HistoryColumnStyle::Prefixed, "lixcol_depth") => {
|
|
550
|
-
Some("depth")
|
|
551
|
-
}
|
|
552
|
-
_ => None,
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
fn nonnegative_u32(value: i64) -> Option<u32> {
|
|
557
|
-
u32::try_from(value).ok()
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
fn extend_unique(bucket: &mut Vec<String>, values: Vec<String>) {
|
|
561
|
-
for value in values {
|
|
562
|
-
if !bucket.contains(&value) {
|
|
563
|
-
bucket.push(value);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
fn string_literal(expr: &Expr) -> Option<String> {
|
|
569
|
-
match expr {
|
|
570
|
-
Expr::Literal(ScalarValue::Utf8(Some(value)), _) => Some(value.clone()),
|
|
571
|
-
_ => None,
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
fn scalar_i64_literal(expr: &Expr) -> Option<i64> {
|
|
576
|
-
match expr {
|
|
577
|
-
Expr::Literal(ScalarValue::Int8(Some(value)), _) => Some(i64::from(*value)),
|
|
578
|
-
Expr::Literal(ScalarValue::Int16(Some(value)), _) => Some(i64::from(*value)),
|
|
579
|
-
Expr::Literal(ScalarValue::Int32(Some(value)), _) => Some(i64::from(*value)),
|
|
580
|
-
Expr::Literal(ScalarValue::Int64(Some(value)), _) => Some(*value),
|
|
581
|
-
Expr::Literal(ScalarValue::UInt8(Some(value)), _) => Some(i64::from(*value)),
|
|
582
|
-
Expr::Literal(ScalarValue::UInt16(Some(value)), _) => Some(i64::from(*value)),
|
|
583
|
-
Expr::Literal(ScalarValue::UInt32(Some(value)), _) => Some(i64::from(*value)),
|
|
584
|
-
Expr::Literal(ScalarValue::UInt64(Some(value)), _) => i64::try_from(*value).ok(),
|
|
585
|
-
_ => None,
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
#[cfg(test)]
|
|
590
|
-
mod tests {
|
|
591
|
-
use datafusion::common::{Column, ScalarValue};
|
|
592
|
-
use datafusion::logical_expr::{BinaryExpr, Expr, Like, Operator};
|
|
593
|
-
|
|
594
|
-
use super::{parse_history_filter, HistoryColumnStyle, HistoryRoute};
|
|
595
|
-
|
|
596
|
-
#[test]
|
|
597
|
-
fn route_extraction_keeps_supported_terms_from_mixed_and_filter() {
|
|
598
|
-
let filter = and(
|
|
599
|
-
eq(col("start_commit_id"), str_lit("commit-1")),
|
|
600
|
-
Expr::Like(Like::new(
|
|
601
|
-
false,
|
|
602
|
-
Box::new(col("path")),
|
|
603
|
-
Box::new(str_lit("/docs/%")),
|
|
604
|
-
None,
|
|
605
|
-
false,
|
|
606
|
-
)),
|
|
607
|
-
);
|
|
608
|
-
|
|
609
|
-
assert!(
|
|
610
|
-
parse_history_filter(&filter, HistoryColumnStyle::Bare).is_none(),
|
|
611
|
-
"mixed filters must not be advertised as exact pushdown"
|
|
612
|
-
);
|
|
613
|
-
|
|
614
|
-
let route = HistoryRoute::from_filters(&[filter], HistoryColumnStyle::Bare);
|
|
615
|
-
assert_eq!(route.start_commit_ids, vec!["commit-1".to_string()]);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
#[test]
|
|
619
|
-
fn route_extraction_does_not_partially_route_mixed_or_filter() {
|
|
620
|
-
let filter = or(
|
|
621
|
-
eq(col("start_commit_id"), str_lit("commit-1")),
|
|
622
|
-
Expr::Like(Like::new(
|
|
623
|
-
false,
|
|
624
|
-
Box::new(col("path")),
|
|
625
|
-
Box::new(str_lit("/docs/%")),
|
|
626
|
-
None,
|
|
627
|
-
false,
|
|
628
|
-
)),
|
|
629
|
-
);
|
|
630
|
-
|
|
631
|
-
let route = HistoryRoute::from_filters(&[filter], HistoryColumnStyle::Bare);
|
|
632
|
-
assert!(
|
|
633
|
-
route.start_commit_ids.is_empty(),
|
|
634
|
-
"partial OR pushdown would change SQL semantics"
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
fn and(left: Expr, right: Expr) -> Expr {
|
|
639
|
-
binary(left, Operator::And, right)
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
fn or(left: Expr, right: Expr) -> Expr {
|
|
643
|
-
binary(left, Operator::Or, right)
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
fn eq(left: Expr, right: Expr) -> Expr {
|
|
647
|
-
binary(left, Operator::Eq, right)
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
fn binary(left: Expr, op: Operator, right: Expr) -> Expr {
|
|
651
|
-
Expr::BinaryExpr(BinaryExpr::new(Box::new(left), op, Box::new(right)))
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
fn col(name: &str) -> Expr {
|
|
655
|
-
Expr::Column(Column::from_name(name))
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
fn str_lit(value: &str) -> Expr {
|
|
659
|
-
Expr::Literal(ScalarValue::Utf8(Some(value.to_string())), None)
|
|
660
|
-
}
|
|
661
|
-
}
|