You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/27 13:34:17 UTC

[GitHub] [arrow-rs] yourenawo opened a new pull request, #3399: Add the option to skip the wrong json line

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

   # Which issue does this PR close?
   Closes #3392 
   


-- 
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 #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1398273008

   > some dirty data will be introduced
   
   Could you expand on this, do you mean data with a mismatching schema, or data that is not even valid JSON? This PR appears to be intending to handle the latter case and I'm confused about how this would arise?


-- 
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 #3399: Add the option to skip the wrong json line

Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1368495662

   Hmm... I'm not sure about this, what is the reason to prefer a callback over just yielding errors through the iterator trait?
   
   I.e. Iterator::next might return
   
   ```
   Some(Ok(batch1))
   Some(Ok(batch2))
   Some(Err(e))
   Some(Ok(batch3_skipping_error))
   Some(Ok(batch4))
   None
   ```


-- 
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 #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#discussion_r1067798452


##########
arrow-json/src/reader.rs:
##########
@@ -677,17 +689,29 @@ impl Decoder {
     ///
     /// Returns `None` if the input iterator is exhausted.
     pub fn next_batch<I>(
-        &self,
+        &mut self,
         value_iter: &mut I,
     ) -> Result<Option<RecordBatch>, ArrowError>
     where
         I: Iterator<Item = Result<Value, ArrowError>>,
     {
+        if let Some(ref s) = self.error_json {
+            let msg = s.clone();
+            self.error_json = None;
+            return Err(ArrowError::JsonError(msg));
+        }
         let batch_size = self.options.batch_size;
         let mut rows: Vec<Value> = Vec::with_capacity(batch_size);
 
         for value in value_iter.by_ref().take(batch_size) {
-            let v = value?;
+            let v = match value {
+                Ok(v) => v,
+                Err(ArrowError::JsonError(s)) => {

Review Comment:
   I think this also needs `if !values.is_empty()` to avoid returning an empty batch



-- 
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 closed pull request #3399: Make JSON Decoder Continue After Error

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold closed pull request #3399: Make JSON Decoder Continue After Error
URL: https://github.com/apache/arrow-rs/pull/3399


-- 
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] yourenawo commented on a diff in pull request #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
yourenawo commented on code in PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#discussion_r1068158112


##########
arrow-json/src/reader.rs:
##########
@@ -677,17 +689,29 @@ impl Decoder {
     ///
     /// Returns `None` if the input iterator is exhausted.
     pub fn next_batch<I>(
-        &self,
+        &mut self,
         value_iter: &mut I,
     ) -> Result<Option<RecordBatch>, ArrowError>
     where
         I: Iterator<Item = Result<Value, ArrowError>>,
     {
+        if let Some(ref s) = self.error_json {
+            let msg = s.clone();
+            self.error_json = None;
+            return Err(ArrowError::JsonError(msg));
+        }
         let batch_size = self.options.batch_size;
         let mut rows: Vec<Value> = Vec::with_capacity(batch_size);
 
         for value in value_iter.by_ref().take(batch_size) {
-            let v = value?;
+            let v = match value {
+                Ok(v) => v,
+                Err(ArrowError::JsonError(s)) => {

Review Comment:
   ok, next rows have this



-- 
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] yourenawo commented on pull request #3399: Add the option to skip the wrong json line

Posted by GitBox <gi...@apache.org>.
yourenawo commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1368515083

   ok, I think so, I added the parameter of recording error information to the decoder, so it needs to be mut


-- 
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 #3399: Make JSON Decoder Continue After Error

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

   I'm afraid this approach is incompatible with the new vectorised RawReader, so closing. Apologies once again for the back and forth


-- 
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 #3399: Add the option to skip the wrong json line

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#discussion_r1067425724


##########
arrow-json/src/reader.rs:
##########
@@ -677,17 +689,29 @@ impl Decoder {
     ///
     /// Returns `None` if the input iterator is exhausted.
     pub fn next_batch<I>(
-        &self,
+        &mut self,
         value_iter: &mut I,
     ) -> Result<Option<RecordBatch>, ArrowError>
     where
         I: Iterator<Item = Result<Value, ArrowError>>,
     {
+        if let Some(ref s) = self.error_json {
+            let msg = s.clone();
+            self.error_json = None;

Review Comment:
   ```suggestion
           if let Some(msg) = self.error_json.take() {
   ```
   



##########
arrow-json/src/reader.rs:
##########
@@ -677,17 +689,29 @@ impl Decoder {
     ///
     /// Returns `None` if the input iterator is exhausted.
     pub fn next_batch<I>(
-        &self,
+        &mut self,

Review Comment:
   This is a breaking change but I support it, it opens the door to making Decoder a regular iterator



##########
arrow-json/src/reader.rs:
##########
@@ -699,8 +723,15 @@ impl Decoder {
             }
         }
         if rows.is_empty() {
-            // reached end of file
-            return Ok(None);
+            match self.error_json {

Review Comment:
   Could use take here



##########
arrow-json/src/reader.rs:
##########
@@ -699,8 +723,15 @@ impl Decoder {
             }
         }
         if rows.is_empty() {
-            // reached end of file
-            return Ok(None);
+            match self.error_json {

Review Comment:
   Could use take here



##########
arrow-json/src/reader.rs:
##########
@@ -677,17 +689,29 @@ impl Decoder {
     ///
     /// Returns `None` if the input iterator is exhausted.
     pub fn next_batch<I>(
-        &self,
+        &mut self,
         value_iter: &mut I,
     ) -> Result<Option<RecordBatch>, ArrowError>
     where
         I: Iterator<Item = Result<Value, ArrowError>>,
     {
+        if let Some(ref s) = self.error_json {
+            let msg = s.clone();
+            self.error_json = None;
+            return Err(ArrowError::JsonError(msg));
+        }
         let batch_size = self.options.batch_size;
         let mut rows: Vec<Value> = Vec::with_capacity(batch_size);
 
         for value in value_iter.by_ref().take(batch_size) {
-            let v = value?;
+            let v = match value {
+                Ok(v) => v,
+                Err(ArrowError::JsonError(s)) => {

Review Comment:
   What do you think of handling all error variants the same way?



-- 
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] yourenawo commented on pull request #3399: Make JSON Decoder Continue After Error

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

   Invalid json data. When the program encounters an exception, a broken line json is written


-- 
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 #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1379931288

   What would you do if there are multiple errors
   
   > Returning previous error in next_batch seems not a good idea
   
   That isn't quite what this does, if there is an error it returns any records already processed without issue, and then returns the error


-- 
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] yourenawo commented on pull request #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
yourenawo commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1398267418

   
   Because the source of json data is external, some dirty data will be introduced


-- 
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 #3399: Add the option to skip the wrong json line

Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1368866053

   I plan to have a play around with this this afternoon


-- 
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] Goodjooy commented on pull request #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
Goodjooy commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1379701695

   I am not understanding what this PR's change.
   
   - if want handle as much as posiable row in a single batch (even though there might have one or many bad JSON record). returning the error messages togeter with the return value will better . like this : `Result<Option<(RecordBatch, Vec<ErrorSet>)>, ArrowError>` . Returning the error in last batch in `next_batch` is also make user confuse.
   
   
   If just do not want loss any rows. becouse the `Iterator` of rust is lazy, once an error occurred the remain rows of this batch is still in the orginal Iterator that can be take in next batch. for a better understanding ,I am writting a rust-playgound [here](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5f77d983ffa876d2beeff2fcaa21aada)
   


-- 
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] yourenawo commented on pull request #3399: Add the option to skip the wrong json line

Posted by GitBox <gi...@apache.org>.
yourenawo commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1368493048

   sure, I try to add a callback function to solve this problem.


-- 
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 #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1383276937

   Sorry for the delay with this, I'm currently reimplementing the JSON reader to not be row-based, and instead process batches at a time to drastically improve performance.
   
   Whilst initially this will be a separate opt-in RawDecoder the eventual goal would be to replace the current implementation. I'm therefore a bit apprehensive about this feature, as it will likely be impossible to port across...
   
   On a related note, such a behaviour is not possible for CSV for much the same reason.
   
   This leads me to the position of not really knowing how best to proceed... Could you perhaps expand a bit on the use-case for this? Perhaps we could parse errors as nulls or something instead?
   
   Sorry to contradict my earlier statements, but I'm wary of painting ourselves into a corner here


-- 
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] Goodjooy commented on pull request #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
Goodjooy commented on PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#issuecomment-1379762923

   I think the error is returning with the return value is better.
   The return type of the function signal can like : `Result<Option<(RecordBatch, Option<ArrowError>)>, ArrowError>` .
   Returning previous error in `next_batch`  seems not a good idea


-- 
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] yourenawo commented on a diff in pull request #3399: Make JSON Decoder Continue After Error

Posted by GitBox <gi...@apache.org>.
yourenawo commented on code in PR #3399:
URL: https://github.com/apache/arrow-rs/pull/3399#discussion_r1068158836


##########
arrow-json/src/reader.rs:
##########
@@ -677,17 +689,29 @@ impl Decoder {
     ///
     /// Returns `None` if the input iterator is exhausted.
     pub fn next_batch<I>(
-        &self,
+        &mut self,
         value_iter: &mut I,
     ) -> Result<Option<RecordBatch>, ArrowError>
     where
         I: Iterator<Item = Result<Value, ArrowError>>,
     {
+        if let Some(ref s) = self.error_json {
+            let msg = s.clone();
+            self.error_json = None;
+            return Err(ArrowError::JsonError(msg));
+        }
         let batch_size = self.options.batch_size;
         let mut rows: Vec<Value> = Vec::with_capacity(batch_size);
 
         for value in value_iter.by_ref().take(batch_size) {
-            let v = value?;
+            let v = match value {
+                Ok(v) => v,
+                Err(ArrowError::JsonError(s)) => {

Review Comment:
   I think best use enum.



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