Validate FIXED_LEN_BYTE_ARRAY length for DECIMAL and INTERVAL types#9985
Open
CynicDog wants to merge 1 commit into
Open
Validate FIXED_LEN_BYTE_ARRAY length for DECIMAL and INTERVAL types#9985CynicDog wants to merge 1 commit into
CynicDog wants to merge 1 commit into
Conversation
The Rust `PrimitiveTypeBuilder` rejects bad `type_length` at construction, but schemas decoded directly from Thrift bypass that path. Previously a malformed DECIMAL length silently produced the wrong Arrow type, and an INTERVAL of length != 12 was accepted unchecked. Validate `type_length` in `from_fixed_len_byte_array`, mirroring the existing FLOAT16 pattern: 1..=32 bytes for DECIMAL (Decimal128 below 16, Decimal256 up to 32), exactly 12 bytes for INTERVAL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
from_fixed_len_byte_arrayinparquet/src/arrow/schema/primitive.rsdoes not validatetype_length. WhilePrimitiveTypeBuilder::build()enforces these constraints during schema construction (schema/types.rs:477for INTERVAL,:565-580for DECIMAL), schemas decoded directly from Thrift bypass that validation path entirely. As a result:DECIMALwith atype_lengthoutside1..=32was silently routed throughDecimal128/Decimal256using invalid parameters.INTERVALwith atype_length != 12silently returnedInterval(DayTime)regardless.The same function already rejects
FLOAT16whentype_length != 2. This PR mirrors that pattern for DECIMAL and INTERVAL, closing the TODO introduced in #1682.What changes are included in this PR?
check_decimal_lengthhelper to rejecttype_lengthvalues outside1..=32for bothLogicalType::DecimalandConvertedType::DECIMAL.type_length == 12check forConvertedType::INTERVAL.Are these changes tested?
Yes. Added five new tests in
parquet/src/arrow/schema/primitive.rs::testscovering:{-1, 0, 33}for DECIMAL,{0, 11, 13}for INTERVAL)Decimal128, 32 →Decimal256, 12 →Interval(DayTime))To exercise the reader-side check, the tests construct a valid
Type::PrimitiveTypevia the builder and directly modify thetype_lengthon the resulting enum, simulating a malformed schema decoded from Thrift.Are there any user-facing changes?
No public API changes. The only behavior change is on the reader side: schemas with an out-of-range
type_lengthfor DECIMAL or INTERVAL will now return aParquetError::Generalinstead of silently producing a mismatched Arrow type.