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, SqlError};
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        }])
17    }
18
19    fn plan_upsert(&self, _p: UpsertParams) -> Result<Vec<SqlPlan>> {
20        Err(SqlError::Unsupported {
21            detail: "UPSERT is not supported on columnar collections".into(),
22        })
23    }
24
25    fn plan_scan(&self, p: ScanParams) -> Result<SqlPlan> {
26        Ok(SqlPlan::Scan {
27            collection: p.collection,
28            alias: p.alias,
29            engine: EngineType::Columnar,
30            filters: p.filters,
31            projection: p.projection,
32            sort_keys: p.sort_keys,
33            limit: p.limit,
34            offset: p.offset,
35            distinct: p.distinct,
36            window_functions: p.window_functions,
37        })
38    }
39
40    fn plan_point_get(&self, p: PointGetParams) -> Result<SqlPlan> {
41        Ok(SqlPlan::PointGet {
42            collection: p.collection,
43            alias: p.alias,
44            engine: EngineType::Columnar,
45            key_column: p.key_column,
46            key_value: p.key_value,
47        })
48    }
49
50    fn plan_update(&self, p: UpdateParams) -> Result<Vec<SqlPlan>> {
51        Ok(vec![SqlPlan::Update {
52            collection: p.collection,
53            engine: EngineType::Columnar,
54            assignments: p.assignments,
55            filters: p.filters,
56            target_keys: p.target_keys,
57            returning: p.returning,
58        }])
59    }
60
61    fn plan_delete(&self, p: DeleteParams) -> Result<Vec<SqlPlan>> {
62        Ok(vec![SqlPlan::Delete {
63            collection: p.collection,
64            engine: EngineType::Columnar,
65            filters: p.filters,
66            target_keys: p.target_keys,
67        }])
68    }
69
70    fn plan_aggregate(&self, p: AggregateParams) -> Result<SqlPlan> {
71        let base_scan = SqlPlan::Scan {
72            collection: p.collection,
73            alias: p.alias,
74            engine: EngineType::Columnar,
75            filters: p.filters,
76            projection: Vec::new(),
77            sort_keys: Vec::new(),
78            limit: None,
79            offset: 0,
80            distinct: false,
81            window_functions: Vec::new(),
82        };
83        Ok(SqlPlan::Aggregate {
84            input: Box::new(base_scan),
85            group_by: p.group_by,
86            aggregates: p.aggregates,
87            having: p.having,
88            limit: p.limit,
89        })
90    }
91}