Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Jul 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

While reviewing #7919 from @Samyak2 I found I wanted to write some additional tests directly for Variant::get_path

When I started doing that I found it was somewhat awkward to write examples, so I added some new conversion routines to make it easier.

What changes are included in this PR?

  1. Add doc examples (and thus tests) of VaraintGet and VariantPath
  2. Add more documentation

Are these changes tested?

Yes, by doc examples which run in 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.

@github-actions github-actions bot added the parquet Changes to the parquet crate label Jul 16, 2025
single_variant_get_test(
r#"{"some_field": 1234}"#,
vec![VariantPathElement::field("some_field".into())].into(),
VariantPath::from("some_field"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This gives a good idea of what the new API looks like. I think it is much clearer personally

///
/// If the path is not found, `None` is returned.
///
/// # Example
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 really wanted to add these tests / examples which lead to the other API changes

Copy link
Contributor Author

@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.

};
use arrow_schema::{ArrowError, Field};
use parquet_variant::path::VariantPath;
use parquet_variant::VariantPath;
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 re-exported the paths at the same top level

VariantPathElement::field("some_field".into()),
]
.into(),
VariantPath::from(0).join("some_field"),
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 a much better API!

Copy link
Contributor

@friendlymatthew friendlymatthew left a comment

Choose a reason for hiding this comment

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

Love the chaining -- looks very sleek

@alamb
Copy link
Contributor Author

alamb commented Jul 17, 2025

Thank you @friendlymatthew and @Samyak2 for the reviews

@alamb alamb merged commit d809f19 into apache:main Jul 17, 2025
12 checks passed
Comment on lines +49 to +52
/// let path3 = VariantPath::new(vec![
/// VariantPathElement::field("foo"),
/// VariantPathElement::index(0)
/// ]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it also impl FromIterator so people can do:

VariantPath::from_iter(["foo".into(), 0.into()])

or

["foo".into(), 0.into()].into_iter().collect::<VariantPath>()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alamb alamb deleted the alamb/variant_get_tests branch July 17, 2025 18:58
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.

4 participants