-
Notifications
You must be signed in to change notification settings - Fork 1k
Variant: Write Variant Values as JSON #7670
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f278b9d
[CHANGE][ISSUE#7426] Add support to convert variant to JSON
carpecodeum 4f005f3
[FIX] fix doc tests and refactor code in variant_to_json
carpecodeum 5c249f8
[FIX] fix issues with clippy errors and rename files
carpecodeum 97e9309
[FIX/ADD] fix and changes to accomodate new variant types
carpecodeum c4e4868
[TEST] add tests for new variant types to json functionality
carpecodeum f930f3b
[FIX] fix merge conflict issues
carpecodeum 345d9c5
[TEST] Add tests for objects and lists to json
carpecodeum 47d809b
[FIX] fix cargo fmt tests
carpecodeum b8f708a
[FIX] fix clippy warnings
carpecodeum 1ac766d
[RENAME] rename file to to_json
carpecodeum 5f7cca7
[FIX] use impl in convert_variant_to_json function
carpecodeum e2502a6
[FIX] try removing f64 to convert decimal to string
carpecodeum d947dce
[FIX] make date time formatting more modular
carpecodeum c96c2d4
[FIX] fix merge conflicts
carpecodeum 743d0e9
[FIX] make intergration_tests.rs more modular
carpecodeum b455997
[FIX] modify to_json to hide lines when rendering as documentation & …
carpecodeum 1853fe5
[FIX] modify the examples to a single function
carpecodeum b78b110
[FIX] add an example for the new variant builder
carpecodeum e7a103d
[FIX] remove integration_tests and consolidate tests
carpecodeum a7e19d8
[FIX] remove dependency on f64 variant_to_json_value conversion
carpecodeum a4314e2
[FIX] use the let-else pattern to reduce indentation
carpecodeum c8c810a
[FIX] fix the formatting issues
carpecodeum 3ac00ca
[FIX] fix all clippy and doc tests errors
carpecodeum b49c26f
Fix logical conflict with #7738
alamb a47ccfc
Less explicit panics
alamb 0e10d82
[FIX] retain the position of from bool
carpecodeum 35a2f50
[FIX] make the returns from writes more modular
carpecodeum b16d1e5
[FIX] make the write decimal functions modular
carpecodeum 4010b73
[FIX] format code with improved iters and value::null handling
carpecodeum de7c979
[FIX] fix further precision issues from the decimal
carpecodeum d8f43f2
[FIX] implement fromiterator
carpecodeum 2f52569
[FIX] fix clippy and fmt errors
carpecodeum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! Example showing how to convert Variant values to JSON | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be great to include this inline in the docs rather than a standalone example, but I will make a follow on PR to do so |
||
| use parquet_variant::{ | ||
| variant_to_json, variant_to_json_string, variant_to_json_value, VariantBuilder, | ||
| }; | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let mut builder = VariantBuilder::new(); | ||
|
|
||
| { | ||
| let mut person = builder.new_object(); | ||
| person.append_value("name", "Alice"); | ||
| person.append_value("age", 30i32); | ||
| person.append_value("email", "[email protected]"); | ||
| person.append_value("is_active", true); | ||
| person.append_value("score", 95.7f64); | ||
| person.append_value("department", "Engineering"); | ||
| person.finish(); | ||
| } | ||
|
|
||
| let (metadata, value) = builder.finish(); | ||
| let variant = parquet_variant::Variant::try_new(&metadata, &value)?; | ||
|
|
||
| let json_string = variant_to_json_string(&variant)?; | ||
| let json_value = variant_to_json_value(&variant)?; | ||
| let pretty_json = serde_json::to_string_pretty(&json_value)?; | ||
| println!("{}", pretty_json); | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| variant_to_json(&mut buffer, &variant)?; | ||
| let buffer_result = String::from_utf8(buffer)?; | ||
|
|
||
| // Verify all methods produce the same result | ||
| assert_eq!(json_string, buffer_result); | ||
| assert_eq!(json_string, serde_json::to_string(&json_value)?); | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be nice if we could avoid adding these dependencies if possible as serdejson brings non trivial code.
This probably looks like adding a optional feature flag (like serde-json) or something
I think we can do it as a follow on PR though
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.
Filed
serde_jsonan optional dependency ofparquet-variant#7775