-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Variant] Introduce parquet-variant-json crate
#7862
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
Conversation
| @@ -1,552 +0,0 @@ | |||
| // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these tests into a mod test next to the relevant code
| @@ -1,151 +0,0 @@ | |||
| // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves to new crate
| @@ -1,50 +0,0 @@ | |||
| // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example duplicated the doc example on from_json so I removed it entirely
|
@harshmotw-db or @scovich or @friendlymatthew -- could i trouble one of you for a review of this PR? |
| arrow-schema = { workspace = true } | ||
| parquet-variant = { path = "../parquet-variant" } | ||
| chrono = { workspace = true } | ||
| serde_json = "1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea being, this new crate can take an unapologetic dependency on serde-json, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any changes in this file? Or just code movement that github didn't detect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume it's because this PR adds some tests to this file. Moving the tests to a different file should fix it.
| #[cfg(test)] | ||
| mod test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thatsalottatests... move to from_json/test.rs while we're at it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is more standard to put in the same module as the code being tested. I prefer it this way but I think it would be fine to move it to a different file if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting.. I didn't have any intuition that inline vs. out of line test modules were meaningfully different?
#[cfg(test)]
mod tests {
...
}vs.
#[cfg(test)]
mod tests;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a matter of convention / preference -- I don't think there is any technical difference
If you strongly prefer an out of line test module I will change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any other out of line test modules, so we should probably follow the existing convention?
(if we were going to split one out, I'd probably start with the 2k+ LoC in the builder.rs test module)
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again... to_json/tests.rs while we're at it?
| /// let json_result = variant_to_json_string(&variant)?; | ||
| /// let json_value = variant_to_json_value(&variant)?; | ||
| /// | ||
| /// let mut buffer = Vec::new(); | ||
| /// variant_to_json(&mut buffer, &variant)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you think of keeping variant_to_json and variant_to_json_string in the main crate? They have no dependency on serde-json, and IMO are useful in their own right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree they are useful in their own right, but I think it is pretty confusing to have json functionality split across two crates. I suggest we move all the JSON stuff to a new crate and we can always put to_json back if a need arises
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every engine needs the ability to convert variant values to strings, in order to display query results:
SELECT v FROM tAnd the string form of a variant column is the output of variant_to_json_string.
This is true regardless of which JSON library they might use (serde_json vs arrow-json vs. something else entirely), and also true even if they use no JSON library at all.
In other words,
we can always put to_json back if a need arises
... will happen the moment an engine actually tries to integrate with parquet-json and doesn't want to take on a serde-json dependency. The fact that this PR tries to isolate the serde-json dependency to its own sub-crate is a claim that such engines exist.
it is pretty confusing to have json functionality split across two crates
JSON functionality (as in, parsing and manipulating JSON trees) is different from converting variant values to strings, even if it so happens that the string form is a JSON value literal?
What if we drop variant_to_json_string from the public API, and just impl Display for Variant instead? Anything fancier would require a json library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we drop variant_to_json_string from the public API, and just impl Display for Variant instead? Anything fancier would require a json library.
I think this sounds like a good idea to me.
What do you think @harshmotw-db ? I can make the change if we are agreed (though this PR is getting big as it is)
I could do it in this PR or a follow on one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I didn't notice before, but the to-string logic relies on serde_json::to_string for proper JSON string escaping. So the code really is tied to serde_json crate.
Further, serde_json::to_string is fallible, which would not play well with std::fmt::Error used by impl Display:
This type does not support transmission of an error other than that an error occurred. This is because, despite the existence of this error, string formatting is considered an infallible operation.
fmt()implementors should not return thisErrorunless they received it from their Formatter. The only time your code should create a new instance of this error is when implementingfmt::Write, in order to cancel the formatting operation when writing to the underlying stream fails.
Probably better to take this as a follow-up item...
harshmotw-db
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
|
Let's go with this one and then refactor as needed |
|
Thank you again @scovich @friendlymatthew and @harshmotw-db for the reviews |
…s of JSON strings to and from Variants (#7884) # Which issue does this PR close? We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. - Closes #7883. # Rationale for this change Explained in the ticket. **Note:** This PR will go through changes once [this PR](#7862) is merged. # What changes are included in this PR? This PR introduces two new functions `batch_json_string_to_variant` and `batch_variant_to_json_string` which can be used to transform batches of JSON strings to batches of Variant structs and vice versa. This PR attempts to implement `batch_variant_to_json_string` in a zero-copy way (@alamb see if you agree) since `variant_to_json` allows an input implementing a `Write` interface. `batch_json_string_to_variant` should also eventually be zero-copy once [this issue](#7805) is resolved. # Are these changes tested? Simple unit tests since the underlying functions have already been tested. # Are there any user-facing changes? Yes, it introduces the `batch_json_string_to_variant` and `batch_variant_to_json_string` APIs in a new crate. --------- Co-authored-by: Andrew Lamb <[email protected]>
Which issue does this PR close?
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax.
serde_jsondependency ofparquet-variant#7845serde_jsonan optional dependency ofparquet-variant#7775Rationale for this change
Now that we have the basic json conversion functionality complete thanks to @harshmotw-db ❤️ ❤️ ❤️ in
I would like to move all the json related code into its own crate to keep the functionality clean and clear
What changes are included in this PR?
parquet-variant-jsoncrate where we can continue to iterateAre these changes tested?
CI
Are there any user-facing changes?
If there are user-facing changes then we may require documentation to be updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.