Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Jun 25, 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

I was going through the code and examples and I felt that there was some redundancy and that the example file was unlikely to be found as not many crates in this repo have examples

I would like to propose moving the examples as close to the actual code as possible to give it the best chance to be discovered.

What changes are included in this PR?

  1. Remove parquet-variant/examples/variant_to_json_examples.rs
  2. Update some of the other examples and docs for the json functions with content from that example

Are these changes tested?

The examples are covered by CI tests.

Are there any user-facing changes?

Different docs

@github-actions github-actions bot added the parquet Changes to the parquet crate label Jun 25, 2025
///
///
/// ```rust
/// # use parquet_variant::{Variant, variant_to_json};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the redundant examples for Variant::Int32 and Variant::String, here and below, as I didn't think they were substantially different.

/// let mut buffer = Vec::new();
/// variant_to_json(&mut buffer, &variant)?;
/// assert_eq!(String::from_utf8(buffer).unwrap(), "\"Hello, World!\"");
/// let mut builder = VariantBuilder::new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The nested object is a great example and I wanted to have that again on variant_to_json as well

@alamb
Copy link
Contributor Author

alamb commented Jun 25, 2025

@carpecodeum I wonder if you have some time to review this PR?

@alamb alamb marked this pull request as ready for review June 25, 2025 21:39
/// # use parquet_variant::{Variant, variant_to_json};
/// # use arrow_schema::ArrowError;
/// let variant = Variant::Int32(42);
/// let variant = Variant::String("Hello, World!");
Copy link
Contributor

@friendlymatthew friendlymatthew Jun 25, 2025

Choose a reason for hiding this comment

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

Hi, I just realized there's nothing stopping a user from creating a Variant::String that could've been a Variant::ShortString.

This isn't the end of the world, but using the String variant adds 4 unnecessary bytes to the header, which could accumulate in loops or large payloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. My understanding is that a smaller string for Variant::Stirng is still valid, just less efficient.

Maybe I should update the examples to use Variant::from which does the right thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 6afa9cf

@alamb
Copy link
Contributor Author

alamb commented Jun 26, 2025

Thank you for the review @carpecodeum

@alamb alamb merged commit 72e91fc into apache:main Jun 26, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants