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 the Iterator trait for the json Reader. #451

Merged
merged 2 commits into from
Jun 13, 2021

Conversation

LaurentMazare
Copy link
Contributor

Which issue does this PR close?

Closes #193 (JSON reader does not implement iterator).

Rationale for this change

Fairly straightforward change that makes it easy to iterate over RecordBatch when reading a json file.

What changes are included in this PR?

  • Implement the Iterator trait directly on json::Reader.
  • Add test reading some json file through a for loop using this iterator.

Are there any user-facing changes?

None expected, this adds a next function as part of the trait, there is already a public next function defined on json::Reader and this doesn't seem to be an issue.

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.

Thank you for the contribution @LaurentMazare ! This looks like a great improvement to me.

type Item = Result<RecordBatch>;

fn next(&mut self) -> Option<Self::Item> {
match self.next() {
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 you might be able to do self.next().transpose() here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah indeed that sounds more idiomatic, I just pushed this change.

@alamb alamb added the arrow Changes to the arrow crate label Jun 12, 2021
type Item = Result<RecordBatch>;

fn next(&mut self) -> Option<Self::Item> {
self.next().transpose()
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@codecov-commenter
Copy link

Codecov Report

Merging #451 (9aec343) into master (71e9d78) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #451   +/-   ##
=======================================
  Coverage   82.65%   82.66%           
=======================================
  Files         164      164           
  Lines       45468    45481   +13     
=======================================
+ Hits        37581    37596   +15     
+ Misses       7887     7885    -2     
Impacted Files Coverage Δ
arrow/src/json/reader.rs 83.91% <100.00%> (+0.26%) ⬆️
arrow/src/array/array_dictionary.rs 84.56% <0.00%> (-0.32%) ⬇️
arrow/src/compute/kernels/cast.rs 94.53% <0.00%> (ø)
arrow/src/array/transform/boolean.rs 84.61% <0.00%> (+7.69%) ⬆️

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 71e9d78...9aec343. Read the comment docs.

@nevi-me nevi-me merged commit e5cda31 into apache:master Jun 13, 2021
alamb pushed a commit that referenced this pull request Jun 22, 2021
* Implement the Iterator trait for the json Reader.

* Use transpose.
@alamb
Copy link
Contributor

alamb commented Jun 22, 2021

This is planned for release in arrow-rs 4.4.0 FYI

alamb added a commit that referenced this pull request Jun 23, 2021
* Implement the Iterator trait for the json Reader.

* Use transpose.

Co-authored-by: Laurent Mazare <laurent.mazare@gmail.com>
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.

JSON reader does not implement iterator
4 participants