This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 96631417b2 Expand wildcard expressions in distinct on (#12941)
96631417b2 is described below
commit 96631417b24380f96244d4afca9c85be00ecb5dd
Author: epsio-banay <[email protected]>
AuthorDate: Wed Oct 16 17:25:14 2024 +0300
Expand wildcard expressions in distinct on (#12941)
---
.../optimizer/src/analyzer/expand_wildcard_rule.rs | 31 ++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs
b/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs
index a26ec4be5c..9fbe54e1cc 100644
--- a/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs
+++ b/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs
@@ -26,7 +26,9 @@ use datafusion_expr::expr::PlannedReplaceSelectItem;
use datafusion_expr::utils::{
expand_qualified_wildcard, expand_wildcard, find_base_plan,
};
-use datafusion_expr::{Expr, LogicalPlan, Projection, SubqueryAlias};
+use datafusion_expr::{
+ Distinct, DistinctOn, Expr, LogicalPlan, Projection, SubqueryAlias,
+};
#[derive(Default, Debug)]
pub struct ExpandWildcardRule {}
@@ -59,12 +61,25 @@ fn expand_internal(plan: LogicalPlan) ->
Result<Transformed<LogicalPlan>> {
.map(LogicalPlan::Projection)?,
))
}
- // Teh schema of the plan should also be updated if the child plan is
transformed.
+ // The schema of the plan should also be updated if the child plan is
transformed.
LogicalPlan::SubqueryAlias(SubqueryAlias { input, alias, .. }) => {
Ok(Transformed::yes(
SubqueryAlias::try_new(input,
alias).map(LogicalPlan::SubqueryAlias)?,
))
}
+ LogicalPlan::Distinct(Distinct::On(distinct_on)) => {
+ let projected_expr =
+ expand_exprlist(&distinct_on.input, distinct_on.select_expr)?;
+ validate_unique_names("Distinct", projected_expr.iter())?;
+ Ok(Transformed::yes(LogicalPlan::Distinct(Distinct::On(
+ DistinctOn::try_new(
+ distinct_on.on_expr,
+ projected_expr,
+ distinct_on.sort_expr,
+ distinct_on.input,
+ )?,
+ ))))
+ }
_ => Ok(Transformed::no(plan)),
}
}
@@ -240,6 +255,18 @@ mod tests {
assert_plan_eq(plan, expected)
}
+ #[test]
+ fn test_expand_wildcard_in_distinct_on() -> Result<()> {
+ let table_scan = test_table_scan()?;
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .distinct_on(vec![col("a")], vec![wildcard()], None)?
+ .build()?;
+ let expected = "\
+ DistinctOn: on_expr=[[test.a]], select_expr=[[test.a, test.b,
test.c]], sort_expr=[[]] [a:UInt32, b:UInt32, c:UInt32]\
+ \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";
+ assert_plan_eq(plan, expected)
+ }
+
#[test]
fn test_subquery_schema() -> Result<()> {
let analyzer =
Analyzer::with_rules(vec![Arc::new(ExpandWildcardRule::new())]);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]