martin-g commented on code in PR #20102:
URL: https://github.com/apache/datafusion/pull/20102#discussion_r2754035422


##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -3256,24 +3256,97 @@ drop table array_repeat_table;
 statement ok
 drop table large_array_repeat_table;
 
-
+# array_repeat: arrays with NULL counts
 statement ok
 create table array_repeat_null_count_table
 as values
 (1, 2),
 (2, null),
-(3, 1);
+(3, 1),
+(4, -1);
 
 query I?
 select column1, array_repeat(column1, column2) from 
array_repeat_null_count_table;
 ----
 1 [1, 1]
-2 []
+2 NULL
 3 [3]
+4 []

Review Comment:
   ```suggestion
   4 []
   NULL NULL
   ```



##########
datafusion/functions-nested/src/repeat.rs:
##########
@@ -238,42 +231,46 @@ fn general_repeat<O: OffsetSizeTrait>(
 /// ```
 fn general_list_repeat<O: OffsetSizeTrait>(
     list_array: &GenericListArray<O>,
-    count_array: &UInt64Array,
+    count_array: &Int64Array,
 ) -> Result<ArrayRef> {
     let counts = count_array.values();

Review Comment:
   This also does not check for NULLs in the count_array and may lead to 
overestimates. You need to use `get_count_with_validity()` at line 245 too



##########
datafusion/functions-nested/src/repeat.rs:
##########
@@ -193,21 +180,27 @@ fn array_repeat_inner(args: &[ArrayRef]) -> 
Result<ArrayRef> {
 /// ```
 fn general_repeat<O: OffsetSizeTrait>(
     array: &ArrayRef,
-    count_array: &UInt64Array,
+    count_array: &Int64Array,
 ) -> Result<ArrayRef> {
-    // Build offsets and take_indices
-    let total_repeated_values: usize =
-        count_array.values().iter().map(|&c| c as usize).sum();
+    let total_repeated_values: usize = count_array
+        .values()
+        .iter()
+        .map(|&c| if c > 0 { c as usize } else { 0 })

Review Comment:
   Possible fix:
   ```rust
   let total_repeated_values: usize = (0..count_array.len())
       .map(|i| get_count_with_validity(count_array, i).0)
       .sum();
   ```



##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -3256,24 +3256,97 @@ drop table array_repeat_table;
 statement ok
 drop table large_array_repeat_table;
 
-
+# array_repeat: arrays with NULL counts
 statement ok
 create table array_repeat_null_count_table
 as values
 (1, 2),
 (2, null),
-(3, 1);
+(3, 1),
+(4, -1);

Review Comment:
   ```suggestion
   (4, -1),
   (null, null);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to