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

[GitHub] [arrow-rs] tustvold opened a new pull request, #4079: Improve JSON decoder errors (#4076)

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

   # Which issue does this PR close?
   
   <!--
   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.
   -->
   
   Closes #4076
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   This improves the error messages when decoding the tape, these are produced when the JSON input is valid but doesn't match the expected schema. Producing a more helpful error message is therefore useful for identifying what has gone wrong.
   
   Unfortunately at this level rows don't really exist, but at the very least we can provide more context than a single byte :sweat_smile: 
   
   # 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.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   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 #4079: Improve JSON decoder errors (#4076)

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


##########
arrow-json/src/reader/tape.rs:
##########
@@ -125,14 +108,62 @@ impl<'a> Tape<'a> {
             | TapeElement::Null => Ok(cur_idx + 1),
             TapeElement::StartList(end_idx) => Ok(end_idx + 1),
             TapeElement::StartObject(end_idx) => Ok(end_idx + 1),
-            d => Err(d),
+            _ => Err(self.error(cur_idx, expected)),
         }
     }
 
     /// Returns the number of rows
     pub fn num_rows(&self) -> usize {
         self.num_rows
     }
+
+    /// Serialize the tape element at index `idx` to `out` returning the next field index

Review Comment:
   It is worth noting that this necessarily cannot preserve whitespace, but it at least preserves structure



-- 
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] viirya commented on a diff in pull request #4079: Improve JSON decoder errors (#4076)

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


##########
arrow-json/src/reader/mod.rs:
##########
@@ -1866,4 +1862,95 @@ mod tests {
         assert_eq!(3, num_batches);
         assert_eq!(100000000000011, sum_a);
     }
+
+    #[test]
+    fn test_decoder_error() {
+        let schema = Arc::new(Schema::new(vec![Field::new_struct(
+            "a",
+            vec![Field::new("child", DataType::Int32, false)],
+            true,
+        )]));
+
+        let parse_err = |s: &str| {
+            ReaderBuilder::new(schema.clone())
+                .build(Cursor::new(s.as_bytes()))
+                .unwrap()
+                .next()
+                .unwrap()
+                .unwrap_err()
+                .to_string()
+        };
+
+        let err = parse_err(r#"{"a": 123}"#);
+        assert_eq!(
+            err,
+            "Json error: whilst decoding field 'a': expected { got 123"

Review Comment:
   👍 



-- 
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 pull request #4079: Improve JSON decoder errors (#4076)

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

   This does not appear to materially impact the performance benchmarks


-- 
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] viirya commented on a diff in pull request #4079: Improve JSON decoder errors (#4076)

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


##########
arrow-json/src/reader/tape.rs:
##########
@@ -116,7 +99,7 @@ impl<'a> Tape<'a> {
     ///
     /// Return an error containing the [`TapeElement`] at `cur_idx` if it
     /// is not the start of a field

Review Comment:
   ```suggestion
       /// Return an error containing at `cur_idx` if it
       /// is not the start of a field
   ```



-- 
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 #4079: Improve JSON decoder errors (#4076)

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


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