You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/11/17 10:43:48 UTC

[GitHub] [arrow] vertexclique commented on a change in pull request #8686: ARROW-10297: [Rust] Change output of parquet-read binary to json

vertexclique commented on a change in pull request #8686:
URL: https://github.com/apache/arrow/pull/8686#discussion_r525055603



##########
File path: rust/parquet/src/record/api.rs
##########
@@ -624,6 +634,49 @@ impl Field {
             _ => nyi!(descr, value),
         }
     }
+
+    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(|n| Value::Number(n))
+                .unwrap_or(Value::Null),
+            Field::Double(n) => serde_json::Number::from_f64(*n)
+                .map(|n| Value::Number(n))
+                .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(String::from_utf8_lossy(b.data()).into()),

Review comment:
       These bytes need collection and formatting as their hex representations since this will replace unknown codepoints with Unicode not defined character.

##########
File path: rust/parquet/Cargo.toml
##########
@@ -41,6 +41,7 @@ chrono = "0.4"
 num-bigint = "0.3"
 arrow = { path = "../arrow", version = "3.0.0-SNAPSHOT", optional = true }
 base64 = { version = "*", optional = true }
+serde_json = { version = "1.0", features = ["preserve_order"] }

Review comment:
       Better to make this one optional and gated.




----------------------------------------------------------------
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:
users@infra.apache.org