Skip to content

Unparse TableScan with pushdown projection #12154

Description

@goldmedal

Is your feature request related to a problem or challenge?

Consider the following case:

    let ctx = SessionContext::new();
    ctx.sql("create table t1 (a int, b int)").await?;
    ctx.sql("insert into t1 values (1, 2), (3, 4)").await?;

    let plan = ctx.sql(r#"select s1.a from (select s1.a, s1.b from (select a, b from t1) s1) s1"#).await?.into_optimized_plan()?;
    println!("optimized plan: {plan}");
    let unparse = plan_to_sql(&plan)?.to_string();
    println!("{}", format!("Unparsed SQL: {}", unparse));

The output result is

Optimized plan: SubqueryAlias: s1
  SubqueryAlias: s1
    TableScan: t1 projection=[a]
Unparsed SQL: SELECT * FROM t1 AS s1

The unparsing isn't equal to the original SQL. I think it should be

select s1.a from t1 as s1

Describe the solution you'd like

Handle the pushdown projection at Unparser:select_to_sql_recursively

LogicalPlan::TableScan(scan) => {
let mut builder = TableRelationBuilder::default();
let mut table_parts = vec![];
if let Some(catalog_name) = scan.table_name.catalog() {

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions