Skip to content

Commit f044bc8

Browse files
XiangpengHaoalamb
andauthored
Fix bug that COUNT(DISTINCT) on StringView panics (#11768)
* fix bug * Add test showing panic on string view --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 0d98b99 commit f044bc8

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

datafusion/functions-aggregate/src/count.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,17 @@ impl AggregateUDFImpl for Count {
237237
Box::new(BytesDistinctCountAccumulator::<i32>::new(OutputType::Utf8))
238238
}
239239
DataType::Utf8View => {
240-
Box::new(BytesViewDistinctCountAccumulator::new(OutputType::Utf8))
240+
Box::new(BytesViewDistinctCountAccumulator::new(OutputType::Utf8View))
241241
}
242242
DataType::LargeUtf8 => {
243243
Box::new(BytesDistinctCountAccumulator::<i64>::new(OutputType::Utf8))
244244
}
245245
DataType::Binary => Box::new(BytesDistinctCountAccumulator::<i32>::new(
246246
OutputType::Binary,
247247
)),
248+
DataType::BinaryView => Box::new(BytesViewDistinctCountAccumulator::new(
249+
OutputType::BinaryView,
250+
)),
248251
DataType::LargeBinary => Box::new(BytesDistinctCountAccumulator::<i64>::new(
249252
OutputType::Binary,
250253
)),

datafusion/sqllogictest/test_files/string_view.slt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,40 @@ logical_plan
321321
02)--Filter: CAST(test.column2_utf8 AS Utf8View) = test.column1_utf8view
322322
03)----TableScan: test projection=[column1_utf8, column2_utf8, column1_utf8view]
323323

324+
## Test distinct aggregates
325+
query III
326+
SELECT
327+
COUNT(DISTINCT column1_utf8),
328+
COUNT(DISTINCT column1_utf8view),
329+
COUNT(DISTINCT column1_dict)
330+
FROM test;
331+
----
332+
3 3 3
333+
334+
query III
335+
SELECT
336+
COUNT(DISTINCT column1_utf8),
337+
COUNT(DISTINCT column1_utf8view),
338+
COUNT(DISTINCT column1_dict)
339+
FROM test
340+
GROUP BY column2_utf8view;
341+
----
342+
1 1 1
343+
1 1 1
344+
1 1 1
345+
346+
347+
query TT
348+
EXPLAIN SELECT
349+
COUNT(DISTINCT column1_utf8),
350+
COUNT(DISTINCT column1_utf8view),
351+
COUNT(DISTINCT column1_dict)
352+
FROM test;
353+
----
354+
logical_plan
355+
01)Aggregate: groupBy=[[]], aggr=[[count(DISTINCT test.column1_utf8), count(DISTINCT test.column1_utf8view), count(DISTINCT test.column1_dict)]]
356+
02)--TableScan: test projection=[column1_utf8, column1_utf8view, column1_dict]
357+
324358

325359
statement ok
326360
drop table test;

0 commit comments

Comments
 (0)