From 263781ac7efa913caab50ad6cf826b9f0dd29352 Mon Sep 17 00:00:00 2001 From: Xiangpeng Hao Date: Thu, 1 Aug 2024 13:05:27 -0400 Subject: [PATCH 1/2] fix bug --- datafusion/functions-aggregate/src/count.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/datafusion/functions-aggregate/src/count.rs b/datafusion/functions-aggregate/src/count.rs index e2d59003fca1..64eb7253f5c9 100644 --- a/datafusion/functions-aggregate/src/count.rs +++ b/datafusion/functions-aggregate/src/count.rs @@ -237,7 +237,7 @@ impl AggregateUDFImpl for Count { Box::new(BytesDistinctCountAccumulator::::new(OutputType::Utf8)) } DataType::Utf8View => { - Box::new(BytesViewDistinctCountAccumulator::new(OutputType::Utf8)) + Box::new(BytesViewDistinctCountAccumulator::new(OutputType::Utf8View)) } DataType::LargeUtf8 => { Box::new(BytesDistinctCountAccumulator::::new(OutputType::Utf8)) @@ -245,6 +245,9 @@ impl AggregateUDFImpl for Count { DataType::Binary => Box::new(BytesDistinctCountAccumulator::::new( OutputType::Binary, )), + DataType::BinaryView => Box::new(BytesViewDistinctCountAccumulator::new( + OutputType::BinaryView, + )), DataType::LargeBinary => Box::new(BytesDistinctCountAccumulator::::new( OutputType::Binary, )), From 1922c729b9e14c7df6dae8ce8b470fa7a9035413 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 1 Aug 2024 09:49:40 -0400 Subject: [PATCH 2/2] Add test showing panic on string view --- .../sqllogictest/test_files/string_view.slt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/datafusion/sqllogictest/test_files/string_view.slt b/datafusion/sqllogictest/test_files/string_view.slt index 3f9a4793f655..763b4e99c614 100644 --- a/datafusion/sqllogictest/test_files/string_view.slt +++ b/datafusion/sqllogictest/test_files/string_view.slt @@ -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;