Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for ignoring (or optionally returning, as strings) JSON records that do not conform to the arrow schema.
The most obvious approach would be to do in a single pass: as we encounter a field that doesn't conform to the schema, we would then skip deserializing and move to the next row. However, this does not appear to be possible. Arrow-json decodes json in Arrays by column instead of row. That means that if we detect a problem in the second field, we have already built up the entire array for the first field.
Instead, we take a two-pass approach. First, we validate each row (via a new validate_row method on each array decoder) and determine which ones will be deserializable. Then, we deserialize only those rows (if the
allow_bad_data
option is set to true on the Decoder).There is also a new
flush_with_bad_data
method on the Decoder which will partition the good and bad rows, deserialize the good rows into the RecordBatch, and return the bad rows as strings so that they can be handled alternately. It also returns a mask that tells us which of the original rowset was valid, which is helpful for excluding rows in companion arrays (like our timestamp array).