1use crate::engine_rules::*;
6use crate::error::{Result, SqlError};
7use crate::types::*;
8
9pub struct SchemalessRules;
10
11impl EngineRules for SchemalessRules {
12 fn plan_insert(&self, p: InsertParams) -> Result<Vec<SqlPlan>> {
13 Ok(vec![SqlPlan::Insert(InsertPlan {
14 collection: p.collection,
15 engine: EngineType::DocumentSchemaless,
16 route: WriteRoute::Document,
17 rows: p.rows,
18 volatile_defaults: p.volatile_defaults,
19 if_absent: p.if_absent,
20 column_schema: vec![],
21 primary_key: p.primary_key,
22 })])
23 }
24
25 fn plan_insert_select(&self, p: InsertSelectParams) -> Result<Vec<SqlPlan>> {
26 Ok(vec![SqlPlan::InsertSelect {
27 target: p.collection,
28 source: p.source,
29 column_map: p.column_map,
30 source_columns: p.source_columns,
31 }])
32 }
33
34 fn plan_upsert(&self, p: UpsertParams) -> Result<Vec<SqlPlan>> {
35 Ok(vec![SqlPlan::Upsert(UpsertPlan {
36 collection: p.collection,
37 engine: EngineType::DocumentSchemaless,
38 route: WriteRoute::Document,
39 rows: p.rows,
40 volatile_defaults: p.volatile_defaults,
41 on_conflict_updates: p.on_conflict_updates,
42 column_schema: vec![],
43 primary_key: p.primary_key,
44 })])
45 }
46
47 fn plan_scan(&self, p: ScanParams) -> Result<SqlPlan> {
48 if p.temporal.is_temporal() && !p.bitemporal {
49 return Err(SqlError::Unsupported {
50 detail: format!(
51 "FOR SYSTEM_TIME / FOR VALID_TIME requires a bitemporal \
52 collection; '{}' was not created WITH bitemporal = true",
53 p.collection
54 ),
55 });
56 }
57 if let Some(plan) =
58 crate::engine_rules::try_document_index_lookup(&p, EngineType::DocumentSchemaless)
59 {
60 return Ok(plan);
61 }
62 Ok(SqlPlan::Scan {
63 collection: p.collection,
64 alias: p.alias,
65 engine: EngineType::DocumentSchemaless,
66 filters: p.filters,
67 projection: p.projection,
68 sort_keys: p.sort_keys,
69 limit: p.limit,
70 offset: p.offset,
71 distinct: p.distinct,
72 window_functions: p.window_functions,
73 temporal: p.temporal,
74 })
75 }
76
77 fn plan_point_get(&self, p: PointGetParams) -> Result<SqlPlan> {
78 Ok(SqlPlan::PointGet {
79 collection: p.collection,
80 alias: p.alias,
81 engine: EngineType::DocumentSchemaless,
82 key_column: p.key_column,
83 key_value: p.key_value,
84 projection: p.projection,
85 })
86 }
87
88 fn plan_update(&self, p: UpdateParams) -> Result<Vec<SqlPlan>> {
89 Ok(vec![SqlPlan::Update {
90 collection: p.collection,
91 engine: EngineType::DocumentSchemaless,
92 assignments: p.assignments,
93 filters: p.filters,
94 target_keys: p.target_keys,
95 returning: p.returning,
96 }])
97 }
98
99 fn plan_update_from(&self, p: UpdateFromParams) -> Result<Vec<SqlPlan>> {
100 Ok(vec![SqlPlan::UpdateFrom {
101 collection: p.collection,
102 engine: EngineType::DocumentSchemaless,
103 source: p.source,
104 source_alias: p.source_alias,
105 target_join_col: p.target_join_col,
106 source_join_col: p.source_join_col,
107 assignments: p.assignments,
108 target_filters: p.target_filters,
109 returning: p.returning,
110 }])
111 }
112
113 fn plan_delete(&self, p: DeleteParams) -> Result<Vec<SqlPlan>> {
114 Ok(vec![SqlPlan::Delete {
115 collection: p.collection,
116 engine: EngineType::DocumentSchemaless,
117 filters: p.filters,
118 target_keys: p.target_keys,
119 }])
120 }
121
122 fn plan_merge(&self, p: MergeParams) -> Result<Vec<SqlPlan>> {
123 Ok(vec![SqlPlan::Merge(MergePlan {
124 target: p.collection,
125 engine: EngineType::DocumentSchemaless,
126 source: p.source,
127 target_join_col: p.target_join_col,
128 source_join_col: p.source_join_col,
129 source_alias: p.source_alias,
130 clauses: p.clauses,
131 returning: p.returning,
132 })])
133 }
134
135 fn plan_truncate(&self, p: TruncateParams) -> Result<Vec<SqlPlan>> {
136 Ok(vec![SqlPlan::Truncate {
137 collection: p.collection,
138 engine: EngineType::DocumentSchemaless,
139 restart_identity: p.restart_identity,
140 }])
141 }
142
143 fn plan_aggregate(&self, p: AggregateParams) -> Result<SqlPlan> {
144 let base_scan = SqlPlan::Scan {
145 collection: p.collection,
146 alias: p.alias,
147 engine: EngineType::DocumentSchemaless,
148 filters: p.filters,
149 projection: Vec::new(),
150 sort_keys: Vec::new(),
151 limit: None,
152 offset: 0,
153 distinct: false,
154 window_functions: Vec::new(),
155 temporal: p.temporal,
156 };
157 Ok(SqlPlan::Aggregate {
158 input: Box::new(base_scan),
159 group_by: p.group_by,
160 group_by_aliases: Vec::new(),
161 output_order: Vec::new(),
162 aggregates: p.aggregates,
163 having: p.having,
164 limit: p.limit,
165 grouping_sets: p.grouping_sets,
166 sort_keys: Vec::new(),
167 })
168 }
169
170 fn accepts_undeclared_columns(&self) -> bool {
173 true
174 }
175}