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

Implement Array for ArrayRef, Improve as_* kernels to take &dyn Array #1129

Merged
merged 3 commits into from
Jan 5, 2022

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jan 2, 2022

Which issue does this PR close?

Closes #1128

Rationale for this change

See ticket -- I am trying to make writing compute kernels more ergonomic while working on #1127

What changes are included in this PR?

  1. impl Array for ArrayRef
  2. Change signature fromarr: &ArrayRef to arr: &dyn Array in cast kernels
  3. tests for same

Are there any user-facing changes?

Better ergonomics (users can avoid .as_ref() in some places)

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 2, 2022
@alamb alamb changed the title Implement Array for ArrayRef Implement Array for ArrayRef, Improve as_* kernels to take &dyn Array Jan 2, 2022
@@ -21,7 +21,7 @@ use crate::array::*;
use crate::datatypes::*;

/// Force downcast ArrayRef to PrimitiveArray<T>
pub fn as_primitive_array<T>(arr: &ArrayRef) -> &PrimitiveArray<T>
pub fn as_primitive_array<T>(arr: &dyn Array) -> &PrimitiveArray<T>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As ArrayRef now implements Array all previous calls to this function will still compile and we can also pass &dyn Array as well

Copy link
Contributor Author

@alamb alamb Jan 5, 2022

Choose a reason for hiding this comment

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

FWIW this change means that calls that pass in a &ArrayRef will generate an extra dispatch as pointed out by @tustvold on #1128 (comment) -- this can be avoided by the user calling as_primitive_array(arr.as_ref()) or as_primitive_array(&*arr) if it is important to avoid the double dispatch

@@ -148,16 +148,6 @@ impl PyArrowConvert for ArrayData {
}
}

impl PyArrowConvert for ArrayRef {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is now covered by the impl of Array for ArrayRef

@codecov-commenter
Copy link

Codecov Report

Merging #1129 (4e82202) into master (89d5273) will increase coverage by 0.02%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1129      +/-   ##
==========================================
+ Coverage   82.36%   82.39%   +0.02%     
==========================================
  Files         169      169              
  Lines       49962    50008      +46     
==========================================
+ Hits        41152    41202      +50     
+ Misses       8810     8806       -4     
Impacted Files Coverage Δ
arrow/src/pyarrow.rs 0.00% <ø> (ø)
arrow/src/array/array.rs 85.14% <84.21%> (-0.11%) ⬇️
arrow/src/array/cast.rs 91.66% <93.75%> (+5.95%) ⬆️
arrow/src/array/equal_json.rs 89.91% <100.00%> (+0.05%) ⬆️
arrow/src/datatypes/field.rs 53.68% <0.00%> (+0.30%) ⬆️
arrow/src/datatypes/datatype.rs 66.80% <0.00%> (+0.42%) ⬆️
arrow/src/array/array_primitive.rs 94.66% <0.00%> (+0.42%) ⬆️
parquet_derive/src/parquet_field.rs 66.21% <0.00%> (+0.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89d5273...4e82202. Read the comment docs.

@alamb
Copy link
Contributor Author

alamb commented Jan 5, 2022

For other reviewers, there are a bunch of good comments from @tustvold on #1128 (comment) related to alternate approaches

@alamb alamb merged commit ae2e39c into apache:master Jan 5, 2022
@alamb alamb deleted the alamb/array_ref branch January 5, 2022 20:25
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.

Implement Array for ArrayRef
2 participants