Skip to content

fix(parquet/pqarrow): decoding Parquet with Arrow dict in schema - #551

Merged
zeroshade merged 5 commits into
apache:mainfrom
freakyzoidberg:fix/dictionary-multiple-pages-bug
Oct 28, 2025
Merged

fix(parquet/pqarrow): decoding Parquet with Arrow dict in schema#551
zeroshade merged 5 commits into
apache:mainfrom
freakyzoidberg:fix/dictionary-multiple-pages-bug

Conversation

@freakyzoidberg

@freakyzoidberg freakyzoidberg commented Oct 27, 2025

Copy link
Copy Markdown
Member

Fix spurious parquet: column chunk cannot have more than one dictionary. with specific parquet file
Resolve #546

Parquet with

  • Arrow Dict column
  • Arrow Schema serialied in Parquet Metadata
  • ColumnChunks with 1 dict page + at least 2 Data page

Bug

When maybeWriteNewDictionary() resets newDictionary = false at line 965, it causes the next call to readDictionary() to try to read the dictionary page again from the pager, which then calls configureDict() again, which throws the "cannot have more than one dictionary" error!

The sequence is:

  1. Read DICTIONARY_PAGE → newDictionary = true
  2. Read DATA_PAGE_1 → calls maybeWriteNewDictionary() → resets newDictionary = false
  3. Read DATA_PAGE_2 → calls readDictionary() → since newDictionary = false, tries to get dictionary page again → calls configureDict() → ERROR because decoder already exists

Fix

Added DictionaryState enum (column_reader.go):

  • DictNotRead: Dictionary page hasn't been read yet
  • DictReadNotInserted: Dictionary page read and decoder configured, but not inserted into Arrow builder
  • DictFullyProcessed: Dictionary fully processed (read + inserted into builder)
@freakyzoidberg freakyzoidberg changed the title Fix decoding of parquet with Arrow dict in schema Oct 27, 2025
@ahmed-mez

Copy link
Copy Markdown
Contributor

Thanks for the fix and reproducer @freakyzoidberg !

I confirm that running your branch on the file I mentioned in #546 now doesn't return the parquet: column chunk cannot have more than one dictionary. error any more.

@zeroshade zeroshade changed the title Fix decoding Parquet with Arrow dict in schema Oct 28, 2025

@zeroshade zeroshade 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.

Only one critique, everything else looks great! 😄 Thanks!

Comment thread parquet/file/column_reader.go Outdated
Comment on lines +41 to +52
// DictionaryState tracks the lifecycle of dictionary handling for a column chunk
type DictionaryState int

const (
// DictNotRead: Dictionary page has not been read yet
DictNotRead DictionaryState = iota
// DictReadNotInserted: Dictionary page has been read and decoder configured,
// but not yet inserted into Arrow builder (for Arrow Dictionary types only)
DictReadNotInserted
// DictFullyProcessed: Dictionary has been read, configured, and inserted into builder
DictFullyProcessed
)

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.

my only critique is that we shouldn't export these.

@zeroshade
zeroshade merged commit 9b9fdd0 into apache:main Oct 28, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants