Skip to content

fix(parquet/pqarrow): unsupported dictionary types in pqarrow - #520

Merged
zeroshade merged 2 commits into
apache:mainfrom
zeroshade:pqarrow-dict-types
Oct 1, 2025
Merged

fix(parquet/pqarrow): unsupported dictionary types in pqarrow#520
zeroshade merged 2 commits into
apache:mainfrom
zeroshade:pqarrow-dict-types

Conversation

@zeroshade

Copy link
Copy Markdown
Member

Rationale for this change

fixes #490

What changes are included in this PR?

When using PutDictionary to write an arrow dictionary array to Parquet directly, we will now normalize the data type to a parquet physical storage type to avoid type problems. e.g. A dictionary with int8 values will get cast to int32 values before we process it so that all of the remaining encoding code can continue to be based on the physical storage type. This alleviates panics when using pqarrow to write Dictionary arrays.

Are these changes tested?

Yes, the unit tests are updated to include tests for int8/uint8/etc. as dictionary value types.

Are there any user-facing changes?

No, just fixing panics.

Comment thread parquet/internal/encoding/types.go Outdated
Comment on lines +120 to +122
// The returned array must be released by the caller if different from
// the input array. If no normalization is needed, the input array
// may be returned as-is.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's kind of annoying, right? You have to branch. Maybe it should always require releasing (normalize can call retain)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fair enough, i'll update to that.

@amoeba amoeba left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two tangential notes:

  • Would it be good to title PRs like this fix(pqarrow): ... so users can skim changelogs for parquet changes?
  • Does pqarrow smuggle Arrow schemas inside Parquet metadata so users can round-trip? This PR doesn't introduce any breakage of course but it strikes me that arrow -> parquet -> arrow won't round-trip well if the arrow input has to be cast like this.
Comment thread parquet/pqarrow/encode_arrow_test.go
@zeroshade zeroshade changed the title fix: unsupported dictionary types in pqarrow Sep 26, 2025
@zeroshade

Copy link
Copy Markdown
Member Author

Does pqarrow smuggle Arrow schemas inside Parquet metadata so users can round-trip?

If you set the StoreSchema option, then yes it does add the Arrow schema inside the parquet metadata.

This PR doesn't introduce any breakage of course but it strikes me that arrow -> parquet -> arrow won't round-trip well if the arrow input has to be cast like this.

This is the case no matter what type you pass (even if it's not dictionary encoded) because Parquet only has int32/int64 as physical storage types. In the case where the original Arrow schema is in the metadata, we properly cast on the way out so there isn't an issue.

@amoeba

amoeba commented Sep 26, 2025

Copy link
Copy Markdown
Member

Thanks for the answers to my questions.

@zeroshade
zeroshade merged commit fff99b3 into apache:main Oct 1, 2025
46 of 49 checks passed
@zeroshade
zeroshade deleted the pqarrow-dict-types branch March 27, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants