Skip to content

Commit

Permalink
Fix: support Qualified Wildcard in count aggregate function (apache#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
HuSen8891 authored Oct 2, 2024
1 parent b0ec2d6 commit c45fc41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 1 addition & 7 deletions datafusion/optimizer/src/analyzer/count_wildcard_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ impl AnalyzerRule for CountWildcardRule {
}

fn is_wildcard(expr: &Expr) -> bool {
matches!(
expr,
Expr::Wildcard {
qualifier: None,
..
}
)
matches!(expr, Expr::Wildcard { .. })
}

fn is_count_star_aggregate(aggregate_function: &AggregateFunction) -> bool {
Expand Down
12 changes: 12 additions & 0 deletions datafusion/sql/src/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
qualifier: None,
options: WildcardOptions::default(),
}),
FunctionArg::Unnamed(FunctionArgExpr::QualifiedWildcard(object_name)) => {
let qualifier = self.object_name_to_table_reference(object_name)?;
// sanity check on qualifier with schema
let qualified_indices = schema.fields_indices_with_qualified(&qualifier);
if qualified_indices.is_empty() {
return plan_err!("Invalid qualifier {qualifier}");
}
Ok(Expr::Wildcard {
qualifier: Some(qualifier),
options: WildcardOptions::default(),
})
}
_ => not_impl_err!("Unsupported qualified wildcard argument: {sql:?}"),
}
}
Expand Down
8 changes: 8 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,14 @@ SELECT COUNT(*) FROM aggregate_test_100
----
100

query I
SELECT COUNT(aggregate_test_100.*) FROM aggregate_test_100
----
100

query error Error during planning: Invalid qualifier foo
SELECT COUNT(foo.*) FROM aggregate_test_100

# csv_query_count_literal
query I
SELECT COUNT(2) FROM aggregate_test_100
Expand Down

0 comments on commit c45fc41

Please sign in to comment.