Repository navigation
fix(parquet): add early rejection of unsupported encodings - #11266
Conversation
etseidl
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Makes sense. Removed the additional call 🙇
| } | ||
|
|
||
| fn unsupported_column_encoding(encoding: Encoding, physical_type: Type) -> ParquetError { | ||
| if encoding == Encoding::ALP { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| create_and_check_encoder::<Int32Type>(0, Encoding::DELTA_LENGTH_BYTE_ARRAY, None); | ||
| create_and_check_encoder::<Int32Type>(0, Encoding::DELTA_BYTE_ARRAY, None); |
There was a problem hiding this comment.
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]>
50e19c0 to
8c903ca
Compare
Thanks @etseidl, good to be back!
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
left a comment
There was a problem hiding this comment.
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!
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?
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.