Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that COUNT(DISTINCT) on StringView panics #11768

Merged
merged 2 commits into from
Aug 1, 2024
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
5 changes: 4 additions & 1 deletion datafusion/functions-aggregate/src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,17 @@ impl AggregateUDFImpl for Count {
Box::new(BytesDistinctCountAccumulator::<i32>::new(OutputType::Utf8))
}
DataType::Utf8View => {
Box::new(BytesViewDistinctCountAccumulator::new(OutputType::Utf8))
Box::new(BytesViewDistinctCountAccumulator::new(OutputType::Utf8View))
}
DataType::LargeUtf8 => {
Box::new(BytesDistinctCountAccumulator::<i64>::new(OutputType::Utf8))
}
DataType::Binary => Box::new(BytesDistinctCountAccumulator::<i32>::new(
OutputType::Binary,
)),
DataType::BinaryView => Box::new(BytesViewDistinctCountAccumulator::new(
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

OutputType::BinaryView,
)),
DataType::LargeBinary => Box::new(BytesDistinctCountAccumulator::<i64>::new(
OutputType::Binary,
)),
Expand Down
34 changes: 34 additions & 0 deletions datafusion/sqllogictest/test_files/string_view.slt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,40 @@ logical_plan
02)--Filter: CAST(test.column2_utf8 AS Utf8View) = test.column1_utf8view
03)----TableScan: test projection=[column1_utf8, column2_utf8, column1_utf8view]

## Test distinct aggregates
query III
SELECT
COUNT(DISTINCT column1_utf8),
COUNT(DISTINCT column1_utf8view),
COUNT(DISTINCT column1_dict)
FROM test;
----
3 3 3

query III
SELECT
COUNT(DISTINCT column1_utf8),
COUNT(DISTINCT column1_utf8view),
COUNT(DISTINCT column1_dict)
FROM test
GROUP BY column2_utf8view;
----
1 1 1
1 1 1
1 1 1


query TT
EXPLAIN SELECT
COUNT(DISTINCT column1_utf8),
COUNT(DISTINCT column1_utf8view),
COUNT(DISTINCT column1_dict)
FROM test;
----
logical_plan
01)Aggregate: groupBy=[[]], aggr=[[count(DISTINCT test.column1_utf8), count(DISTINCT test.column1_utf8view), count(DISTINCT test.column1_dict)]]
02)--TableScan: test projection=[column1_utf8, column1_utf8view, column1_dict]


statement ok
drop table test;
Expand Down