From 405683aa2b30e112c9851b7588b03d0a9d3421a8 Mon Sep 17 00:00:00 2001 From: xianwill Date: Mon, 2 Aug 2021 11:36:00 -0400 Subject: [PATCH 1/3] Add failing test for JSON writer i64 bug --- arrow/src/json/reader.rs | 1 + arrow/test/data/arrays.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arrow/src/json/reader.rs b/arrow/src/json/reader.rs index c4e847082c2b..8963dee2d318 100644 --- a/arrow/src/json/reader.rs +++ b/arrow/src/json/reader.rs @@ -1933,6 +1933,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 5dbdd19ffc00..6de2b0324e07 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"} From d838cb7c4ed97481998362cb1a15f85f64f01471 Mon Sep 17 00:00:00 2001 From: xianwill Date: Mon, 2 Aug 2021 11:56:51 -0400 Subject: [PATCH 2/3] Add special handling for i64/u64 to json decoder array builder --- arrow/src/json/reader.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arrow/src/json/reader.rs b/arrow/src/json/reader.rs index 8963dee2d318..67f717f4a8f4 100644 --- a/arrow/src/json/reader.rs +++ b/arrow/src/json/reader.rs @@ -927,8 +927,15 @@ 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::>(), )) From d916826ecf374428527051b967bada4d632868b0 Mon Sep 17 00:00:00 2001 From: xianwill Date: Mon, 2 Aug 2021 13:04:03 -0400 Subject: [PATCH 3/3] Fix linter error - linter wants .flatten on a new line --- arrow/src/json/reader.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arrow/src/json/reader.rs b/arrow/src/json/reader.rs index 67f717f4a8f4..4912c5e4d487 100644 --- a/arrow/src/json/reader.rs +++ b/arrow/src/json/reader.rs @@ -935,7 +935,8 @@ impl Decoder { } else { value.as_f64().map(num::cast::cast) } - }).flatten() + }) + .flatten() }) .collect::>(), ))