-
Notifications
You must be signed in to change notification settings - Fork 881
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
feat: cast between Binary
/LargeBinary
and FixedSizeBinary
#3961
Conversation
arrow-cast/src/cast.rs
Outdated
if is_binary && offsets > i32::MAX as i64 { | ||
return Err(ArrowError::ComputeError( | ||
"Cast from FixedSizeBinary to Binary would overflow".to_string(), | ||
)); | ||
} |
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.
Isn't this also used to LargeBinaryArray
?
arrow-cast/src/cast.rs
Outdated
/// If the target one is too large for the source array it will return an Error. | ||
fn cast_fixed_size_binary_to_binary<O: OffsetSizeTrait>( | ||
array: &dyn Array, | ||
to_type: &DataType, |
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.
to_type
looks redundant as it is known GenericBinaryType<O>
.
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.
Looking good, left some comments
arrow-cast/src/cast.rs
Outdated
let array = array | ||
.as_any() | ||
.downcast_ref::<GenericBinaryArray<O>>() | ||
.unwrap(); |
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.
let array = array | |
.as_any() | |
.downcast_ref::<GenericBinaryArray<O>>() | |
.unwrap(); | |
let array = array.as_binary::<O>(); |
arrow-cast/src/cast.rs
Outdated
|
||
let offsets: i128 = byte_width as i128 * array.len() as i128; | ||
|
||
let is_binary = matches!(to_type, DataType::Binary); |
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.
Could we change this to match on GenericBinaryType<O>::DATA_TYPE
instead
arrow-cast/src/cast.rs
Outdated
let a1 = Arc::new(FixedSizeBinaryArray::from(binary_data.clone())) as ArrayRef; | ||
|
||
let array_ref = cast(&a1, &DataType::Binary).unwrap(); | ||
let down_cast = array_ref.as_any().downcast_ref::<BinaryArray>().unwrap(); |
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.
let down_cast = array_ref.as_any().downcast_ref::<BinaryArray>().unwrap(); | |
let down_cast = array_ref.as_binary::<i32>(); |
arrow-cast/src/cast.rs
Outdated
let down_cast = array_ref | ||
.as_any() | ||
.downcast_ref::<LargeBinaryArray>() | ||
.unwrap(); |
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.
let down_cast = array_ref | |
.as_any() | |
.downcast_ref::<LargeBinaryArray>() | |
.unwrap(); | |
let down_cast = array_ref.as_binary::<i64>(); |
arrow-cast/src/cast.rs
Outdated
if array.is_null(i) { | ||
builder.append_null(); | ||
} else { | ||
builder.append_value(array.value(i))?; |
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.
I think this should handle CastOptions::safe
and insert nulls instead of erroring if safe = true
arrow-cast/src/cast.rs
Outdated
"Cast from FixedSizeBinary to Binary would overflow".to_string(), | ||
)); | ||
} else if !is_binary && offsets > i64::MAX as i128 { | ||
return Err(ArrowError::ComputeError( | ||
"Cast from FixedSizeBinary to LargeBinary would overflow".to_string(), | ||
)); |
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.
The error message can be more specific. E.g., Cannot cast the FixedSizeBinary to Binary because exceeding maximum offset of Binary.
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.
LGTM (non-binding)
Which issue does this PR close?
Closes #3826
Rationale for this change
What changes are included in this PR?
Support cast between
Binary
/LargeBinary
andFixedSizeBinary
Are there any user-facing changes?