Skip to content

Conversation

@liamzwbao
Copy link
Contributor

@liamzwbao liamzwbao commented Aug 16, 2025

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.

Rationale for this change

What changes are included in this PR?

Use extension traits to wrap the json variant conversion function, and rename batch function to a more common name.

Are these changes tested?

Yes

Are there any user-facing changes?

The APIs of parquet-variant-json are changed

@github-actions github-actions bot added the parquet-variant parquet-variant* crates label Aug 16, 2025
fn with_json(&mut self, json: &str) -> Result<(), ArrowError>;
}

fn build_json(json: &Value, builder: &mut impl VariantBuilderExt) -> Result<(), ArrowError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed redundant build_json

use base64::{engine::general_purpose, Engine as _};
use chrono::Timelike;
use parquet_variant::{Variant, VariantList, VariantObject};
use serde_json::Value;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes in this file are basically moving the doc to trait and function body to impl

@liamzwbao liamzwbao marked this pull request as ready for review August 17, 2025 03:18
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 @liamzwbao -- I think this is a really nice improvement (using traits is 👨‍🍳 👌 )

I took the liberty of renaming with_json to be append_json to be consistent with the other APIs but really this was very nicely done

cc @harshmotw-db and @scovich


build_json(&json, builder)?;
Ok(())
pub trait JsonToVariant {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite clever

Ok(())
pub trait JsonToVariant {
/// Create a Variant from a JSON string
fn with_json(&mut self, json: &str) -> Result<(), ArrowError>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we pleae call this append_json to be consistent with VariantBuilderExt::append_value ?

Also I think the convention of using with_* in these crates is for builder / fluent style APIs that take self (rather than &mut self)

Copy link
Contributor

@scovich scovich left a comment

Choose a reason for hiding this comment

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

LGTM

@liamzwbao
Copy link
Contributor Author

Resolved conflicts, should be good to go now

@alamb alamb merged commit cf0c089 into apache:main Aug 19, 2025
12 checks passed
@alamb
Copy link
Contributor

alamb commented Aug 19, 2025

Thank you @liamzwbao and @scovich

@liamzwbao liamzwbao deleted the issue-8144-func-rename branch August 19, 2025 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] Rename batch_json_string_to_variant and batch_variant_to_json_string json_to_variant

3 participants