Skip to main content

nodedb_sql/engine_rules/
columnar.rs

1//! Engine rules for plain columnar collections.
2
3use crate::engine_rules::*;
4use crate::error::Result;
5use crate::types::*;
6
7pub struct ColumnarRules;
8
9impl EngineRules for ColumnarRules {
10    fn plan_insert(&self, p: InsertParams) -> Result<Vec<SqlPlan>> {
11        Ok(vec![SqlPlan::Insert {
12            collection: p.collection,
13            engine: EngineType::Columnar,
14            rows: p.rows,
15            column_defaults: p.column_defaults,
16            if_absent: p.if_absent,
17        }])
18    }
19
20    /// `UPSERT` / `INSERT ... ON CONFLICT (pk) DO UPDATE` on columnar.
21    /// Duplicate PK tombstones the prior row via the segment's delete
22    /// bitmap; the new row (or its merged form, when `on_conflict_updates`
23    /// is non-empty) is appended. Sort-key semantics are unchanged.
24    fn plan_upsert(&self, p: UpsertParams) -> Result<Vec<SqlPlan>> {
25        Ok(vec![SqlPlan::Upsert {
26            collection: p.collection,
27            engine: EngineType::Columnar,
28            rows: p.rows,
29            column_defaults: p.column_defaults,
30            on_conflict_updates: p.on_conflict_updates,
31        }])
32    }
33
34    fn plan_scan(&self, p: ScanParams) -> Result<SqlPlan> {
35        Ok(SqlPlan::Scan {
36            collection: p.collection,
37            alias: p.alias,
38            engine: EngineType::Columnar,
39            filters: p.filters,
40            projection: p.projection,
41            sort_keys: p.sort_keys,
42            limit: p.limit,
43            offset: p.offset,
44            distinct: p.distinct,
45            window_functions: p.window_functions,
46        })
47    }
48
49    fn plan_point_get(&self, p: PointGetParams) -> Result<SqlPlan> {
50        Ok(SqlPlan::PointGet {
51            collection: p.collection,
52            alias: p.alias,
53            engine: EngineType::Columnar,
54            key_column: p.key_column,
55            key_value: p.key_value,
56        })
57    }
58
59    fn plan_update(&self, p: UpdateParams) -> Result<Vec<SqlPlan>> {
60        Ok(vec![SqlPlan::Update {
61            collection: p.collection,
62            engine: EngineType::Columnar,
63            assignments: p.assignments,
64            filters: p.filters,
65            target_keys: p.target_keys,
66            returning: p.returning,
67        }])
68    }
69
70    fn plan_delete(&self, p: DeleteParams) -> Result<Vec<SqlPlan>> {
71        Ok(vec![SqlPlan::Delete {
72            collection: p.collection,
73            engine: EngineType::Columnar,
74            filters: p.filters,
75            target_keys: p.target_keys,
76        }])
77    }
78
79    fn plan_aggregate(&self, p: AggregateParams) -> Result<SqlPlan> {
80        let base_scan = SqlPlan::Scan {
81            collection: p.collection,
82            alias: p.alias,
83            engine: EngineType::Columnar,
84            filters: p.filters,
85            projection: Vec::new(),
86            sort_keys: Vec::new(),
87            limit: None,
88            offset: 0,
89            distinct: false,
90            window_functions: Vec::new(),
91        };
92        Ok(SqlPlan::Aggregate {
93            input: Box::new(base_scan),
94            group_by: p.group_by,
95            aggregates: p.aggregates,
96            having: p.having,
97            limit: p.limit,
98        })
99    }
100}