MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / plan_merge_source

Function plan_merge_source

nodedb-sql/src/planner/merge.rs:77–133  ·  view source on GitHub ↗

Plan the USING clause. Supports: - Table name: `USING src_table ON ...` - Derived subquery: `USING (SELECT ...) AS alias ON ...` - VALUES constructor: treated as a subquery alias.

(factor: &ast::TableFactor, catalog: &dyn SqlCatalog)

Source from the content-addressed store, hash-verified

75/// - Derived subquery: `USING (SELECT ...) AS alias ON ...`
76/// - VALUES constructor: treated as a subquery alias.
77fn plan_merge_source(factor: &ast::TableFactor, catalog: &dyn SqlCatalog) -> Result<SqlPlan> {
78 match factor {
79 ast::TableFactor::Table { name, alias, .. } => {
80 let source_name = normalize_object_name_checked(name)?;
81 let source_info = catalog
82 .get_collection(DatabaseId::DEFAULT, &source_name)?
83 .ok_or_else(|| SqlError::UnknownTable {
84 name: source_name.clone(),
85 })?;
86 let alias_str = alias.as_ref().map(|a| normalize_ident(&a.name));
87 let source_rules = engine_rules::resolve_engine_rules(source_info.engine);
88 source_rules.plan_scan(ScanParams {
89 collection: source_name,
90 alias: alias_str,
91 filters: Vec::new(),
92 projection: Vec::new(),
93 sort_keys: Vec::new(),
94 limit: None,
95 offset: 0,
96 distinct: false,
97 window_functions: Vec::new(),
98 indexes: Vec::new(),
99 temporal: TemporalScope::default(),
100 bitemporal: source_info.bitemporal,
101 })
102 }
103 ast::TableFactor::Derived {
104 lateral: _,
105 subquery,
106 alias,
107 sample: _,
108 } => {
109 use crate::functions::registry::FunctionRegistry;
110 let alias_name = alias
111 .as_ref()
112 .map(|a| normalize_ident(&a.name))
113 .unwrap_or_else(|| "source".to_string());
114 let functions = FunctionRegistry::new();
115 let plan = crate::planner::select::plan_query(
116 subquery,
117 catalog,
118 &functions,
119 TemporalScope::default(),
120 )?;
121 // Wrap in an alias scan-like node; for Merge we pass the sub-plan
122 // directly. The alias is tracked separately via `source_alias`.
123 let _ = alias_name;
124 Ok(plan)
125 }
126 other => Err(SqlError::Unsupported {
127 detail: format!(
128 "MERGE USING source type not supported: {other}; \
129 use a table name or a subquery"
130 ),
131 }),
132 }
133}
134

Callers 1

plan_mergeFunction · 0.85

Calls 9

normalize_identFunction · 0.85
resolve_engine_rulesFunction · 0.85
plan_queryFunction · 0.85
to_stringMethod · 0.80
get_collectionMethod · 0.45
cloneMethod · 0.45
as_refMethod · 0.45
plan_scanMethod · 0.45

Tested by

no test coverage detected