Repository navigation
GH-3095: Follow the spec's LIST rules for the Avro schema parquet-cli derives - #3951
Open
shivadarshan-devadiga wants to merge 1 commit into
Open
shivadarshan-devadiga wants to merge 1 commit into
shivadarshan-devadiga wants to merge 1 commit into
Conversation
Author
|
@wgtmac Could you please approve the workflows and take a look when you have a moment? |
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
For a Parquet file without an Avro schema in its metadata, such as files written by Spark, PyArrow or DuckDB,
parquet-cliderives one withAvroSchemaConverter. That converter defaults toparquet.avro.add-list-element-records=true, which treats the single-field repeated group of a standard 3-level list as the element:So
tagsbecomes an array of recordslist { element }instead of an array of strings. The Parquet spec's backward-compatibility rules for LIST treat such a group as the element only when it is namedarrayor<list name>_tuple.On master this breaks every command that uses the derived schema for such files:
schemaprints the record wrapper.cat,head,to-avroandconvertfail withThe requested schema is not compatible with the file schema. incompatible types: required group element { optional binary element (STRING); } != optional binary element (STRING). In 1.15.0, as reported in parquet-cli reports nested columns as null #3095,catprintednullfor those columns instead.What changes are included in this PR?
Schemas.fromParquetderives the Avro schema withadd-list-element-records=falsewhen the file has no Avro schema, so the converter follows the spec's LIST rules. If the user setsparquet.avro.add-list-element-records, that setting is kept. Files with an Avro schema in their metadata still use it, as before.The open PR #3812 (GH-3672) would move
cat,headandscanto the native Parquet reader, which would also avoid this failure for those commands. This change is independent of it:schema,to-avroandconvertwould keep using the derived Avro schema either way.Scope: this fixes standard 3-level lists named
list/element, the shape the spec recommends and that current writers produce. For other list shapes,schemanow prints an array too, but reading with the derived schema as projection still returnsnullfor the list. These are 2-level lists (repeated binary element), single-field groups with other names (for examplebagor older PyArrow'slist/item), and files that mix a standard list with one of these. That happens when the derived schema is used as the read projection, which this PR doesn't change.list/itemand mixed files already returnednullbefore this change. I'll follow up on those separately.Are these changes tested?
Yes.
ReadCliTest.catReadsStandardListsWithoutAvroSchemawrites a 3-levellist<string>withExampleParquetWriter, so without an Avro schema, with a two-element list, an empty list, a null list and a list with a null element, and checks thecatoutput.SchemaCliTest.printsStandardListsWithoutAvroSchemaAsArrayschecks thatschemaprints the list as an array of nullable strings. Both fail without this change.SchemaCliTest.keepsExplicitAddListElementRecordsSettingchecks that-D parquet.avro.add-list-element-records=truestill gives the record wrapper. All otherparquet-clitests pass.I also checked a file written by PyArrow 26.0.1 with two
list<string>columns:cat,head,schema,to-avroandconvertnow give the values PyArrow reads.Are there any user-facing changes?
Yes. For Parquet files without an Avro schema,
parquet-clinow reads and prints standard 3-level lists as arrays of their elements.Closes #3095