This is an automated email from the ASF dual-hosted git repository.

dheres pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new f044bc8371 Fix bug that `COUNT(DISTINCT)` on StringView panics  
(#11768)
f044bc8371 is described below

commit f044bc8371d5b4e1e51a9026f3eccac16a6d4648
Author: Xiangpeng Hao <[email protected]>
AuthorDate: Fri Aug 2 04:33:05 2024 +0800

    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]>
---
 datafusion/functions-aggregate/src/count.rs        |  5 +++-
 datafusion/sqllogictest/test_files/string_view.slt | 34 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/datafusion/functions-aggregate/src/count.rs 
b/datafusion/functions-aggregate/src/count.rs
index e2d59003fc..64eb7253f5 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::<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))
@@ -245,6 +245,9 @@ impl AggregateUDFImpl for Count {
             DataType::Binary => 
Box::new(BytesDistinctCountAccumulator::<i32>::new(
                 OutputType::Binary,
             )),
+            DataType::BinaryView => 
Box::new(BytesViewDistinctCountAccumulator::new(
+                OutputType::BinaryView,
+            )),
             DataType::LargeBinary => 
Box::new(BytesDistinctCountAccumulator::<i64>::new(
                 OutputType::Binary,
             )),
diff --git a/datafusion/sqllogictest/test_files/string_view.slt 
b/datafusion/sqllogictest/test_files/string_view.slt
index 3f9a4793f6..763b4e99c6 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;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to