Skip to content

MINOR: Read Avro maps with omitted values - #3986

Open
vera-rubin wants to merge 1 commit into
apache:masterfrom
vera-rubin:fix/avro-map-without-values
Open

vera-rubin wants to merge 1 commit into
apache:masterfrom
vera-rubin:fix/avro-map-without-values

Conversation

@vera-rubin

Copy link
Copy Markdown

Rationale for this change

The Parquet MAP rules allow the value field of the repeated key_value group to be omitted, but parquet-avro cannot read such a file. AvroReadSupport derives the Avro schema with AvroSchemaConverter, which requires exactly two fields in key_value and throws:

java.lang.UnsupportedOperationException: Invalid map type required group m (MAP) {
  repeated group key_value {
    required binary key (STRING);
  }
}

for this schema:

message map_test {
  required group m (MAP) {
    repeated group key_value {
      required binary key (STRING);
    }
  }
}

What changes are included in this PR?

  • AvroSchemaConverter accepts a key_value group with only the key field and converts it to an Avro map whose values are null.
  • AvroRecordConverter and AvroIndexedRecordConverter do not create a value converter when there is no value field, so each key is read with a null value.

Maps with a value field are converted as before.

Are these changes tested?

Yes. TestReadWrite.testMapWithoutValue writes a required and an optional map without a value field (with ExampleParquetWriter), including an empty map and, for the optional map, a null map, and reads them back with the Avro reader for every converter and configuration in data(). It checks the derived value schema (null) and the record values. It fails without the fix (Invalid map type, 13 of 13 parameter sets) and passes with it. mvn -pl parquet-avro test passes (431 tests, 2 skipped as before) and mvn -pl parquet-avro spotless:check is clean.

Are there any user-facing changes?

Files whose maps have no value field can now be read with parquet-avro; each key maps to null.

@Fokko
Fokko self-requested a review November 25, 2026 15:13

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vera-rubin, clean fix for the omitted map values. LGTM! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants