manojkarthick commented on a change in pull request #9306: URL: https://github.com/apache/arrow/pull/9306#discussion_r567264445
########## File path: rust/parquet/src/record/api.rs ########## @@ -635,6 +648,55 @@ impl Field { _ => nyi!(descr, value), } } + + #[cfg(feature = "json_output")] + pub fn to_json_value(&self) -> Value { + match &self { + Field::Null => Value::Null, + Field::Bool(b) => Value::Bool(*b), + Field::Byte(n) => Value::Number(serde_json::Number::from(*n)), + Field::Short(n) => Value::Number(serde_json::Number::from(*n)), + Field::Int(n) => Value::Number(serde_json::Number::from(*n)), + Field::Long(n) => Value::Number(serde_json::Number::from(*n)), + Field::UByte(n) => Value::Number(serde_json::Number::from(*n)), + Field::UShort(n) => Value::Number(serde_json::Number::from(*n)), + Field::UInt(n) => Value::Number(serde_json::Number::from(*n)), + Field::ULong(n) => Value::Number(serde_json::Number::from(*n)), + Field::Float(n) => serde_json::Number::from_f64(*n as f64) + .map(Value::Number) + .unwrap_or(Value::Null), + Field::Double(n) => serde_json::Number::from_f64(*n) + .map(Value::Number) + .unwrap_or(Value::Null), + Field::Decimal(n) => Value::String(convert_decimal_to_string(&n)), + Field::Str(s) => Value::String(s.to_owned()), + Field::Bytes(b) => Value::String(base64::encode(b.data())), + Field::Date(d) => Value::String(convert_date_to_string(*d)), + Field::TimestampMillis(ts) => { + Value::String(convert_timestamp_millis_to_string(*ts)) + } + Field::TimestampMicros(ts) => { + Value::String(convert_timestamp_micros_to_string(*ts)) + } + Field::Group(row) => row.to_json_value(), + Field::ListInternal(fields) => { + Value::Array(fields.elements.iter().map(|f| f.to_json_value()).collect()) + } + Field::MapInternal(map) => Value::Object( + map.entries + .iter() + .map(|(key_field, value_field)| { + let key_val = key_field.to_json_value(); + let key_str = key_val + .as_str() + .map(|s| s.to_owned()) + .unwrap_or_else(|| key_val.to_string()); + (key_str, value_field.to_json_value()) + }) + .collect(), + ), + } + } } Review comment: I've also updated the PR and added the test: [test_to_json_value](https://github.com/apache/arrow/pull/9306/files#diff-d6de2aa116b82bf7bfdf40fcbad13dc947139ce7a703990517662ae25eab0159R1676) ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org