Repository navigation
GH-3970: Match the file's list and map structure when converting an Avro requested projection - #3971
shivadarshan-devadiga wants to merge 5 commits into
Conversation
…g an Avro requested projection
|
@wgtmac Could you please approve the workflows and take a look when you have a moment? Thanks! |
…ing with the file
|
For a legacy two-level LIST with |
|
Thanks @shihchengwei-lab, you were right. With The alignment now takes the schema the converters read with (the read schema, else the file's Avro schema) and keeps a list's converted projection when the converter would classify the aligned repeated field differently. |
|
Thanks for digging into this and adding the regression test! |
|
Gentle ping @wgtmac Can you please take a look? Thanks! |
…ey types, and check lists read without an Avro schema
|
@wgtmac Thank you for the detailed review. I have addressed your review comments and made changes accordingly. Can you please re-review? Thanks! |
…ema, and decide list elements structurally first
|
@wgtmac Thanks for the careful review. I've addressed all six in fa164a6. The main change is that without a read schema or an Avro schema in the file, the read now uses the requested projection, as All |
Rationale for this change
With an Avro requested projection,
AvroReadSupportconverts the projection to Parquet with a single list structure for the whole file:repeated <element> array, or the 3-levellist/elementnames when auto-detection (#3816) applies. Maps always getkey_value. A list or map that the file wrote with other repeated or element names is then missing from the projection's point of view, so it reads asnullwithout an error. That covers 2-level lists, single-field groups such asbagor older PyArrow'slist/item, standard lists in a file that also has one of those, and maps namedmap(MAP_KEY_VALUE).parquet-clialways reads with a projection, socat,head,to-avroandconvertprintnullfor these columns.What changes are included in this PR?
After converting the projection,
AvroReadSupport.initwalks it together with the file schema and the Avro projection:MAPorMAP_KEY_VALUE), it does the same with the file's key-value group.It decides whether a list's repeated field is the element the way
AvroCollectionConverterdoes when reading. It usesAvroRecordConverter.isElementType, with the Avro schema the converters read with, so the projection and the converters agree:array, or a repeated child make the repeated field the element.When the converted projection is kept, as before:
Without a read schema or an Avro schema in the file, the converters read with the requested projection, as
parquet-clidoes. Before, they read with an Avro schema converted from the projection.Only the names come from the file. Each element keeps its projected type, so the requested schema is still checked against the file. A type that doesn't match fails with
incompatible typesas before, and so does a map key that isn't a string. Each element's repetition is the one the converted projection gives it: repeated if the file's repeated field is the element, otherwise optional only if the Avro schema allows null. So files whose lists already match the converted projection get the same projection as before, and a non-null Avro element type still fails against optional elements in the file.Are these changes tested?
Yes. New tests in
TestArrayCompatibilityread with a requested projection, with the matching read schema unless noted.List and map shapes:
testProjectionReadsTwoLevelListOfPrimitives:repeated binary element.testProjectionReadsSingleFieldGroupsWithOtherNames:bag/xandlist/item, including a null element.testProjectionReadsMixedListStructures: a standard list and alist/itemlist in one file.testProjectionPrunesRecordsInNonStandardList: a record element with only one of its fields projected.testProjectionReadsMapWithOtherNames:map (MAP_KEY_VALUE).Nesting:
testProjectionReadsNestedNonStandardLists: alist/itemlist whose elements are 2-level lists.testProjectionReadsMapOfNonStandardLists: a map whose values arebaglists, including a null element.testProjectionReadsRepeatedListAsElementOfTwoLevelList: a repeated LIST as the element of a 2-level list, also with only a requested projection.testProjectionReadsDeeplyNestedTwoLevelLists: 26 nested lists, within a time bound, with and without a read schema.testProjectionReadsSingleFieldTupleAsElement:points_tuple { x }as the element of a list of records, with and without a read schema.Type checks still apply:
testProjectionStillChecksElementTypes: anint32list read with a string element type still fails withincompatible types.testProjectionKeepsNonNullElementsRequired: optionallist/itemelements read with a non-null element type still fail withincompatible types.testProjectionStillChecksMapKeyTypes: afixed_len_byte_arraymap key read with a string key still fails withincompatible types.Read schema and columns:
testProjectionOfTwoLevelRecordsFollowsTheReadSchema: a 2-level list of records with a field projected away, under three read schemas, including one that requires that field.testProjectionIgnoresUnselectedColumnsAvroCannotRepresent: projectingitems[].xnext to an unselected MAP withint32keys.Only a requested projection:
testProjectionWithoutAvroSchemaKeepsElementTypes: a 2-level list and alist/itemlist.testProjectionReadsListWrapperNamedLikeAnAvroType: a wrapper namedstring.Not a map:
testProjectionDoesNotReadListOfKeyValueRecordsAsMap: a two-level LIST of key-value records isn't read as a MAP.testProjectionStillChecksElementTypesguards a type check the base already enforces. The six tests added or tightened in this revision all fail on the previous revision.ReadCliTest.catReadsNonStandardListsWithoutAvroSchemachecksparquet catend to end, with and without--columns, for a 2-level list and alist/itemlist. Allparquet-avro(436, 2 skipped) andparquet-cli(93, 2 skipped) tests pass.Are there any user-facing changes?
Yes. Reading with an Avro requested projection now returns the values of lists and maps written with non-standard repeated or element names, instead of
null. This includesparquet-clion such files.Closes #3970