-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add casting of count to UInt64 in array_repeat function to ensure consistent integer type handling
#14236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add casting of count to UInt64 in array_repeat function to ensure consistent integer type handling
#14236
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| use crate::utils::make_scalar_function; | ||
| use arrow::array::{Capacities, MutableArrayData}; | ||
| use arrow::compute; | ||
| use arrow::compute::cast; | ||
| use arrow_array::{ | ||
| new_null_array, Array, ArrayRef, GenericListArray, Int64Array, ListArray, | ||
| OffsetSizeTrait, | ||
|
|
@@ -136,7 +137,17 @@ pub fn array_repeat_inner(args: &[ArrayRef]) -> Result<ArrayRef> { | |
| } | ||
|
|
||
| let element = &args[0]; | ||
| let count_array = as_int64_array(&args[1])?; | ||
| let count_array = &args[1]; | ||
|
|
||
| let count_array = match count_array.data_type() { | ||
| DataType::Int8 | DataType::Int16 | DataType::Int32 => { | ||
| &cast(count_array, &DataType::Int64)? | ||
| } | ||
| DataType::Int64 => count_array, | ||
| _ => return exec_err!("count must be an integer type"), | ||
| }; | ||
|
|
||
| let count_array = as_int64_array(&count_array)?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we want the target type of with current implementation of It is behaving like this , if we are converting all > select array_repeat(1,-20000);
+--------------------------------------+
| array_repeat(Int64(1),Int64(-20000)) |
+--------------------------------------+
| [] |
+--------------------------------------+In Spark, it gives empty arrow for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By target type I've meant conversion to UInt internallly instead of Int, so it wouldn't affect any input arguments, only prevent this function from panicking on negative values (but I thought it would return cast error 🤔 ), so I don't think it's a breaking change. |
||
|
|
||
| match element.data_type() { | ||
| List(_) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely, UInt should also be allowed here