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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]