Skip to content

Apache DataFusion SQL Query Engine

fix: null padding for `array_reverse` on `FixedSizeList` (#17673)

Chen Chongchend96fbde61250
diff --git a/datafusion/functions-nested/src/reverse.rs b/datafusion/functions-nested/src/reverse.rs
index 2fd444f0f0..35ee312945 100644
--- a/datafusion/functions-nested/src/reverse.rs
+++ b/datafusion/functions-nested/src/reverse.rs
@@ -199,7 +199,7 @@ fn fixed_size_array_reverse(
// skip the null value
if array.is_null(row_index) {
nulls.push(false);
- mutable.extend(0, 0, 1);
+ mutable.extend(0, 0, value_length);
continue;
} else {
nulls.push(true);
diff --git a/datafusion/sqllogictest/test_files/array.slt b/datafusion/sqllogictest/test_files/array.slt
index 3521594020..75cf13aae0 100644
--- a/datafusion/sqllogictest/test_files/array.slt
+++ b/datafusion/sqllogictest/test_files/array.slt
@@ -8026,6 +8026,23 @@ NULL NULL
[60, 59, 58, 57, 56, 55, 54, NULL, 52, 51] [51, 52, NULL, 54, 55, 56, 57, 58, 59, 60]
[70, 69, 68, 67, 66, 65, 64, 63, 62, 61] [61, 62, 63, 64, 65, 66, 67, 68, 69, 70]
+statement ok
+CREATE TABLE test_reverse_fixed_size AS VALUES
+ (arrow_cast([1, 2, 3], 'FixedSizeList(3, Int64)')),
+ (arrow_cast([4, 5, 6], 'FixedSizeList(3, Int64)')),
+ (arrow_cast([NULL, 8, 9], 'FixedSizeList(3, Int64)')),
+ (NULL);
+
+query ?
+SELECT array_reverse(column1) FROM test_reverse_fixed_size;
+----
+[3, 2, 1]
+[6, 5, 4]
+[9, 8, NULL]
+NULL
+
+statement ok
+DROP TABLE test_reverse_fixed_size;
# Test defining a table with array columns
statement ok