MCPcopy Create free account
hub / github.com/apache/datafusion / select_to_sql_expr

Method select_to_sql_expr

datafusion/sql/src/unparser/plan.rs:194–227  ·  view source on GitHub ↗
(
        &self,
        plan: &LogicalPlan,
        query: &mut Option<QueryBuilder>,
    )

Source from the content-addressed store, hash-verified

192 }
193
194 fn select_to_sql_expr(
195 &self,
196 plan: &LogicalPlan,
197 query: &mut Option<QueryBuilder>,
198 ) -> Result<SetExpr> {
199 let mut select_builder = SelectBuilder::default();
200 select_builder.push_from(TableWithJoinsBuilder::default());
201 let mut relation_builder = RelationBuilder::default();
202 self.select_to_sql_recursively(
203 plan,
204 query,
205 &mut select_builder,
206 &mut relation_builder,
207 )?;
208
209 // If we were able to construct a full body (i.e. UNION ALL), return it
210 if let Some(body) = query.as_mut().and_then(|q| q.take_body()) {
211 return Ok(*body);
212 }
213
214 // If no projection is set, add a wildcard projection to the select
215 // which will be translated to `SELECT *` in the SQL statement
216 if !select_builder.already_projected() {
217 select_builder.projection(vec![ast::SelectItem::Wildcard(
218 ast::WildcardAdditionalOptions::default(),
219 )]);
220 }
221
222 let mut twj = select_builder.pop_from().unwrap();
223 twj.relation(relation_builder);
224 select_builder.push_from(twj);
225
226 Ok(SetExpr::Select(Box::new(select_builder.build()?)))
227 }
228
229 /// Reconstructs a SELECT SQL statement from a logical plan by unprojecting column expressions
230 /// found in a [Projection] node. This requires scanning the plan tree for relevant Aggregate

Callers 2

Calls 9

newFunction · 0.85
push_fromMethod · 0.80
take_bodyMethod · 0.80
already_projectedMethod · 0.80
pop_fromMethod · 0.80
relationMethod · 0.80
projectionMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected