From 42f906072a3000d005b8ced97654aaec2828a878 Mon Sep 17 00:00:00 2001 From: Tornike Gurgenidze Date: Fri, 18 Oct 2024 23:06:58 +0400 Subject: [PATCH] feat(substrait): add wildcard handling to producer (#12987) * feat(substrait): add wildcard expand rule in producer * add comment describing need for ExpandWildcardRule --- .../substrait/src/logical_plan/producer.rs | 10 +++++- .../tests/cases/roundtrip_logical_plan.rs | 34 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/datafusion/substrait/src/logical_plan/producer.rs b/datafusion/substrait/src/logical_plan/producer.rs index 0e1375a8e0ea..7504a287c055 100644 --- a/datafusion/substrait/src/logical_plan/producer.rs +++ b/datafusion/substrait/src/logical_plan/producer.rs @@ -15,6 +15,9 @@ // specific language governing permissions and limitations // under the License. +use datafusion::config::ConfigOptions; +use datafusion::optimizer::analyzer::expand_wildcard_rule::ExpandWildcardRule; +use datafusion::optimizer::AnalyzerRule; use std::sync::Arc; use substrait::proto::expression_reference::ExprType; @@ -103,9 +106,14 @@ pub fn to_substrait_plan(plan: &LogicalPlan, ctx: &SessionContext) -> Result Result<()> { #[tokio::test] async fn wildcard_select() -> Result<()> { - roundtrip("SELECT * FROM data").await + assert_expected_plan_unoptimized( + "SELECT * FROM data", + "Projection: data.a, data.b, data.c, data.d, data.e, data.f\ + \n TableScan: data", + true, + ) + .await } #[tokio::test] @@ -1174,6 +1180,32 @@ async fn verify_post_join_filter_value(proto: Box) -> Result<()> { Ok(()) } +async fn assert_expected_plan_unoptimized( + sql: &str, + expected_plan_str: &str, + assert_schema: bool, +) -> Result<()> { + let ctx = create_context().await?; + let df = ctx.sql(sql).await?; + let plan = df.into_unoptimized_plan(); + let proto = to_substrait_plan(&plan, &ctx)?; + let plan2 = from_substrait_plan(&ctx, &proto).await?; + + println!("{plan}"); + println!("{plan2}"); + + println!("{proto:?}"); + + if assert_schema { + assert_eq!(plan.schema(), plan2.schema()); + } + + let plan2str = format!("{plan2}"); + assert_eq!(expected_plan_str, &plan2str); + + Ok(()) +} + async fn assert_expected_plan( sql: &str, expected_plan_str: &str,