This is an automated email from the ASF dual-hosted git repository.
nevime pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new b075c3c Fix data corruption in json decoder f64-to-i64 cast (#652)
b075c3c is described below
commit b075c3cef6d48e1e5ffce7e5c555d9c740885fae
Author: Christian Williams <[email protected]>
AuthorDate: Mon Aug 2 13:29:09 2021 -0400
Fix data corruption in json decoder f64-to-i64 cast (#652)
* Add failing test for JSON writer i64 bug
* Add special handling for i64/u64 to json decoder array builder
* Fix linter error - linter wants .flatten on a new line
---
arrow/src/json/reader.rs | 13 +++++++++++--
arrow/test/data/arrays.json | 2 +-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arrow/src/json/reader.rs b/arrow/src/json/reader.rs
index c4e8470..4912c5e 100644
--- a/arrow/src/json/reader.rs
+++ b/arrow/src/json/reader.rs
@@ -927,8 +927,16 @@ impl Decoder {
rows.iter()
.map(|row| {
row.get(&col_name)
- .and_then(|value| value.as_f64())
- .and_then(num::cast::cast)
+ .and_then(|value| {
+ if value.is_i64() {
+ value.as_i64().map(num::cast::cast)
+ } else if value.is_u64() {
+ value.as_u64().map(num::cast::cast)
+ } else {
+ value.as_f64().map(num::cast::cast)
+ }
+ })
+ .flatten()
})
.collect::<PrimitiveArray<T>>(),
))
@@ -1933,6 +1941,7 @@ mod tests {
.unwrap();
assert_eq!(1, aa.value(0));
assert_eq!(-10, aa.value(1));
+ assert_eq!(1627668684594000000, aa.value(2));
let bb = batch
.column(b.0)
.as_any()
diff --git a/arrow/test/data/arrays.json b/arrow/test/data/arrays.json
index 5dbdd19..6de2b03 100644
--- a/arrow/test/data/arrays.json
+++ b/arrow/test/data/arrays.json
@@ -1,3 +1,3 @@
{"a":1, "b":[2.0, 1.3, -6.1], "c":[false, true], "d":"4"}
{"a":-10, "b":[2.0, 1.3, -6.1], "c":[true, true], "d":"4"}
-{"a":2, "b":[2.0, null, -6.1], "c":[false, null], "d":"text"}
+{"a":1627668684594000000, "b":[2.0, null, -6.1], "c":[false, null], "d":"text"}