You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "SteveLauC (via GitHub)" <gi...@apache.org> on 2023/04/26 11:32:42 UTC

[GitHub] [arrow-rs] SteveLauC opened a new pull request, #4138: Prioritize Int64 in infer_json_schema()

SteveLauC opened a new pull request, #4138:
URL: https://github.com/apache/arrow-rs/pull/4138

   # Which issue does this PR close?
   This is relevant to #4134 but does not close it.
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   # Rationale for this change
    See https://github.com/apache/arrow-rs/issues/4134#issuecomment-1523202970
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   In `infer_json_schema()`, `Int64` is prioritized.
   
   # Are there any user-facing changes?
   I guess not.
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4138: Infer Float64 for JSON Numerics Beyond Bounds of i64

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4138:
URL: https://github.com/apache/arrow-rs/pull/4138#discussion_r1177817529


##########
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)?;

Review Comment:
   Could we get a test of this, showing it inferring f64 for values exceeding `i64::MAX` and `i64::MIN`?



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #4138: Infer Float64 for JSON Numerics Beyond Bounds of i64

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4138:
URL: https://github.com/apache/arrow-rs/pull/4138


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] SteveLauC commented on a diff in pull request #4138: Infer Float64 for JSON Numerics Beyond Bounds of i64

Posted by "SteveLauC (via GitHub)" <gi...@apache.org>.
SteveLauC commented on code in PR #4138:
URL: https://github.com/apache/arrow-rs/pull/4138#discussion_r1177860304


##########
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)?;

Review Comment:
   Sure thing! Done:)



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4138: Infer Float64 for JSON Numerics Beyond Bounds of i64

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4138:
URL: https://github.com/apache/arrow-rs/pull/4138#discussion_r1177817529


##########
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)?;

Review Comment:
   Could we get a test of this, showing it inferring f64 for i64::MAX?



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] SteveLauC commented on a diff in pull request #4138: Infer Float64 for JSON Numerics Beyond Bounds of i64

Posted by "SteveLauC (via GitHub)" <gi...@apache.org>.
SteveLauC commented on code in PR #4138:
URL: https://github.com/apache/arrow-rs/pull/4138#discussion_r1177862981


##########
arrow-json/src/reader/schema.rs:
##########
@@ -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
+        );

Review Comment:
   [serde_json::json!](https://docs.rs/serde_json/latest/serde_json/macro.json.html) cannot be used here to construct this json as it will panic when encountering a number smaller than `i64::MIN`



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org