Skip to content

fix(arrow): validate precision in NewDecimalType - #1162

Merged
zeroshade merged 2 commits into
apache:mainfrom
fallintoplace:fix/decimal-type-precision
Aug 26, 2026
Merged

fix(arrow): validate precision in NewDecimalType#1162
zeroshade merged 2 commits into
apache:mainfrom
fallintoplace:fix/decimal-type-precision

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

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.

@fallintoplace
fallintoplace force-pushed the fix/decimal-type-precision branch from 7cbb6c5 to 8ac32a0 Compare August 9, 2026 22:51
@fallintoplace
fallintoplace marked this pull request as ready for review August 9, 2026 22:51
@fallintoplace
fallintoplace marked this pull request as draft August 9, 2026 22:54
@fallintoplace
fallintoplace force-pushed the fix/decimal-type-precision branch from 8ac32a0 to badba8a Compare August 23, 2026 22:04
@fallintoplace
fallintoplace marked this pull request as ready for review August 23, 2026 22:10

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

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",

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.

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.

@fallintoplace
fallintoplace force-pushed the fix/decimal-type-precision branch from badba8a to fd57908 Compare August 25, 2026 20:17
@zeroshade
zeroshade merged commit 2950f2e into apache:main Aug 26, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants