Skip to content

[Variant] Add documentation, tests and cleaner api for Variant::get_path #7942

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 1 commit into from
Jul 17, 2025

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
@@ -133,29 +132,21 @@ mod test {
fn get_primitive_variant_field() {
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

@@ -1068,6 +1072,35 @@ impl<'m, 'v> Variant<'m, 'v> {
/// Return a new Variant with the path followed.
///
/// 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.

@@ -22,7 +22,7 @@ use arrow::{
error::Result,
};
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