Apache DataFusion SQL Query Engine
adding support for Min/Max over LargeList and FixedSizeList (#16071)
logan-keede5293b70a466b
diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rsindex 8389109f94..a2a131309f 100644--- a/datafusion/common/src/scalar/mod.rs+++ b/datafusion/common/src/scalar/mod.rs@@ -4941,6 +4941,40 @@ mod tests {])]),));assert_eq!(a.partial_cmp(&b), Some(Ordering::Greater));++ let a = ScalarValue::LargeList(Arc::new(LargeListArray::from_iter_primitive::<+ Int64Type,+ _,+ _,+ >(vec![Some(vec![+ None,+ Some(2),+ Some(3),+ ])])));+ let b = ScalarValue::LargeList(Arc::new(LargeListArray::from_iter_primitive::<+ Int64Type,+ _,+ _,+ >(vec![Some(vec![+ Some(1),+ Some(2),+ Some(3),+ ])])));+ assert_eq!(a.partial_cmp(&b), Some(Ordering::Greater));++ let a = ScalarValue::FixedSizeList(Arc::new(+ FixedSizeListArray::from_iter_primitive::<Int64Type, _, _>(+ vec![Some(vec![None, Some(2), Some(3)])],+ 3,+ ),+ ));+ let b = ScalarValue::FixedSizeList(Arc::new(+ FixedSizeListArray::from_iter_primitive::<Int64Type, _, _>(+ vec![Some(vec![Some(1), Some(2), Some(3)])],+ 3,+ ),+ ));+ assert_eq!(a.partial_cmp(&b), Some(Ordering::Greater));}#[test]diff --git a/datafusion/functions-aggregate/src/min_max.rs b/datafusion/functions-aggregate/src/min_max.rsindex 9a026e171d..bb46aa5404 100644--- a/datafusion/functions-aggregate/src/min_max.rs+++ b/datafusion/functions-aggregate/src/min_max.rs@@ -622,6 +622,10 @@ fn min_batch(values: &ArrayRef) -> Result<ScalarValue> {}DataType::Struct(_) => min_max_batch_generic(values, Ordering::Greater)?,DataType::List(_) => min_max_batch_generic(values, Ordering::Greater)?,+ DataType::LargeList(_) => min_max_batch_generic(values, Ordering::Greater)?,+ DataType::FixedSizeList(_, _) => {+ min_max_batch_generic(values, Ordering::Greater)?+ }DataType::Dictionary(_, _) => {let values = values.as_any_dictionary().values();min_batch(values)?@@ -720,6 +724,8 @@ pub fn max_batch(values: &ArrayRef) -> Result<ScalarValue> {}DataType::Struct(_) => min_max_batch_generic(values, Ordering::Less)?,DataType::List(_) => min_max_batch_generic(values, Ordering::Less)?,+ DataType::LargeList(_) => min_max_batch_generic(values, Ordering::Less)?,+ DataType::FixedSizeList(_, _) => min_max_batch_generic(values, Ordering::Less)?,DataType::Dictionary(_, _) => {let values = values.as_any_dictionary().values();max_batch(values)?@@ -1008,6 +1014,23 @@ macro_rules! min_max {) => {min_max_generic!(lhs, rhs, $OP)}+++ (+ lhs @ ScalarValue::LargeList(_),+ rhs @ ScalarValue::LargeList(_),+ ) => {+ min_max_generic!(lhs, rhs, $OP)+ }+++ (+ lhs @ ScalarValue::FixedSizeList(_),+ rhs @ ScalarValue::FixedSizeList(_),+ ) => {+ min_max_generic!(lhs, rhs, $OP)+ }+e => {return internal_err!("MIN/MAX is not expected to receive scalars of incompatible types {:?}",diff --git a/datafusion/optimizer/src/analyzer/type_coercion.rs b/datafusion/optimizer/src/analyzer/type_coercion.rsindex e5779646b9..c17e6c766c 100644--- a/datafusion/optimizer/src/analyzer/type_coercion.rs+++ b/datafusion/optimizer/src/analyzer/type_coercion.rs@@ -719,6 +719,8 @@ fn extract_window_frame_target_type(col_type: &DataType) -> Result<DataType> {if col_type.is_numeric()|| is_utf8_or_utf8view_or_large_utf8(col_type)|| matches!(col_type, DataType::List(_))+ || matches!(col_type, DataType::LargeList(_))+ || matches!(col_type, DataType::FixedSizeList(_, _))|| matches!(col_type, DataType::Null)|| matches!(col_type, DataType::Boolean){diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.sltindex 41ce15d794..002014827e 100644--- a/datafusion/sqllogictest/test_files/aggregate.slt+++ b/datafusion/sqllogictest/test_files/aggregate.slt@@ -7018,151 +7018,3 @@ VALUES);----{a: 1, b: 2, c: 3} {a: 1, b: 2, c: 4}--# Min/Max with list over integers-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-([1, 2, 3]),-([1, 2]);------[1, 2] [1, 2, 3]--# Min/Max with lists over strings-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-(['a', 'b', 'c']),-(['a', 'b']);------[a, b] [a, b, c]--# Min/Max with list over booleans-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-([true, true, false]),-([false, true]);------[false, true] [true, true, false]--# Min/Max with list over nullable integers-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-([NULL, 1, 2]),-([1, 2]);------[1, 2] [NULL, 1, 2]--# Min/Max list with different lengths and nulls-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-([1, NULL, 3]),-([1, 2, 3, 4]),-([1, 2]);------[1, 2] [1, NULL, 3]--# Min/Max list with only NULLs-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-([NULL, NULL]),-([NULL]);------[NULL] [NULL, NULL]--# Min/Max list with empty lists-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-([]),-([1]),-([]);------[] [1]--# Min/Max list of varying types (integers and NULLs)-query ??-SELECT MIN(column1), MAX(column1) FROM VALUES-([1, 2, 3]),-([NULL, 2, 3]),-([1, 2, NULL]);------[1, 2, 3] [NULL, 2, 3]--# Min/Max list grouped by key with NULLs and differing lengths-query I?? rowsort-SELECT column1, MIN(column2), MAX(column2) FROM VALUES-(0, [1, NULL, 3]),-(0, [1, 2, 3, 4]),-(1, [1, 2]),-(1, [NULL, 5]),-(1, [])-GROUP BY column1;------0 [1, 2, 3, 4] [1, NULL, 3]-1 [] [NULL, 5]--# Min/Max list grouped by key with NULLs and differing lengths-query I?? rowsort-SELECT column1, MIN(column2), MAX(column2) FROM VALUES-(0, [NULL]),-(0, [NULL, NULL]),-(1, [NULL])-GROUP BY column1;------0 [NULL] [NULL, NULL]-1 [NULL] [NULL]--# Min/Max grouped list with empty and non-empty-query I?? rowsort-SELECT column1, MIN(column2), MAX(column2) FROM VALUES-(0, []),-(0, [1]),-(0, []),-(1, [5, 6]),-(1, [])-GROUP BY column1;------0 [] [1]-1 [] [5, 6]--# Min/Max over lists with a window function-query ?-SELECT min(column1) OVER (ORDER BY column1) FROM VALUES-([1, 2, 3]),-([1, 2, 3]),-([2, 3])------[1, 2, 3]-[1, 2, 3]-[1, 2, 3]--# Min/Max over lists with a window function and nulls-query ?-SELECT min(column1) OVER (ORDER BY column1) FROM VALUES-(NULL),-([4, 5]),-([2, 3])------[2, 3]-[2, 3]-[2, 3]--# Min/Max over lists with a window function, nulls and ROWS BETWEEN statement-query ?-SELECT min(column1) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES-(NULL),-([4, 5]),-([2, 3])------[2, 3]-[2, 3]-[4, 5]--# Min/Max over lists with a window function using a different column-query ?-SELECT max(column2) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES-([1, 2, 3], [4, 5]),-([2, 3], [2, 3]),-([1, 2, 3], NULL)------[4, 5]-[4, 5]-[2, 3]diff --git a/datafusion/sqllogictest/test_files/min_max/fixed_size_list.slt b/datafusion/sqllogictest/test_files/min_max/fixed_size_list.sltnew file mode 100644index 0000000000..164daec228--- /dev/null+++ b/datafusion/sqllogictest/test_files/min_max/fixed_size_list.slt@@ -0,0 +1,134 @@+# Min/Max with FixedSizeList over integers+query ??+SELECT MIN(column1), MAX(column1) FROM VALUES+(arrow_cast(make_array(1, 2, 3, 4), 'FixedSizeList(4, Int64)')),+(arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)'));+----+[1, 2] [1, 2, 3, 4]++# Min/Max with FixedSizeList over strings+query ??+SELECT MIN(column1), MAX(column1) FROM VALUES+(arrow_cast(make_array('a', 'b', 'c'), 'FixedSizeList(3, Utf8)')),+(arrow_cast(make_array('a', 'b'), 'LargeList(Utf8)'));+----+[a, b] [a, b, c]++# Min/Max with FixedSizeList over booleans+query ??+SELECT MIN(column1), MAX(column1) FROM VALUES+(arrow_cast(make_array(true, false, true), 'FixedSizeList(3, Boolean)')),+(arrow_cast(make_array(true, false), 'FixedSizeList(2, Boolean)'));+----+[true, false] [true, false, true]++# Min/Max with FixedSizeList over nullable integers+query ??+SELECT MIN(column1), MAX(column1) FROM VALUES+(arrow_cast(make_array(NULL, 1, 2), 'FixedSizeList(3, Int64)')),+(arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)'));+----+[1, 2] [NULL, 1, 2]++# Min/Max FixedSizeList with different lengths and nulls+query ??+SELECT MIN(column1), MAX(column1) FROM VALUES+(arrow_cast(make_array(1, 2, 3, 4), 'FixedSizeList(4, Int64)')),+(arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)')),+(arrow_cast(make_array(1, NULL, 3), 'FixedSizeList(3, Int64)'));+----+[1, 2] [1, NULL, 3]++# Min/Max FixedSizeList with only NULLs+query ??+SELECT MIN(column1), MAX(column1) FROM VALUES+(arrow_cast(make_array(NULL, NULL), 'FixedSizeList(2, Int64)')),+(arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)'));+----+[NULL] [NULL, NULL]+++# Min/Max FixedSizeList of varying types (integers and NULLs)+query ??+SELECT MIN(column1), MAX(column1) FROM VALUES+(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')),+(arrow_cast(make_array(NULL, 2, 3), 'FixedSizeList(3, Int64)')),+(arrow_cast(make_array(1, 2, NULL), 'FixedSizeList(3, Int64)'));+----+[1, 2, 3] [NULL, 2, 3]++# Min/Max FixedSizeList grouped by key with NULLs and differing lengths+query I?? rowsort+SELECT column1, MIN(column2), MAX(column2) FROM VALUES+(0, arrow_cast(make_array(1, NULL, 3), 'FixedSizeList(3, Int64)')),+(0, arrow_cast(make_array(1, 2, 3, 4), 'FixedSizeList(4, Int64)')),+(1, arrow_cast(make_array(1, 2), 'FixedSizeList(2, Int64)')),+(1, arrow_cast(make_array(NULL, 5), 'FixedSizeList(2, Int64)'))+GROUP BY column1;+----+0 [1, 2, 3, 4] [1, NULL, 3]+1 [1, 2] [NULL, 5]++# Min/Max FixedSizeList grouped by key with NULLs and differing lengths+query I?? rowsort+SELECT column1, MIN(column2), MAX(column2) FROM VALUES+(0, arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')),+(0, arrow_cast(make_array(NULL, NULL), 'FixedSizeList(2, Int64)')),+(1, arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)'))+GROUP BY column1;+----+0 [NULL] [NULL, NULL]+1 [NULL] [NULL]++# Min/Max grouped FixedSizeList with empty and non-empty+query I?? rowsort+SELECT column1, MIN(column2), MAX(column2) FROM VALUES+(0, arrow_cast(make_array(1), 'FixedSizeList(1, Int64)')),+(1, arrow_cast(make_array(5, 6), 'FixedSizeList(2, Int64)'))+GROUP BY column1;+----+0 [1] [1]+1 [5, 6] [5, 6]++# Min/Max over FixedSizeList with a window function+query ?+SELECT min(column1) OVER (ORDER BY column1) FROM VALUES+(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')),+(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')),+(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)'))+----+[1, 2, 3]+[1, 2, 3]+[1, 2, 3]++# Min/Max over FixedSizeList with a window function and nulls+query ?+SELECT min(column1) OVER (ORDER BY column1) FROM VALUES+(arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')),+(arrow_cast(make_array(4, 5), 'FixedSizeList(2, Int64)')),+(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)'))+----+[2, 3]+[2, 3]+[2, 3]++# Min/Max over FixedSizeList with a window function, nulls and ROWS BETWEEN statement+query ?+SELECT min(column1) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES+(arrow_cast(make_array(NULL), 'FixedSizeList(1, Int64)')),+(arrow_cast(make_array(4, 5), 'FixedSizeList(2, Int64)')),+(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)'))+----+[2, 3]+[2, 3]+[4, 5]++# Min/Max over FixedSizeList with a window function using a different column+query ?+SELECT max(column2) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM VALUES+(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)'), arrow_cast(make_array(4, 5), 'FixedSizeList(2, Int64)')),+(arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)'), arrow_cast(make_array(2, 3), 'FixedSizeList(2, Int64)'))+----+[4, 5]+[4, 5]+diff --git a/datafusion/sqllogictest/test_files/min_max/init_data.slt.part b/datafusion/sqllogictest/test_files/min_max/init_data.slt.partnew file mode 100644index 0000000000..57e14f6993--- /dev/null+++ b/datafusion/sqllogictest/test_files/min_max/init_data.slt.part@@ -0,0 +1,155 @@+# 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.++# --------------------------------------+# 1. Min/Max over integers+# --------------------------------------+statement ok+create table min_max_base_int as values+ (make_array(1, 2, 3, 4)),+ (make_array(1, 2))+;++# --------------------------------------+# 2. Min/Max over strings+# --------------------------------------+statement ok+create table min_max_base_string as values+ (make_array('a', 'b', 'c')),+ (make_array('a', 'b'))+;++# --------------------------------------+# 3. Min/Max over booleans+# --------------------------------------+statement ok+create table min_max_base_bool as values+ (make_array(true, false, true)),+ (make_array(true, false))+;++# --------------------------------------+# 4. Min/Max over nullable integers+# --------------------------------------+statement ok+create table min_max_base_nullable_int as values+ (make_array(NULL, 1, 2)),+ (make_array(1, 2))+;++# --------------------------------------+# 5. Min/Max with mixed lengths and nulls+# --------------------------------------+statement ok+create table min_max_base_mixed_lengths_nulls as values+ (make_array(1, 2, 3, 4)),+ (make_array(1, 2)),+ (make_array(1, NULL, 3))+;++# --------------------------------------+# 6. Min/Max with only NULLs+# --------------------------------------+statement ok+create table min_max_base_all_nulls as values+ (make_array(NULL, NULL)),+ (make_array(NULL))+;++# --------------------------------------+# 7. Min/Max with partial NULLs+# --------------------------------------+statement ok+create table min_max_base_null_variants as values+ (make_array(1, 2, 3)),+ (make_array(NULL, 2, 3)),+ (make_array(1, 2, NULL))+;++# --------------------------------------+# 8. Min/Max grouped by key with NULLs and differing lengths+# --------------------------------------+statement ok+create table min_max_base_grouped_nulls as values+ (0, make_array(1, NULL, 3)),+ (0, make_array(1, 2, 3, 4)),+ (1, make_array(1, 2)),+ (1, make_array(NULL, 5)),+ (1, make_array())+;++# --------------------------------------+# 9. Min/Max grouped by key with only NULLs+# --------------------------------------+statement ok+create table min_max_base_grouped_all_null as values+ (0, make_array(NULL)),+ (0, make_array(NULL, NULL)),+ (1, make_array(NULL))+;++# --------------------------------------+# 10. Min/Max grouped with empty and non-empty lists+# --------------------------------------+statement ok+create table min_max_base_grouped_simple as values+ (0, make_array()),+ (0, make_array(1)),+ (0, make_array()),+ (1, make_array()),+ (1, make_array(5, 6))+;++# --------------------------------------+# 11. Min over with window function+# --------------------------------------+statement ok+create table min_base_window_simple as values+ (make_array(1, 2, 3)),+ (make_array(1, 2, 3)),+ (make_array(2, 3))+;++# --------------------------------------+# 12. Min over with window + NULLs+# --------------------------------------+statement ok+create table min_base_window_with_null as values+ (make_array(NULL)),+ (make_array(4, 5)),+ (make_array(2, 3))+;++# --------------------------------------+# 13. Min over with ROWS BETWEEN clause+# --------------------------------------+statement ok+create table min_base_window_rows_between as values+ (make_array(NULL)),+ (make_array(4, 5)),+ (make_array(2, 3))+;++# --------------------------------------+# 14. Max over using different order column+# --------------------------------------+statement ok+create table max_base_window_different_column as values+ (make_array(1, 2, 3), make_array(4, 5)),+ (make_array(2, 3), make_array(2, 3)),+ (make_array(2, 3), NULL)+;diff --git a/datafusion/sqllogictest/test_files/min_max/large_list.slt b/datafusion/sqllogictest/test_files/min_max/large_list.sltnew file mode 100644index 0000000000..0dd7b5631b--- /dev/null+++ b/datafusion/sqllogictest/test_files/min_max/large_list.slt@@ -0,0 +1,148 @@+# 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.++include ./init_data.slt.part++## --------------------------------------+## 1. Min/Max over integers+## --------------------------------------+statement ok+create table min_max_int as (+ select+ arrow_cast(column1, 'LargeList(Int64)') as column1+ from min_max_base_int+ );++## --------------------------------------+## 2. Min/Max over strings+## --------------------------------------+statement ok+create table min_max_string as (+ select+ arrow_cast(column1, 'LargeList(Utf8)') as column1+from min_max_base_string);++## --------------------------------------+## 3. Min/Max over booleans+## --------------------------------------+statement ok+create table min_max_bool as+(+ select+ arrow_cast(column1, 'LargeList(Boolean)') as column1+from min_max_base_bool);++## --------------------------------------+## 4. Min/Max over nullable integers+## --------------------------------------+statement ok+create table min_max_nullable_int as (+ select+ arrow_cast(column1, 'LargeList(Int64)') as column1+ from min_max_base_nullable_int+);++## --------------------------------------+## 5. Min/Max with mixed lengths and nulls+## --------------------------------------+statement ok+create table min_max_mixed_lengths_nulls as (select+ arrow_cast(column1, 'LargeList(Int64)') as column1+from min_max_base_mixed_lengths_nulls);++## --------------------------------------+## 6. Min/Max with only NULLs+## --------------------------------------+statement ok+create table min_max_all_nulls as (select+ arrow_cast(column1, 'LargeList(Int64)') as column1+from min_max_base_all_nulls);++## --------------------------------------+## 7. Min/Max with partial NULLs+## --------------------------------------+statement ok+create table min_max_null_variants as (select+ arrow_cast(column1, 'LargeList(Int64)') as column1+from min_max_base_null_variants);++## --------------------------------------+## 8. Min/Max grouped by key with NULLs and differing lengths+## --------------------------------------+statement ok+create table min_max_grouped_nulls as (select+ column1,+ arrow_cast(column2, 'LargeList(Int64)') as column2+from min_max_base_grouped_nulls);++## --------------------------------------+## 9. Min/Max grouped by key with only NULLs+## --------------------------------------+statement ok+create table min_max_grouped_all_null as (select+ column1,+ arrow_cast(column2, 'LargeList(Int64)') as column2+from min_max_base_grouped_all_null);++## --------------------------------------+## 10. Min/Max grouped with simple sizes+## --------------------------------------+statement ok+create table min_max_grouped_simple as (select+ column1,+ arrow_cast(column2, 'LargeList(Int64)') as column2+from min_max_base_grouped_simple);++## --------------------------------------+## 11. Min over with window function+## --------------------------------------+statement ok+create table min_window_simple as (select+ arrow_cast(column1, 'LargeList(Int64)') as column1+from min_base_window_simple);++## --------------------------------------+## 12. Min over with window + NULLs+## --------------------------------------+statement ok+create table min_window_with_null as (select+ arrow_cast(column1, 'LargeList(Int64)') as column1+from min_base_window_with_null);++## --------------------------------------+## 13. Min over with ROWS BETWEEN clause+## --------------------------------------+statement ok+create table min_window_rows_between as (select+ arrow_cast(column1, 'LargeList(Int64)') as column1+from min_base_window_rows_between);++## --------------------------------------+## 14. Max over using different order column+## --------------------------------------+statement ok+create table max_window_different_column as (select+ arrow_cast(column1, 'LargeList(Int64)') as column1,+ arrow_cast(column2, 'LargeList(Int64)') as column2+from max_base_window_different_column);++include ./queries.slt.part+++++diff --git a/datafusion/sqllogictest/test_files/min_max/list.slt b/datafusion/sqllogictest/test_files/min_max/list.sltnew file mode 100644index 0000000000..da56b1a8ea--- /dev/null+++ b/datafusion/sqllogictest/test_files/min_max/list.slt@@ -0,0 +1,133 @@+# 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.++include ./init_data.slt.part++# --------------------------------------+# 1. Min/Max over integers+# --------------------------------------+statement ok+create table min_max_int as (+ select * from min_max_base_int )+;++# --------------------------------------+# 2. Min/Max over strings+# --------------------------------------+statement ok+create table min_max_string as (+ select * from min_max_base_string )+;++# --------------------------------------+# 3. Min/Max over booleans+# --------------------------------------+statement ok+create table min_max_bool as (+ select * from min_max_base_bool )+;++# --------------------------------------+# 4. Min/Max over nullable integers+# --------------------------------------+statement ok+create table min_max_nullable_int as (+ select * from min_max_base_nullable_int )+;++# --------------------------------------+# 5. Min/Max with mixed lengths and nulls+# --------------------------------------+statement ok+create table min_max_mixed_lengths_nulls as (+ select * from min_max_base_mixed_lengths_nulls )+;++# --------------------------------------+# 6. Min/Max with only NULLs+# --------------------------------------+statement ok+create table min_max_all_nulls as (+ select * from min_max_base_all_nulls )+;++# --------------------------------------+# 7. Min/Max with partial NULLs+# --------------------------------------+statement ok+create table min_max_null_variants as (+ select * from min_max_base_null_variants )+;++# --------------------------------------+# 8. Min/Max grouped by key with NULLs and differing lengths+# --------------------------------------+statement ok+create table min_max_grouped_nulls as (+ select * from min_max_base_grouped_nulls )+;++# --------------------------------------+# 9. Min/Max grouped by key with only NULLs+# --------------------------------------+statement ok+create table min_max_grouped_all_null as (+ select * from min_max_base_grouped_all_null )+;++# --------------------------------------+# 10. Min/Max grouped with simple sizes+# --------------------------------------+statement ok+create table min_max_grouped_simple as (+ select * from min_max_base_grouped_simple )+;++# --------------------------------------+# 11. Min over with window function+# --------------------------------------+statement ok+create table min_window_simple as (+ select * from min_base_window_simple )+;++# --------------------------------------+# 12. Min over with window + NULLs+# --------------------------------------+statement ok+create table min_window_with_null as (+ select * from min_base_window_with_null )+;++# --------------------------------------+# 13. Min over with ROWS BETWEEN clause+# --------------------------------------+statement ok+create table min_window_rows_between as (+ select * from min_base_window_rows_between )+;++# --------------------------------------+# 14. Max over using different order column+# --------------------------------------+statement ok+create table max_window_different_column as (+ select * from max_base_window_different_column )+;++include ./queries.slt.part+diff --git a/datafusion/sqllogictest/test_files/min_max/queries.slt.part b/datafusion/sqllogictest/test_files/min_max/queries.slt.partnew file mode 100644index 0000000000..bc7fb840bf--- /dev/null+++ b/datafusion/sqllogictest/test_files/min_max/queries.slt.part@@ -0,0 +1,112 @@+# 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.+++## 1. Min/Max List over integers+query ??+SELECT MIN(column1), MAX(column1) FROM min_max_int;+----+[1, 2] [1, 2, 3, 4]++## 2. Min/Max List over strings+query ??+SELECT MIN(column1), MAX(column1) FROM min_max_string;+----+[a, b] [a, b, c]++## 3. Min/Max List over booleans+query ??+SELECT MIN(column1), MAX(column1) FROM min_max_bool;+----+[true, false] [true, false, true]++## 4. Min/Max List over nullable integers+query ??+SELECT MIN(column1), MAX(column1) FROM min_max_nullable_int;+----+[1, 2] [NULL, 1, 2]++## 5. Min/Max List with mixed lengths and nulls+query ??+SELECT MIN(column1), MAX(column1) FROM min_max_mixed_lengths_nulls;+----+[1, 2] [1, NULL, 3]++## 6. Min/Max List with only NULLs+query ??+SELECT MIN(column1), MAX(column1) FROM min_max_all_nulls;+----+[NULL] [NULL, NULL]++## 7. Min/Max List with partial NULLs+query ??+SELECT MIN(column1), MAX(column1) FROM min_max_null_variants;+----+[1, 2, 3] [NULL, 2, 3]++## 8. Min/Max List grouped by key with NULLs and differing lengths+query I??+SELECT column1, MIN(column2), MAX(column2) FROM min_max_grouped_nulls GROUP BY column1 ORDER BY column1;+----+0 [1, 2, 3, 4] [1, NULL, 3]+1 [] [NULL, 5]++## 9. Min/Max List grouped by key with only NULLs+query I??+SELECT column1, MIN(column2), MAX(column2) FROM min_max_grouped_all_null GROUP BY column1 ORDER BY column1;+----+0 [NULL] [NULL, NULL]+1 [NULL] [NULL]++## 10. Min/Max grouped List with simple sizes+query I??+SELECT column1, MIN(column2), MAX(column2) FROM min_max_grouped_simple GROUP BY column1 ORDER BY column1;+----+0 [] [1]+1 [] [5, 6]++## 11. Min over List with window function+query ?+SELECT MIN(column1) OVER (ORDER BY column1) FROM min_window_simple;+----+[1, 2, 3]+[1, 2, 3]+[1, 2, 3]++## 12. Min over List with window + NULLs+query ?+SELECT MIN(column1) OVER (ORDER BY column1) FROM min_window_with_null;+----+[2, 3]+[2, 3]+[2, 3]++## 13. Min over List with ROWS BETWEEN clause+query ?+SELECT MIN(column1) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM min_window_rows_between;+----+[2, 3]+[2, 3]+[4, 5]++## 14. Max over List using different order column+query ?+SELECT MAX(column2) OVER (ORDER BY column1 ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM max_window_different_column;+----+[4, 5]+[4, 5]+[2, 3]