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

Using Borrow<Value> on infer_json_schema_from_iterator #3728

Merged
merged 1 commit into from Feb 16, 2023

Conversation

rguerreiromsft
Copy link
Contributor

@rguerreiromsft rguerreiromsft commented Feb 16, 2023

Which issue does this PR close?

None

Rationale for this change

In a project I'm working on, we need to save the json data and the schema into a different file. Today we need to clone the original json, where it'd be much easier to just use a read-only reference.

Are there any user-facing changes?

No, using Borrow makes any owned instance still work here.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Feb 16, 2023
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

I've left a suggestion on how to avoid the Box.

FWIW the Decoder that accepts Value is intended to be deprecated soon, see #3718, I'd be interested to hear your thoughts on this

where
I: Iterator<Item = Result<Value, ArrowError>>,
I: Iterator<Item = Result<V, ArrowError>>,
V: AsRef<Value>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
V: AsRef<Value>,
V: Borrow<Value>,

I think this should remove the need for the boxing

@rguerreiromsft
Copy link
Contributor Author

Thank you for both suggestions, I really appreciate them! I didn't remember about Borrow when coding it.

About the RawReader, awesome, I'll start using it right away!

However, I still need to use the infer_json_schema_from_iterator because I have to manually work with serde_json::Value before I attempt to generate the schema.

Then I save this schema into a file to be used later, but I'm using tokio::fs to work with files, it'd be nicer to have the RawReader also support async work. It's not a huge issue, though, I can use std fs for this particular operation.

On a separate note, I don't think exposing Values is a bad thing, sure a user doesn't need it, but when we're building a library on top of Arrow, it's nice to have access to lower level apis.

@rguerreiromsft rguerreiromsft changed the title Using AsRef<Value> on infer_json_schema_from_iterator Using Borrow<Value> on infer_json_schema_from_iterator Feb 16, 2023
…the json and get the schema. This avoids unnecessary cloning the entire json.
@tustvold
Copy link
Contributor

tustvold commented Feb 16, 2023

it'd be nicer to have the RawReader also support async work

You might want to try out RawDecoder in that case, it is designed for use in async contexts. You could possibly use it in conjunction with AsyncBufRead.

FYI no operating systems currently support async file IO, tokio actually just calls tokio::spawn_blocking under the hood, unless you're using something like glomio or streaming data over a network, async is not necessarily helpful.

I don't think exposing Values is a bad thing,

The reason for moving away from Values is to avoid intermediate allocations, and allow for vectorised decoding, there wasn't a way to achieve these with the current API.

@tustvold tustvold merged commit 59016e5 into apache:master Feb 16, 2023
@tustvold
Copy link
Contributor

Thank you

@ursabot
Copy link

ursabot commented Feb 16, 2023

Benchmark runs are scheduled for baseline = 221533f and contender = 59016e5. 59016e5 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

@rguerreiromsft
Copy link
Contributor Author

Thank you so much! I'll take a look at the RawDecoder. Because I'm also streaming multiple json files before saving them locally into a single file, which I'm providing to the RawReader.

I couldn't test everything yet, I'm certain there are improvements I need to do before finalizing everything.

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

3 participants