Skip to content

Apache DataFusion SQL Query Engine

chore: add aggregation test for listview types (#21776)

Jeffrey Vo067ba4b02e18
diff --git a/datafusion/sqllogictest/test_files/list_view.slt b/datafusion/sqllogictest/test_files/list_view.slt
new file mode 100644
index 0000000000..0e0fe817f6
--- /dev/null
+++ b/datafusion/sqllogictest/test_files/list_view.slt
@@ -0,0 +1,66 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#############
+## ListView Aggregation Tests
+#############
+
+### Setup: Create test tables with ListView arrays
+
+statement ok
+CREATE TABLE list_view_agg_test AS
+SELECT
+ id,
+ group_col,
+ arrow_cast(make_array(val1, val2, val3), 'ListView(Int64)') as list_view_col,
+ arrow_cast(make_array(val1, val2, val3), 'LargeListView(Int64)') as large_list_view_col
+FROM (VALUES
+ (1, 'A', 10, 20, 30),
+ (2, 'A', 40, 50, 60),
+ (3, 'B', 70, 80, 90),
+ (4, 'B', 100, 110, 120),
+ (5, 'C', 1, 2, 3)
+) AS t(id, group_col, val1, val2, val3);
+
+### Test: GROUP BY on ListView column
+
+query ?I rowsort
+SELECT list_view_col, COUNT(*)
+FROM list_view_agg_test
+GROUP BY list_view_col;
+----
+[1, 2, 3] 1
+[10, 20, 30] 1
+[100, 110, 120] 1
+[40, 50, 60] 1
+[70, 80, 90] 1
+
+query ?I rowsort
+SELECT large_list_view_col, COUNT(*)
+FROM list_view_agg_test
+GROUP BY large_list_view_col;
+----
+[1, 2, 3] 1
+[10, 20, 30] 1
+[100, 110, 120] 1
+[40, 50, 60] 1
+[70, 80, 90] 1
+
+### Cleanup
+
+statement ok
+DROP TABLE list_view_agg_test;