You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2023/04/26 18:50:17 UTC
[arrow-rs] branch master updated: Infer Float64 for JSON Numerics Beyond Bounds of i64 (#4138)
This is an automated email from the ASF dual-hosted git repository.
tustvold 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 83f784da5 Infer Float64 for JSON Numerics Beyond Bounds of i64 (#4138)
83f784da5 is described below
commit 83f784da567807d238d810e14d6ee3e646d99577
Author: SteveLauC <st...@outlook.com>
AuthorDate: Thu Apr 27 02:50:10 2023 +0800
Infer Float64 for JSON Numerics Beyond Bounds of i64 (#4138)
* Prioritize Int64 in infer_json_schema()
* add test
---
arrow-json/src/reader/schema.rs | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/arrow-json/src/reader/schema.rs b/arrow-json/src/reader/schema.rs
index 427c20e02..c8250ac37 100644
--- a/arrow-json/src/reader/schema.rs
+++ b/arrow-json/src/reader/schema.rs
@@ -442,11 +442,10 @@ fn collect_field_types_from_object(
// inferring
}
Value::Number(n) => {
- if n.is_f64() {
- set_object_scalar_field_type(field_types, k, DataType::Float64)?;
- } else {
- // default to i64
+ if n.is_i64() {
set_object_scalar_field_type(field_types, k, DataType::Int64)?;
+ } else {
+ set_object_scalar_field_type(field_types, k, DataType::Float64)?;
}
}
Value::String(_) => {
@@ -663,6 +662,24 @@ mod tests {
assert_eq!(inferred_schema, schema);
}
+ #[test]
+ fn test_infer_json_schema_bigger_than_i64_max() {
+ let bigger_than_i64_max = (i64::MAX as i128) + 1;
+ let smaller_than_i64_min = (i64::MIN as i128) - 1;
+ let json = format!(
+ "{{ \"bigger_than_i64_max\": {}, \"smaller_than_i64_min\": {} }}",
+ bigger_than_i64_max, smaller_than_i64_min
+ );
+ let mut buf_reader = BufReader::new(json.as_bytes());
+ let inferred_schema = infer_json_schema(&mut buf_reader, Some(1)).unwrap();
+ let fields = inferred_schema.fields();
+
+ let (_, big_field) = fields.find("bigger_than_i64_max").unwrap();
+ assert_eq!(big_field.data_type(), &DataType::Float64);
+ let (_, small_field) = fields.find("smaller_than_i64_min").unwrap();
+ assert_eq!(small_field.data_type(), &DataType::Float64);
+ }
+
#[test]
fn test_coercion_scalar_and_list() {
use arrow_schema::DataType::*;