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

Add ArrayAccessor trait, remove duplication in array iterators (#1948) #2133

Merged
merged 3 commits into from Jul 22, 2022

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Part of #1948

Rationale for this change

This makes it possible to write code that is generic over more types, which is particularly useful for #1764 where otherwise GenericStringArray and GenericBinaryArray have to be handled separately.

What changes are included in this PR?

Adds an ArrayAccessor trait and uses this to reduce duplication within the iterators

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jul 22, 2022
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

I think this is very cool -- nice work @tustvold

cc @viirya and @HaoYang670 and @jhorstmann

I wonder if we should run benchmarks to verify this does not introduce a performance regression

}

/// A generic trait for accessing the values of an [`Array`]
pub trait ArrayAccessor: Array {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

// Note: This implementation is based on std's [Vec]s' [IntoIter].
#[derive(Debug)]
pub struct PrimitiveIter<'a, T: ArrowPrimitiveType> {
array: &'a PrimitiveArray<T>,
pub struct ArrayIter<T: ArrayAccessor> {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 this is very cool

@alamb alamb changed the title Add ArrayAccessor trait (#1948) Add ArrayAccessor trait, remove duplication in array iterators (#1948) Jul 22, 2022
Comment on lines +100 to +105
/// an iterator that returns Some(T) or None, that can be used on any PrimitiveArray
pub type PrimitiveIter<'a, T> = ArrayIter<&'a PrimitiveArray<T>>;
pub type BooleanIter<'a> = ArrayIter<&'a BooleanArray>;
pub type GenericStringIter<'a, T> = ArrayIter<&'a GenericStringArray<T>>;
pub type GenericBinaryIter<'a, T> = ArrayIter<&'a GenericBinaryArray<T>>;
pub type GenericListArrayIter<'a, O> = ArrayIter<&'a GenericListArray<O>>;
Copy link
Member

Choose a reason for hiding this comment

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

👍 Nice

@tustvold
Copy link
Contributor Author

Out benchmark coverage of these iterators does not appear to be excellent, but I'm not seeing anything to suggest this represents a regression

@codecov-commenter
Copy link

Codecov Report

Merging #2133 (6382402) into master (5e3facf) will decrease coverage by 0.05%.
The diff coverage is 69.95%.

❗ Current head 6382402 differs from pull request most recent head 5c3081d. Consider uploading reports for the commit 5c3081d to get more accurate results

@@            Coverage Diff             @@
##           master    #2133      +/-   ##
==========================================
- Coverage   83.71%   83.65%   -0.06%     
==========================================
  Files         225      225              
  Lines       59567    59606      +39     
==========================================
- Hits        49865    49862       -3     
- Misses       9702     9744      +42     
Impacted Files Coverage Δ
arrow/src/array/array_decimal.rs 91.03% <ø> (ø)
arrow/src/array/equal_json.rs 86.89% <0.00%> (-1.01%) ⬇️
arrow/src/array/mod.rs 100.00% <ø> (ø)
arrow/src/array/array.rs 86.83% <20.00%> (-4.98%) ⬇️
arrow/src/array/array_list.rs 95.10% <25.00%> (-1.12%) ⬇️
arrow/src/array/array_binary.rs 92.87% <50.00%> (-0.32%) ⬇️
arrow/src/array/array_boolean.rs 92.85% <50.00%> (-1.15%) ⬇️
arrow/src/array/array_primitive.rs 95.41% <50.00%> (-0.37%) ⬇️
arrow/src/array/array_string.rs 97.05% <50.00%> (-0.71%) ⬇️
parquet/src/column/reader/decoder.rs 61.33% <60.00%> (-2.05%) ⬇️
... and 14 more

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

@tustvold tustvold merged commit 91b2d7e into apache:master Jul 22, 2022
@ursabot
Copy link

ursabot commented Jul 22, 2022

Benchmark runs are scheduled for baseline = 866f1a1 and contender = 91b2d7e. 91b2d7e 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.

None yet

5 participants