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-10996: [Rust] [Parquet] change return value type of get_arrow_schema_from_metadata() #9058

Closed
wants to merge 4 commits into from

Conversation

mqy
Copy link
Contributor

@mqy mqy commented Dec 31, 2020

#8936 updated crate flatbuffers to 0.8.0 , but function get_arrow_schema_from_metadata still returning Option rather than Result. This PR fixes this issue.

@mqy mqy changed the title ARROW-10996: [Rust] change return value type of get_arrow_schema_from_metadata ARROW-10996: [Rust] change return value type of get_arrow_schema_from_metadata() Dec 31, 2020
@github-actions
Copy link

@alamb
Copy link
Contributor

alamb commented Dec 31, 2020

The full set of Rust CI tests did not run on this PR :(

Can you please rebase this PR against apache/master to pick up the changes in #9056 so that they do?

I apologize for the inconvenience.

@mqy mqy force-pushed the get_arrow_schema_from_metadata branch from beceee3 to 2254cb5 Compare December 31, 2020 15:53
@mqy
Copy link
Contributor Author

mqy commented Dec 31, 2020

@alamb thanks
I will rebase again after #9061 get merged, it has passed all checks.
ping @Dandandan

@mqy mqy force-pushed the get_arrow_schema_from_metadata branch from 2254cb5 to c904ee9 Compare January 1, 2021 07:28
@codecov-io
Copy link

codecov-io commented Jan 1, 2021

Codecov Report

Merging #9058 (56c24ed) into master (51672b2) will increase coverage by 0.00%.
The diff coverage is 77.77%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9058   +/-   ##
=======================================
  Coverage   82.61%   82.62%           
=======================================
  Files         202      202           
  Lines       50048    50055    +7     
=======================================
+ Hits        41347    41356    +9     
+ Misses       8701     8699    -2     
Impacted Files Coverage Δ
rust/parquet/src/arrow/schema.rs 90.93% <77.77%> (+0.31%) ⬆️
rust/arrow/src/memory.rs 98.14% <0.00%> (-1.86%) ⬇️
rust/arrow/src/ffi.rs 70.00% <0.00%> (-0.29%) ⬇️
rust/arrow/src/array/array_boolean.rs 86.50% <0.00%> (-0.22%) ⬇️
rust/parquet/src/encodings/encoding.rs 95.24% <0.00%> (-0.20%) ⬇️
rust/arrow/src/array/array_primitive.rs 91.64% <0.00%> (-0.05%) ⬇️
rust/arrow/src/array/array_list.rs 93.10% <0.00%> (-0.02%) ⬇️
rust/arrow/src/buffer.rs 98.21% <0.00%> (-0.01%) ⬇️
rust/arrow/src/array/raw_pointer.rs 100.00% <0.00%> (ø)
rust/arrow/src/array/array_binary.rs 90.61% <0.00%> (ø)
... and 4 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 51672b2...56c24ed. Read the comment docs.

Copy link
Member

@jorgecarleitao jorgecarleitao left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks a lot @mqy for taking this on. I always hit those prints when searching for my own prints in the code 😆

.remove(super::ARROW_SCHEMA_META_KEY)
.map(|encoded| get_arrow_schema_from_metadata(&encoded));

let arrow_schema_metadata = match maybe_schema {
Copy link
Member

Choose a reason for hiding this comment

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

There may be an idiom for this in rust (that I do not know).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jorgecarleitao thank you for the tip!

The codes were updated to use map_or for flipping Option<Result> to Result<Option>.
BTW, I found some similar usage of map_or in parquet/src/column/writer.rs 🥇

_ => None,
};
.map(|encoded| get_arrow_schema_from_metadata(&encoded))
.map_or(Ok(None), |v| v.map(Some))?;
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 can use unwrap_or, as both of the cases map to Ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Dandandan thanks a lot! The code looks more concise!

@mqy mqy changed the title ARROW-10996: [Rust] change return value type of get_arrow_schema_from_metadata() ARROW-10996: [Rust] [Parquet] change return value type of get_arrow_schema_from_metadata() Jan 1, 2021
@@ -123,7 +119,7 @@ where
let arrow_schema_metadata = metadata
.remove(super::ARROW_SCHEMA_META_KEY)
.map(|encoded| get_arrow_schema_from_metadata(&encoded))
.unwrap_or_default();
.map_or(Ok(None), |v| v.map(Some))?;
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 can use it here to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, let me try

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.

Looks good to me -- thanks @mqy

I think @Dandandan has one more suggested cleanup https://github.com/apache/arrow/pull/9058/files#r550758655 -- but I also think this PR is fine to merge as is.

Let me know if you want to make any more changes -- once you are finished we'll merge it.

Thanks again

@mqy
Copy link
Contributor Author

mqy commented Jan 1, 2021

@Dandandan @alamb Sorry, I failed to apply unwrap_or or something else toparquet_to_arrow_schema_by_columns,
because there are two places using arrow schema (if exists), so we can't return early.

@Dandandan
Copy link
Contributor

@mqy no problem, is a rather small style improvement anyway.

@jorgecarleitao
Copy link
Member

Thanks a lot for helping out in the reviews, @Dandandan , much appreciated 💯

GeorgeAp pushed a commit to sirensolutions/arrow that referenced this pull request Jun 7, 2021
…chema_from_metadata()

apache#8936 updated crate `flatbuffers` to 0.8.0 , but function `get_arrow_schema_from_metadata` still returning `Option` rather than `Result`. This PR fixes this issue.

Closes apache#9058 from mqy/get_arrow_schema_from_metadata

Authored-by: mqy <meng.qingyou@gmail.com>
Signed-off-by: Jorge C. Leitao <jorgecarleitao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants