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

Method select_to_sql_recursively

datafusion/sql/src/unparser/plan.rs:556–1361  ·  view source on GitHub ↗
(
        &self,
        plan: &LogicalPlan,
        query: &mut Option<QueryBuilder>,
        select: &mut SelectBuilder,
        relation: &mut RelationBuilder,
    )

Source from the content-addressed store, hash-verified

554
555 #[cfg_attr(feature = "recursive_protection", recursive::recursive)]
556 fn select_to_sql_recursively(
557 &self,
558 plan: &LogicalPlan,
559 query: &mut Option<QueryBuilder>,
560 select: &mut SelectBuilder,
561 relation: &mut RelationBuilder,
562 ) -> Result<()> {
563 match plan {
564 LogicalPlan::TableScan(scan) => {
565 if let Some(unparsed_table_scan) = self.unparse_table_scan_pushdown(
566 plan,
567 None,
568 select.already_projected(),
569 )? {
570 return self.select_to_sql_recursively(
571 &unparsed_table_scan,
572 query,
573 select,
574 relation,
575 );
576 }
577 let mut builder = TableRelationBuilder::default();
578 let mut table_parts = vec![];
579 if let Some(catalog_name) = scan.table_name.catalog() {
580 table_parts
581 .push(self.new_ident_quoted_if_needs(catalog_name.to_string()));
582 }
583 if let Some(schema_name) = scan.table_name.schema() {
584 table_parts
585 .push(self.new_ident_quoted_if_needs(schema_name.to_string()));
586 }
587 table_parts.push(
588 self.new_ident_quoted_if_needs(scan.table_name.table().to_string()),
589 );
590 builder.name(ast::ObjectName::from(table_parts));
591 relation.table(builder);
592
593 Ok(())
594 }
595 LogicalPlan::Projection(p) => {
596 if let Some(new_plan) = rewrite_plan_for_sort_on_non_projected_fields(p) {
597 return self
598 .select_to_sql_recursively(&new_plan, query, select, relation);
599 }
600
601 // Projection can be top-level plan for unnest relation.
602 // The projection generated by the `RecursiveUnnestRewriter`
603 // will have at least one expression referencing an unnest
604 // placeholder column.
605 let unnest_input_type: Option<UnnestInputType> =
606 p.expr.iter().find_map(Self::find_unnest_placeholder);
607
608 // --- UNNEST table factor path (BigQuery, etc.) ---
609 // Only fires for a single bare-placeholder projection.
610 // Uses peel_to_unnest_with_modifiers (rather than matching
611 // p.input directly) to handle Limit/Sort between Projection
612 // and Unnest.
613 if self.dialect.unnest_as_table_factor()

Tested by

no test coverage detected