alamb commented on a change in pull request #9306:
URL: https://github.com/apache/arrow/pull/9306#discussion_r567413050
##########
File path: rust/parquet/src/record/api.rs
##########
@@ -1608,6 +1670,117 @@ mod tests {
);
}
}
+
+ #[test]
+ #[cfg(feature = "cli")]
+ fn test_to_json_value() {
+ assert_eq!(Field::Null.to_json_value(), Value::Null);
+ assert_eq!(Field::Bool(true).to_json_value(), Value::Bool(true));
+ assert_eq!(Field::Bool(false).to_json_value(), Value::Bool(false));
+ assert_eq!(
+ Field::Byte(1).to_json_value(),
+ Value::Number(serde_json::Number::from(1))
+ );
+ assert_eq!(
+ Field::Short(2).to_json_value(),
+ Value::Number(serde_json::Number::from(2))
+ );
+ assert_eq!(
+ Field::Int(3).to_json_value(),
+ Value::Number(serde_json::Number::from(3))
+ );
+ assert_eq!(
+ Field::Long(4).to_json_value(),
+ Value::Number(serde_json::Number::from(4))
+ );
+ assert_eq!(
+ Field::UByte(1).to_json_value(),
+ Value::Number(serde_json::Number::from(1))
+ );
+ assert_eq!(
+ Field::UShort(2).to_json_value(),
+ Value::Number(serde_json::Number::from(2))
+ );
+ assert_eq!(
+ Field::UInt(3).to_json_value(),
+ Value::Number(serde_json::Number::from(3))
+ );
+ assert_eq!(
+ Field::ULong(4).to_json_value(),
+ Value::Number(serde_json::Number::from(4))
+ );
+ assert_eq!(
+ Field::Float(5.0).to_json_value(),
+ Value::Number(serde_json::Number::from_f64(f64::from(5.0 as
f32)).unwrap())
+ );
+ assert_eq!(
+ Field::Float(5.1234).to_json_value(),
+ Value::Number(
+ serde_json::Number::from_f64(f64::from(5.1234 as f32)).unwrap()
+ )
+ );
+ assert_eq!(
+ Field::Double(6.0).to_json_value(),
+ Value::Number(serde_json::Number::from_f64(6.0 as f64).unwrap())
+ );
+ assert_eq!(
+ Field::Double(6.1234).to_json_value(),
+ Value::Number(serde_json::Number::from_f64(6.1234 as f64).unwrap())
+ );
+ assert_eq!(
+ Field::Str("abc".to_string()).to_json_value(),
+ Value::String(String::from("abc"))
+ );
+ assert_eq!(
+ Field::Decimal(Decimal::from_i32(4, 8, 2)).to_json_value(),
+ Value::String(String::from("0.04"))
+ );
+ assert_eq!(
+ Field::Bytes(ByteArray::from(vec![1, 2, 3])).to_json_value(),
+ Value::String(String::from("AQID"))
+ );
+ assert_eq!(
Review comment:
When I ran the new test, it failed for me (probably because my timezone
is different). Maybe we should print out UTF timestamps for consistency?
```
cargo test --features=cli -- test_to_json_value
cargo test --features=cli -- test_to_json_value
Finished test [unoptimized + debuginfo] target(s) in 0.10s
Running
/Users/alamb/Software/arrow2/rust/target/debug/deps/parquet-113eb074b13ea986
running 1 test
test record::api::tests::test_to_json_value ... FAILED
failures:
---- record::api::tests::test_to_json_value stdout ----
thread 'record::api::tests::test_to_json_value' panicked at 'assertion
failed: `(left == right)`
left: `String("1969-12-31 19:00:12 -05:00")`,
right: `String("1969-12-31 16:00:12 -08:00")`',
parquet/src/record/api.rs:1742:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
record::api::tests::test_to_json_value
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 429 filtered
out
error: test failed, to rerun pass '--lib'
alamb@ip-10-0-0-49 parquet %
```
----------------------------------------------------------------
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:
[email protected]