-
Notifications
You must be signed in to change notification settings - Fork 867
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
Use unary()
for array conversion in Parquet array readers, speed up Decimal128
, Decimal256
and Float16
#6252
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f37b8ae
add unary to FixedSizeBinaryArray; use unary for transformations
etseidl 69b42d9
clean up documentation some
etseidl 5db457c
add from_unary to PrimitiveArray
etseidl c388d30
use from_unary for converting byte array to decimal
etseidl cf625bf
rework from_unary to skip vector initialization
etseidl 4836237
add example to from_unary docstring
etseidl 7d1fac8
fix broken link
etseidl 96ad209
add comments per review suggestion
etseidl 1f600b6
Merge branch 'apache:master' into to_prim
etseidl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,35 +217,19 @@ where | |
arrow_cast::cast(&a, target_type)? | ||
} | ||
ArrowType::Decimal128(p, s) => { | ||
// We can simply reuse the null buffer from `array` rather than recomputing it | ||
// (as was the case when we simply used `collect` to produce the new array). | ||
let nulls = array.nulls().cloned(); | ||
let array = match array.data_type() { | ||
ArrowType::Int32 => { | ||
let decimal = array | ||
.as_any() | ||
.downcast_ref::<Int32Array>() | ||
.unwrap() | ||
.iter() | ||
.map(|v| match v { | ||
Some(i) => i as i128, | ||
None => i128::default(), | ||
}); | ||
Decimal128Array::from_iter_values_with_nulls(decimal, nulls) | ||
} | ||
|
||
ArrowType::Int64 => { | ||
let decimal = array | ||
.as_any() | ||
.downcast_ref::<Int64Array>() | ||
.unwrap() | ||
.iter() | ||
.map(|v| match v { | ||
Some(i) => i as i128, | ||
None => i128::default(), | ||
}); | ||
Decimal128Array::from_iter_values_with_nulls(decimal, nulls) | ||
} | ||
ArrowType::Int32 => array | ||
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. I suggest we add a comment explaining the rationale for not checking nulls -- something like // Apply conversion to all elements regardless of null slots as the conversion
// to `i128` is infallible. This improves performance by avoiding a branch in
// the inner loop 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. done! |
||
.as_any() | ||
.downcast_ref::<Int32Array>() | ||
.unwrap() | ||
.unary(|i| i as i128) | ||
as Decimal128Array, | ||
ArrowType::Int64 => array | ||
.as_any() | ||
.downcast_ref::<Int64Array>() | ||
.unwrap() | ||
.unary(|i| i as i128) | ||
as Decimal128Array, | ||
_ => { | ||
return Err(arrow_err!( | ||
"Cannot convert {:?} to decimal", | ||
|
@@ -258,35 +242,19 @@ where | |
Arc::new(array) as ArrayRef | ||
} | ||
ArrowType::Decimal256(p, s) => { | ||
// We can simply reuse the null buffer from `array` rather than recomputing it | ||
// (as was the case when we simply used `collect` to produce the new array). | ||
let nulls = array.nulls().cloned(); | ||
let array = match array.data_type() { | ||
ArrowType::Int32 => { | ||
let decimal = array | ||
.as_any() | ||
.downcast_ref::<Int32Array>() | ||
.unwrap() | ||
.iter() | ||
.map(|v| match v { | ||
Some(i) => i256::from_i128(i as i128), | ||
None => i256::default(), | ||
}); | ||
Decimal256Array::from_iter_values_with_nulls(decimal, nulls) | ||
} | ||
|
||
ArrowType::Int64 => { | ||
let decimal = array | ||
.as_any() | ||
.downcast_ref::<Int64Array>() | ||
.unwrap() | ||
.iter() | ||
.map(|v| match v { | ||
Some(i) => i256::from_i128(i as i128), | ||
None => i256::default(), | ||
}); | ||
Decimal256Array::from_iter_values_with_nulls(decimal, nulls) | ||
} | ||
ArrowType::Int32 => array | ||
.as_any() | ||
.downcast_ref::<Int32Array>() | ||
.unwrap() | ||
.unary(|i| i256::from_i128(i as i128)) | ||
as Decimal256Array, | ||
ArrowType::Int64 => array | ||
.as_any() | ||
.downcast_ref::<Int64Array>() | ||
.unwrap() | ||
.unary(|i| i256::from_i128(i as i128)) | ||
as Decimal256Array, | ||
_ => { | ||
return Err(arrow_err!( | ||
"Cannot convert {:?} to decimal", | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 like how this follows the model of
BooleanArray::from_unary
https://docs.rs/arrow/latest/arrow/array/struct.BooleanArray.html#method.from_unary