Skip to content

Commit c45fc41

Browse files
authored
Fix: support Qualified Wildcard in count aggregate function (#12673)
1 parent b0ec2d6 commit c45fc41

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

datafusion/optimizer/src/analyzer/count_wildcard_rule.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ impl AnalyzerRule for CountWildcardRule {
4848
}
4949

5050
fn is_wildcard(expr: &Expr) -> bool {
51-
matches!(
52-
expr,
53-
Expr::Wildcard {
54-
qualifier: None,
55-
..
56-
}
57-
)
51+
matches!(expr, Expr::Wildcard { .. })
5852
}
5953

6054
fn is_count_star_aggregate(aggregate_function: &AggregateFunction) -> bool {

datafusion/sql/src/expr/function.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
432432
qualifier: None,
433433
options: WildcardOptions::default(),
434434
}),
435+
FunctionArg::Unnamed(FunctionArgExpr::QualifiedWildcard(object_name)) => {
436+
let qualifier = self.object_name_to_table_reference(object_name)?;
437+
// sanity check on qualifier with schema
438+
let qualified_indices = schema.fields_indices_with_qualified(&qualifier);
439+
if qualified_indices.is_empty() {
440+
return plan_err!("Invalid qualifier {qualifier}");
441+
}
442+
Ok(Expr::Wildcard {
443+
qualifier: Some(qualifier),
444+
options: WildcardOptions::default(),
445+
})
446+
}
435447
_ => not_impl_err!("Unsupported qualified wildcard argument: {sql:?}"),
436448
}
437449
}

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,14 @@ SELECT COUNT(*) FROM aggregate_test_100
11241124
----
11251125
100
11261126

1127+
query I
1128+
SELECT COUNT(aggregate_test_100.*) FROM aggregate_test_100
1129+
----
1130+
100
1131+
1132+
query error Error during planning: Invalid qualifier foo
1133+
SELECT COUNT(foo.*) FROM aggregate_test_100
1134+
11271135
# csv_query_count_literal
11281136
query I
11291137
SELECT COUNT(2) FROM aggregate_test_100

0 commit comments

Comments
 (0)