jagill commented on code in PR #6643:
URL: https://github.com/apache/arrow-rs/pull/6643#discussion_r1909571822


##########
arrow-json/src/reader/struct_array.rs:
##########
@@ -70,43 +74,81 @@ impl ArrayDecoder for StructArrayDecoder {
             .is_nullable
             .then(|| BooleanBufferBuilder::new(pos.len()));
 
-        for (row, p) in pos.iter().enumerate() {
-            let end_idx = match (tape.get(*p), nulls.as_mut()) {
-                (TapeElement::StartObject(end_idx), None) => end_idx,
-                (TapeElement::StartObject(end_idx), Some(nulls)) => {
-                    nulls.append(true);
-                    end_idx
-                }
-                (TapeElement::Null, Some(nulls)) => {
-                    nulls.append(false);
-                    continue;
-                }
-                _ => return Err(tape.error(*p, "{")),
-            };
-
-            let mut cur_idx = *p + 1;
-            while cur_idx < end_idx {
-                // Read field name
-                let field_name = match tape.get(cur_idx) {
-                    TapeElement::String(s) => tape.get_string(s),
-                    _ => return Err(tape.error(cur_idx, "field name")),
+        if self.struct_mode == StructMode::ObjectOnly {
+            for (row, p) in pos.iter().enumerate() {
+                let end_idx = match (tape.get(*p), nulls.as_mut()) {
+                    (TapeElement::StartObject(end_idx), None) => end_idx,
+                    (TapeElement::StartObject(end_idx), Some(nulls)) => {
+                        nulls.append(true);
+                        end_idx
+                    }
+                    (TapeElement::Null, Some(nulls)) => {
+                        nulls.append(false);
+                        continue;
+                    }
+                    (_, _) => return Err(tape.error(*p, "{")),
                 };
 
-                // Update child pos if match found
-                match fields.iter().position(|x| x.name() == field_name) {
-                    Some(field_idx) => child_pos[field_idx][row] = cur_idx + 1,
-                    None => {
-                        if self.strict_mode {
-                            return Err(ArrowError::JsonError(format!(
-                                "column '{}' missing from schema",
-                                field_name
-                            )));
+                let mut cur_idx = *p + 1;
+                while cur_idx < end_idx {
+                    // Read field name
+                    let field_name = match tape.get(cur_idx) {
+                        TapeElement::String(s) => tape.get_string(s),
+                        _ => return Err(tape.error(cur_idx, "field name")),
+                    };
+
+                    // Update child pos if match found
+                    match fields.iter().position(|x| x.name() == field_name) {
+                        Some(field_idx) => child_pos[field_idx][row] = cur_idx 
+ 1,
+                        None => {
+                            if self.strict_mode {
+                                return Err(ArrowError::JsonError(format!(
+                                    "column '{}' missing from schema",
+                                    field_name
+                                )));
+                            }
                         }
                     }
+                    // Advance to next field
+                    cur_idx = tape.next(cur_idx + 1, "field value")?;
                 }
+            }
+        } else {
+            for (row, p) in pos.iter().enumerate() {

Review Comment:
   Yeah, strict mode is implied for Lists, since you can't skip a field and 
know what field was skipped (since you have no field names).  I've updated the 
documentation in `with_strict_mode` to make this explicit.  It just occurs to 
me that `strict_mode` and `struct_mode` are very similar names.



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