You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/12/11 08:59:54 UTC

Re: [PR] arrow_json: support decimal 128 and 256 types in json writer [arrow-rs]

tustvold commented on code in PR #5197:
URL: https://github.com/apache/arrow-rs/pull/5197#discussion_r1422118258


##########
arrow-json/src/writer.rs:
##########
@@ -469,11 +469,67 @@ fn set_column_for_json_rows(
                 row.insert(col_name.to_string(), serde_json::Value::Object(obj));
             }
         }
+        DataType::Decimal128(_precision, _scale) | DataType::Decimal256(_precision, _scale) => {
+            to_json_float(rows, array, col_name, explicit_nulls)?;
+        }
         _ => {
             return Err(ArrowError::JsonError(format!(
-                "data type {:?} not supported in nested map for json writer",
+                "data type {:?} not supported for json writer",
                 array.data_type()
-            )))
+            )));
+        }
+    }
+    Ok(())
+}
+
+fn to_json_float(
+    rows: &mut [Option<JsonMap<String, Value>>],
+    array: &ArrayRef,
+    col_name: &str,
+    explicit_nulls: bool,
+) -> Result<(), ArrowError> {
+    let options = FormatOptions::default();
+    let formatter = ArrayFormatter::try_new(array.as_ref(), &options)?;

Review Comment:
   This will result in precision loss, decimals need to use the formatting logic in arrow-cast



-- 
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-unsubscribe@arrow.apache.org

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