(parquet-avro) Automatically detect list encodings in AvroReadSupport - #3753
Draft
clairemcginty wants to merge 1 commit into
Draft
(parquet-avro) Automatically detect list encodings in AvroReadSupport#3753clairemcginty wants to merge 1 commit into
clairemcginty wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rationale for this change
parquet-avro supports writing both "old" and "new" list encodings via the parquet.avro.write-old-list-structure config. "old" encodings (aka "2-level"), which wrap the list in a
repeated group arrayschema, are the default; "new" encodings (aka "3-level") are opt-in.On the reader side, if you're using
ParquetAvroReaderto read data that was written usingParquetAvroWriter, and don't specify a projection, both type sof list encoding get parsed automatically from a combination of the file schema + theparquet.avro.schemametadata key. There's no need to setparquet.avro.write-old-list-structurekey in your Configuration.However, if you're either:
AvroReadSupport.setRequestedProjection(...)), orparquet.avro.schemametadata key),3-levle list encodings will not be parsed correctly - the reader will inject an extra nested record, named
element, into the list item type.As a reader this introduces some pain, since you have to look up the underlying file metadata of the upstream Parquet file, and risk reading incorrect data. This PR attempts to automatically detect new list encodings based on the writer file schema.
lmk what you think of this change. Automatic inference is always a bit risky, but I tried to be conservative with the approach (only set the list structure property if all list fields in the schema use 3-level encoding; don't override
parquet.avro.write-old-list-structureif the user is already setting it). any ideas for a better approach here are welcome - this is becoming more of a pain point as 3-level lists become a more popular option among other writer sdks.What changes are included in this PR?
A new read configuration property
parquet.avro.read.autoDetectListStructure(defaulting to true) that will instruct AvroReadSupport to automatically set List configuration properties based on parsing the writer file schema.Are these changes tested?
Yes, unit tests + locally on real data.
Are there any user-facing changes?
Yes, since the new property defaults to
true- it would impact anyone who's reading 3-level list data without setting theparquet.avro.write-old-list-structurekey and who's relying on/working around the incorrectly formatted data (e.g.{"locations": [{"element": {"latitude": 0.0, "longitude": 180.0}}, ...]}instead of{"locations": [{"latitude": 0.0, "longitude": 180.0}, ...]}.additionally, this change also modifies the underlying Configuration object to add the properties.