Skip to content
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 ArrayAccessor and FromIterator in Cast Kernels #2169

Merged
merged 3 commits into from Jul 27, 2022
Merged

Conversation

viirya
Copy link
Member

@viirya viirya commented Jul 25, 2022

Which issue does this PR close?

Closes #2137.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jul 25, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jul 25, 2022

Codecov Report

Merging #2169 (3ca4911) into master (13e6f39) will decrease coverage by 0.24%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2169      +/-   ##
==========================================
- Coverage   82.86%   82.61%   -0.25%     
==========================================
  Files         237      239       +2     
  Lines       61429    62272     +843     
==========================================
+ Hits        50902    51447     +545     
- Misses      10527    10825     +298     
Impacted Files Coverage Δ
arrow/src/compute/kernels/cast.rs 95.82% <100.00%> (+0.03%) ⬆️
parquet/src/column/page.rs 83.33% <0.00%> (-15.36%) ⬇️
object_store/src/local.rs 79.47% <0.00%> (-3.42%) ⬇️
parquet/src/arrow/array_reader/null_array.rs 78.57% <0.00%> (-2.92%) ⬇️
arrow/src/array/builder/boolean_builder.rs 84.26% <0.00%> (-2.47%) ⬇️
object_store/src/throttle.rs 94.63% <0.00%> (-1.89%) ⬇️
parquet/src/arrow/array_reader/mod.rs 87.50% <0.00%> (-0.74%) ⬇️
object_store/src/memory.rs 91.79% <0.00%> (-0.39%) ⬇️
...et/src/arrow/array_reader/byte_array_dictionary.rs 86.66% <0.00%> (-0.31%) ⬇️
arrow/src/array/builder/struct_builder.rs 77.09% <0.00%> (-0.26%) ⬇️
... and 27 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

|v| {
// with_precision_and_scale validates the
// value is within range for the output precision
((num::ToPrimitive::to_f64(&v).unwrap()) * mul) as i128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is now a checked conversion where previously it wasn't?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but I cannot use v as f64 here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error[E0605]: non-primitive cast: `<T as native::ArrowPrimitiveType>::Native` as `i128`
   --> arrow/src/compute/kernels/cast.rs:300:42
    |
300 |     cast_primitive_to_decimal(array, |v| v as i128 * mul, precision, scale)
    |                                          ^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added helper functions to ArrowPrimitiveType.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use AsPrimitive instead of ToPrimitive?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of AsPrimitive trait.

// value is within range for the output precision
cast_primitive_to_decimal(
array,
|v| v.to_isize().unwrap() as i128 * mul,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -79,6 +79,18 @@ pub trait ArrowNativeType:
None
}

/// Convert native type to i128.
#[inline]
fn to_i128(&self) -> Option<i128> {
Copy link
Contributor

@tustvold tustvold Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a massive fan of more of these, when I hope to remove them in favour of the standard num traits...

|v| {
// with_precision_and_scale validates the
// value is within range for the output precision
((num::ToPrimitive::to_f64(&v).unwrap()) * mul) as i128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use AsPrimitive instead of ToPrimitive?

@alamb alamb merged commit 445283c into apache:master Jul 27, 2022
@ursabot
Copy link

ursabot commented Jul 27, 2022

Benchmark runs are scheduled for baseline = dfc7ef8 and contender = 445283c. 445283c is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use ArrayAccessor and FromIterator in Cast Kernels
5 participants