alamb commented on a change in pull request #1205:
URL: https://github.com/apache/arrow-rs/pull/1205#discussion_r788014908



##########
File path: arrow/src/json/writer.rs
##########
@@ -110,64 +110,64 @@ use serde_json::Value;
 
 use crate::array::*;
 use crate::datatypes::*;
-use crate::error::Result;
+use crate::error::{ArrowError, Result};
 use crate::record_batch::RecordBatch;
 
-fn primitive_array_to_json<T: ArrowPrimitiveType>(array: &ArrayRef) -> 
Vec<Value> {
-    as_primitive_array::<T>(array)
+fn primitive_array_to_json<T: ArrowPrimitiveType>(
+    array: &ArrayRef,
+) -> Result<Vec<Value>> {
+    Ok(as_primitive_array::<T>(array)
         .iter()
         .map(|maybe_value| match maybe_value {
             Some(v) => v.into_json_value().unwrap_or(Value::Null),
             None => Value::Null,
         })
-        .collect()
+        .collect())
 }
 
 fn struct_array_to_jsonmap_array(
     array: &StructArray,
     row_count: usize,
-) -> Vec<JsonMap<String, Value>> {
+) -> Result<Vec<JsonMap<String, Value>>> {
     let inner_col_names = array.column_names();
 
     let mut inner_objs = iter::repeat(JsonMap::new())
         .take(row_count)
         .collect::<Vec<JsonMap<String, Value>>>();
 
-    array
-        .columns()
-        .iter()
-        .enumerate()
-        .for_each(|(j, struct_col)| {
-            set_column_for_json_rows(
-                &mut inner_objs,
-                row_count,
-                struct_col,
-                inner_col_names[j],
-            );
-        });
-
-    inner_objs
+    for (j, struct_col) in array.columns().iter().enumerate() {
+        match set_column_for_json_rows(
+            &mut inner_objs,
+            row_count,
+            struct_col,
+            inner_col_names[j],
+        ) {
+            Ok(_) => {}
+            Err(e) => return Err(e),
+        }

Review comment:
       Indeed -- we are all learning together! Thank you for your contributions




-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to