fix(arrow): validate precision in NewDecimalType - #1162
Conversation
7cbb6c5 to
8ac32a0
Compare
8ac32a0 to
badba8a
Compare
zeroshade
left a comment
There was a problem hiding this comment.
The core precision bounds are correct, but the newly reachable error is discarded by the Avro schema conversion caller. Invalid Avro decimal precision therefore degrades into a generic nil-datatype error instead of preserving arrow.ErrInvalid. Local Arrow and Avro tests otherwise pass.
This review was drafted by an AI-assisted tool and confirmed by an Apache Arrow Go maintainer. After you've addressed the point above and pushed an update, an Apache Arrow Go maintainer — a real person — will take the next look at the PR. If you think the finding is misapplied, please reply on the PR and a maintainer will weigh in.
More on how Apache Arrow Go handles maintainer review:
CONTRIBUTING.md.
| } | ||
|
|
||
| if prec <= 0 || prec > maxPrecision { | ||
| return nil, fmt.Errorf("%w: precision for %s must be between 1 and %d, got %d", |
There was a problem hiding this comment.
Blocking: This new error path makes the existing caller in arrow/avro/schema.go:475 unsafe: it does dt, _ = arrow.NewDecimalType(...). For an Avro decimal with precision 77, the actual ErrInvalid is discarded, dt becomes nil, and schema construction later returns only invalid avro schema: arrow: field with nil DataType. Consequently, callers cannot use errors.Is(err, arrow.ErrInvalid) or see the invalid precision. Please handle and propagate the constructor error at that call site—panicking with it would work with the existing Avro recovery boundary—and add an Avro regression test preserving the precision error.
badba8a to
fd57908
Compare
Rationale for this change
NewDecimalType only checks maximum precision with debug assertions and does not reject zero precision. Normal builds can therefore create invalid decimal types.
What changes are included in this PR?
Validate that precision is between 1 and the maximum supported by the requested decimal type, and return arrow.ErrInvalid otherwise.
Are these changes tested?
Yes. The tests cover the lower and upper valid boundaries plus zero and overflow precision for all four decimal widths. The full arrow package suite passes.
Are there any user-facing changes?
NewDecimalType now returns an error for invalid precision instead of constructing an invalid type.