sdf-jkl commented on code in PR #11232:
URL: https://github.com/apache/arrow-rs/pull/11232#discussion_r4127205423


##########
parquet-variant/src/path.rs:
##########
@@ -324,6 +324,32 @@ mod tests {
         assert_eq!(path, expected);
     }
 
+    #[test]
+    fn test_variant_path_bracket_field_ownership() {
+        let path = 
VariantPath::try_from(r#"[""]["plain"]["escaped\]field"]"#).unwrap();
+
+        match &path[0] {
+            VariantPathElement::Field {
+                name: Cow::Borrowed(name),
+            } => assert_eq!(*name, ""),
+            other => panic!("expected borrowed field, got {other:?}"),
+        }
+
+        match &path[1] {
+            VariantPathElement::Field {
+                name: Cow::Borrowed(name),
+            } => assert_eq!(*name, "plain"),
+            other => panic!("expected borrowed field, got {other:?}"),
+        }
+
+        match &path[2] {
+            VariantPathElement::Field {
+                name: Cow::Owned(name),
+            } => assert_eq!(name, "escaped]field"),
+            other => panic!("expected owned field, got {other:?}"),
+        }
+    }

Review Comment:
   can move the three asserts into one



##########
parquet-variant/src/utils.rs:
##########
@@ -243,26 +243,33 @@ fn parse_in_bracket(s: &str, i: usize) -> 
Result<(VariantPathElement<'_>, usize)
         match c {
             // Escape: take next char literally
             '\\' => {
+                let unescaped =
+                    unescaped.get_or_insert_with(|| 
String::from(&s[start..start + offset]));
                 if let Some((_, next)) = chars.next() {
                     unescaped.push(next);
                 }
                 // Trailing backslash will be handled as 'unclosed [' below
             }
             '\'' | '"' if quote == Some(c) => {
                 quote = None;
-                unescaped.push(c);
+                if let Some(unescaped) = &mut unescaped {
+                    unescaped.push(c);

Review Comment:
   Instead of pushing each char to the `unescaped` one by one we can count the 
offsets where the string starts and ends or encounters a new backslash. 
   
   It shows improvement when I prototyped locally



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to