Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also add a negative test (aka a test that shows an unknown table)?

Perhaps something like

query error
SELECT COUNT(foo.*) FROM aggregate_test_100

Copy link
Contributor Author

@HuSen8891 HuSen8891 Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this test case later, thanks!

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