Skip to content

Commit 88e1964

Browse files
committed
fix test
1 parent 109bc6c commit 88e1964

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

parquet-variant/src/path.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::{borrow::Cow, ops::Deref};
3333
/// ```rust
3434
/// # use parquet_variant::{VariantPath, VariantPathElement};
3535
/// // access the field "foo" in a variant object value
36-
/// let path = VariantPath::from("foo");
36+
/// let path = VariantPath::try_from("foo").unwrap();
3737
/// // access the first element in a variant list vale
3838
/// let path = VariantPath::from(0);
3939
/// ```
@@ -43,7 +43,7 @@ use std::{borrow::Cow, ops::Deref};
4343
/// # use parquet_variant::{VariantPath, VariantPathElement};
4444
/// /// You can also create a path by joining elements together:
4545
/// // access the field "foo" and then the first element in a variant list value
46-
/// let path = VariantPath::from("foo").join(0);
46+
/// let path = VariantPath::try_from("foo").unwrap().join(0);
4747
/// // this is the same as the previous one
4848
/// let path2 = VariantPath::from_iter(["foo".into(), 0.into()]);
4949
/// assert_eq!(path, path2);
@@ -59,8 +59,8 @@ use std::{borrow::Cow, ops::Deref};
5959
/// ```
6060
/// # use parquet_variant::{VariantPath, VariantPathElement};
6161
/// /// You can also convert strings directly into paths using dot notation
62-
/// let path = VariantPath::from("foo.bar.baz");
63-
/// let expected = VariantPath::from("foo").join("bar").join("baz");
62+
/// let path = VariantPath::try_from("foo.bar.baz").unwrap();
63+
/// let expected = VariantPath::try_from("foo").unwrap().join("bar").join("baz");
6464
/// assert_eq!(path, expected);
6565
/// ```
6666
///
@@ -69,11 +69,21 @@ use std::{borrow::Cow, ops::Deref};
6969
/// # use parquet_variant::{VariantPath, VariantPathElement};
7070
/// /// You can access the paths using slices
7171
/// // access the field "foo" and then the first element in a variant list value
72-
/// let path = VariantPath::from("foo")
72+
/// let path = VariantPath::try_from("foo").unwrap()
7373
/// .join("bar")
7474
/// .join("baz");
7575
/// assert_eq!(path[1], VariantPathElement::field("bar"));
7676
/// ```
77+
///
78+
/// # Example: Accessing filed with bracket
79+
/// ```
80+
/// # use parquet_variant::{VariantPath, VariantPathElement};
81+
/// let path = VariantPath::try_from("a[b.c].d[2]").unwrap();
82+
/// let expected = VariantPath::from_iter([VariantPathElement::field("a"),
83+
/// VariantPathElement::field("b.c"),
84+
/// VariantPathElement::field("d"),
85+
/// VariantPathElement::index(2)]);
86+
/// assert_eq!(path, expected)
7787
#[derive(Debug, Clone, PartialEq, Default)]
7888
pub struct VariantPath<'a>(Vec<VariantPathElement<'a>>);
7989

parquet-variant/src/variant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,9 +1459,9 @@ impl<'m, 'v> Variant<'m, 'v> {
14591459
/// // given a variant like `{"foo": ["bar", "baz"]}`
14601460
/// let variant = Variant::new(&metadata, &value);
14611461
/// // Accessing a non existent path returns None
1462-
/// assert_eq!(variant.get_path(&VariantPath::from("non_existent")), None);
1462+
/// assert_eq!(variant.get_path(&VariantPath::try_from("non_existent").unwrap()), None);
14631463
/// // Access obj["foo"]
1464-
/// let path = VariantPath::from("foo");
1464+
/// let path = VariantPath::try_from("foo").unwrap();
14651465
/// let foo = variant.get_path(&path).expect("field `foo` should exist");
14661466
/// assert!(foo.as_list().is_some(), "field `foo` should be a list");
14671467
/// // Access foo[0]
@@ -1470,7 +1470,7 @@ impl<'m, 'v> Variant<'m, 'v> {
14701470
/// // bar is a string
14711471
/// assert_eq!(bar.as_string(), Some("bar"));
14721472
/// // You can also access nested paths
1473-
/// let path = VariantPath::from("foo").join(0);
1473+
/// let path = VariantPath::try_from("foo").unwrap().join(0);
14741474
/// assert_eq!(variant.get_path(&path).unwrap(), bar);
14751475
/// ```
14761476
pub fn get_path(&self, path: &VariantPath) -> Option<Variant<'_, '_>> {

0 commit comments

Comments
 (0)