Skip to content

[avro] Fix ClassCastException when writing MULTISET with non-string element type - #9066

Merged
JingsongLi merged 1 commit into
apache:masterfrom
thswlsqls:fix/avro-multiset-non-string-element
Aug 6, 2026
Merged

[avro] Fix ClassCastException when writing MULTISET with non-string element type#9066
JingsongLi merged 1 commit into
apache:masterfrom
thswlsqls:fix/avro-multiset-non-string-element

Conversation

@thswlsqls

Copy link
Copy Markdown
Contributor

Purpose

fix #9064

  • AvroSchemaConverter handles MULTISET and MAP in one branch, so a non-string element gets the array-of-record encoding.
  • AvroSchemaVisitor.visit() recognized only MapType in its ARRAY branch and cast everything else to the final class ArrayType, so any MULTISET with a non-string element threw ClassCastException on write and read, even though validateDataFields passed. ORC and Parquet already accept that schema.
  • Reuse the converter's extractKeyTypeToAvroMap/extractValueTypeToAvroMap there, keeping schema creation and visiting on one source. The converter is untouched, so the written encoding is unchanged.
  • Correct the avro MAP/MULTISET rows in fileformat.md: the MAP row says the key must be a string type, but FormatReadWriteTest's nonStrKeyMap = MAP(INT, ...) already passes on avro.

Tests

  • Added AvroFormatReadWriteTest#testMultisetWithNonStringElement (round trip; throws without the fix) and #testMultisetWithStringElement (regression guard).
  • mvn -pl paimon-format -DfailIfNoTests=false clean install — 531 tests passed, 0 failures. No existing test used MULTISET.

…lement type

AvroSchemaConverter routes MULTISET and MAP through the same branch, so a
multiset with a non-string element is encoded as an array of key-value
records. AvroSchemaVisitor only recognized MapType there and cast every
other type to the final class ArrayType, so any MultisetType failed.

Handle MultisetType in the ARRAY branch by reusing the converter's own
extractKeyTypeToAvroMap/extractValueTypeToAvroMap, keeping schema creation
and schema visiting on one source. Also correct the Avro type mapping table
for MAP and MULTISET in fileformat.md.

Generated-by: Claude Code
@JingsongLi

Copy link
Copy Markdown
Contributor

+1

@JingsongLi
JingsongLi merged commit 90bb27c into apache:master Aug 6, 2026
13 checks passed
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.

[Bug] Avro throws ClassCastException when writing MULTISET with a non-string element type

2 participants