Skip to content

fix(parquet): add early rejection of unsupported encodings - #11266

Merged
etseidl merged 1 commit into
apache:mainfrom
HippoBaro:reject_early
Sep 29, 2026
Merged

etseidl merged 1 commit into
apache:mainfrom
HippoBaro:reject_early

Conversation

@HippoBaro

@HippoBaro HippoBaro commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The writer accepts some encoding and physical-type combinations that no encoder can represent correctly. Invalid configurations can therefore fail only when values are written, when a dictionary falls back, or when a reader encounters the output.

What changes are included in this PR?

  • Define the supported value-encoding matrix explicitly.
  • Validate encoding and physical-type combinations at encoder construction, including the Arrow byte-array fallback path.
  • Reject invalid dictionary fallback configurations even when the fallback would never be used.
  • Add a construction-time validation matrix covering physical types, writer versions, and dictionary settings, and update existing error expectations.

Supported encodings and their wire representations are unchanged.

Are these changes tested?

Yes. The tests cover the supported encoding matrix at column construction, with dictionary encoding both enabled and disabled and with both Parquet writer versions. The Arrow writer regression now expects the invalid DOUBLE/DELTA_BINARY_PACKED configuration to fail earlier.

Are there any user-facing changes?

Yes. Unsupported encoding configurations are rejected when the physical column encoder is constructed, before values reach that encoder. Invalid dictionary fallbacks are rejected even if the column would remain dictionary-encoded.

This deliberately changes failure timing and error messages for invalid configurations. It does not change supported encodings, valid output, or public API signatures.

@etseidl etseidl 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 @HippoBaro, long time no see 👋.

Maybe I'm missing something, but I think rather than adding the new validation function (which to me seems like a maintenance headache), why don't we just add type checking to get_encoder implementations?

WriterVersion::PARQUET_2_0 => Encoding::DELTA_BYTE_ARRAY,
});

crate::encodings::encoding::validate_column_encoding(

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.

calling this is duplicating the default arm of the following match. Other than standardizing messages I don't know that this is strictly necessary. And it means if we add a new byte array encoding, we have to modify this check in two places.

If we keep it anyway, let's no fully qualify it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Removed the additional call 🙇

Comment thread parquet/src/encodings/encoding/mod.rs Outdated
}

fn unsupported_column_encoding(encoding: Encoding, physical_type: Type) -> ParquetError {
if encoding == Encoding::ALP {

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.

why is ALP the only special case here. for instance, BIT_PACKED is not supported at all, but now the error message will be it isn't supported for type X, which sort of implies it is supported for some other type.

Since this is only called right before entering a match on encoding, why don't we just shore up the type checking in those matches, so there's a single place where this stuff is encoded/enforced.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ugh. Apologies for the ALP thing, ALP was merged recently, and this code dates from before, and I may have used an agent to rebase since... :shame-nun:

I’ve removed that validation layer and added the missing type checks directly to the encoding-selection matches. BIT_PACKED again reports: Encoding BIT_PACKED is not supported, without suggesting that another physical type would work. Dictionary encodings also retain: Cannot initialize this encoding through this function.

Comment on lines -852 to -853
create_and_check_encoder::<Int32Type>(0, Encoding::DELTA_LENGTH_BYTE_ARRAY, None);
create_and_check_encoder::<Int32Type>(0, Encoding::DELTA_BYTE_ARRAY, None);

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.

I see your point though...why did this ever pass?

The writer accepts encoding and physical-type combinations that no
encoder can represent correctly. Those invalid configurations can
therefore fail only later, while writing values, when a dictionary falls
back, or even when a reader encounters the output; dictionary encoding
can also hide the problem entirely when its invalid fallback is never
exercised.

Define the supported value-encoding matrix explicitly and validate it at
encoder construction, including the Arrow byte-array fallback path. This
deliberately moves failure to the physical column construction boundary,
before any values reach the affected encoder, and rejects invalid
dictionary fallbacks even when they would never be used. Supported
encodings and their wire representations remain unchanged.

Signed-off-by: Hippolyte Barraud <[email protected]>
@HippoBaro

Copy link
Copy Markdown
Contributor Author

Thanks @HippoBaro, long time no see 👋.

Thanks @etseidl, good to be back!

Maybe I'm missing something, but I think rather than adding the new validation function (which to me seems like a maintenance headache), why don't we just add type checking to get_encoder implementations?

Agreed. I’ve removed the separate validator and moved the physical-type checks into the existing encoder factory matches. I’ve also strengthened the tests to check factory errors directly, alongside the column-construction matrix covering both writer versions and dictionary settings.

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

Cool beans, thanks! I was starting to suggest conditionals in the match arms to cut down on repetition, but then that wound up with more lines and wasn't any more readable. Plus it added a catch-all which would have made this hard to find and update when adding new encodings. I think this is good to go now. Thanks again!

@etseidl
etseidl merged commit a297bdb into apache:main Sep 29, 2026
29 checks passed
@alamb alamb added the bug Squash those bugs label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet: unsupported encoding/type combinations are accepted until writing begins

3 participants