Skip to content

Commit

Permalink
Fix data corruption in json decoder f64-to-i64 cast (#652) (#665)
Browse files Browse the repository at this point in the history
* 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

Co-authored-by: Christian Williams <[email protected]>
  • Loading branch information
alamb and xianwill authored Aug 6, 2021
1 parent 64c78b8 commit 51f2b2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions arrow/src/json/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,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>>(),
))
Expand Down Expand Up @@ -1831,6 +1839,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()
Expand Down
2 changes: 1 addition & 1 deletion arrow/test/data/arrays.json
Original file line number Diff line number Diff line change
@@ -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"}

0 comments on commit 51f2b2b

Please sign in to comment.