You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parsing SQL strings to Exprs wtih the qualified schema #11551
Is your feature request related to a problem or challenge?
After #10995, we have parse_sql_expr() to create a logical expression from the SQL string. This API allows creating the expression with a Schema. I tried to create the expression with a qualified schema:
let sql = "a < 5 OR a = 8";let expr = col("t.a").lt(lit(5_i64)).or(col("t.a").eq(lit(8_i64)));// provide type information that `a` is an Int32let schema = Schema::new(vec![Field::new("a",DataType::Int32,true)]);let df_schema = DFSchema::try_from_qualified_schema("t",&schema).unwrap();let ctx = SessionContext::new();let parsed_expr = ctx.parse_sql_expr(sql,&df_schema)?;assert_eq!(parsed_expr, expr);
I expected the identifier to be col("t.a"), but it is actually col("a").
I think the behavior can be aligned with the planning for the SQL statement:
ctx.register_batch("t",a_batch());let df = ctx.sql("SELECT a < 5 OR a = 8 FROM t").await?.into_optimized_plan()?;dbg!(&df);
The result would be:
[datafusion-examples/examples/parse_sql_expr.rs:89:5] &df = Projection: t.a < Int32(5) OR t.a = Int32(8) AS t.a < Int64(5) OR t.a = Int64(8)
TableScan: t projection=[a]
All of the identifiers are qualified.
Describe the solution you'd like
I think we can find the field by qualified_field_with_unqualified_name, and pass the qualifier when planning a column at
Activity
Lordworms commentedon Jul 20, 2024
take