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

ARROW-6847: [C++] Add range_expression adapter to Iterator #5621

Closed
wants to merge 6 commits into from

Conversation

bkietz
Copy link
Member

@bkietz bkietz commented Oct 10, 2019

Allows Iterator<T> to be used in a range-for loop

@github-actions
Copy link

@pitrou
Copy link
Member

pitrou commented Oct 14, 2019

Getting the Status on the side is a bit weird. Should we return a Result<> when iterating from the range instead?
@JohanMabille @wolfv What would be your thoughts on this?

@pitrou
Copy link
Member

pitrou commented Oct 14, 2019

(also needs rebasing @bkietz )

@bkietz
Copy link
Member Author

bkietz commented Oct 14, 2019

@pitrou returning a Result<> as the range value requires placing a status check inside the loop body:

for (Result<int> i_result : ints.AsRange()) {
  ARROW_ASSIGN_OR_RAISE(int i, i_result);
  // loop body
}

IMHO, this seems less natural to me than placing the check outside:

Status status;
for (int i : ints.AsRange(&status)) {
  // loop body
}
RETURN_NOT_OK(status);

But neither is a problem. @fsaintjacques ?

@bkietz bkietz force-pushed the 6847-Add-a-range-expression-in branch from 4efb645 to 72469af Compare October 14, 2019 20:35
@bkietz
Copy link
Member Author

bkietz commented Oct 14, 2019

@fsaintjacques @pitrou I've refactored so the range's elements are Result<>

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Perhaps you should add some tests for Status and Result (in)equality?

cpp/src/arrow/result.h Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Oct 15, 2019

Codecov Report

Merging #5621 into master will increase coverage by <.01%.
The diff coverage is 94.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5621      +/-   ##
==========================================
+ Coverage   89.49%   89.49%   +<.01%     
==========================================
  Files         898      796     -102     
  Lines      125350   118804    -6546     
  Branches     1501        0    -1501     
==========================================
- Hits       112182   106325    -5857     
+ Misses      13157    12479     -678     
+ Partials       11        0      -11
Impacted Files Coverage Δ
cpp/src/arrow/util/iterator.h 99.37% <100%> (+0.08%) ⬆️
cpp/src/arrow/result.h 90.38% <100%> (+0.18%) ⬆️
cpp/src/arrow/util/iterator_test.cc 98.66% <100%> (+0.18%) ⬆️
cpp/src/arrow/status.h 91.26% <70%> (-2.29%) ⬇️
python/pyarrow/plasma.py 58.9% <0%> (-1.37%) ⬇️
cpp/src/arrow/compute/kernels/hash_test.cc 100% <0%> (ø) ⬆️
js/src/util/fn.ts
js/src/builder/index.ts
js/src/enum.ts
js/src/Arrow.node.ts
... and 102 more

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 d7ad509...aa9934b. Read the comment docs.

@bkietz
Copy link
Member Author

bkietz commented Oct 15, 2019

@pitrou I've added inequality and tests

@fsaintjacques The EqualityComparable helper ought to help with https://issues.apache.org/jira/browse/ARROW-6772

@JohanMabille
Copy link
Contributor

JohanMabille commented Oct 16, 2019

Getting the Status on the side is a bit weird. Should we return a Result<> when iterating from the range instead?
@JohanMabille @wolfv What would be your thoughts on this?

Not sure to get why you need the iterator to fill a Status object. Anyway, the second loop written by @bkietz

for (int i : ints.AsRange(&status)) {
  // loop body
}

is indeed more natural in C++ than having to check anything in the loop body.

@bkietz
Copy link
Member Author

bkietz commented Oct 16, 2019

@JohanMabille the Iterator may return an error status when attempting to retrieve the next sequence element. That error needs to be accessible by the consumer of the Iterator, hence the result/side status loops.

Copy link
Contributor

@fsaintjacques fsaintjacques left a comment

Choose a reason for hiding this comment

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

Very handy work, this will definitively improve the ergonomics. I've restarted the tests, failed due to external errors (github or dockerhub network).

class EqualityComparable {
public:
~EqualityComparable() {
static_assert(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this safe to override the destructor just for a static_assert?

Copy link
Member Author

Choose a reason for hiding this comment

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

The default generated destructor is just an empty block like this. I think it's fine, but if you prefer I can replace with void CheckEqualsImpemented() or so

cpp/src/arrow/util/compare.h Show resolved Hide resolved
cpp/src/arrow/util/iterator.h Show resolved Hide resolved
@bkietz bkietz force-pushed the 6847-Add-a-range-expression-in branch from 409fa84 to 927ae0f Compare October 16, 2019 13:49
@bkietz bkietz deleted the 6847-Add-a-range-expression-in branch February 25, 2021 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants