Skip to content

[common] Fix invalid DecimalType when extracting a variant decimal - #9672

Open
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:variant-decimal-scale
Open

[common] Fix invalid DecimalType when extracting a variant decimal#9672
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:variant-decimal-scale

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Purpose

VariantGet took the precision and scale straight off the BigDecimal that getDecimal() returns. precision() counts the unscaled digits, so it is below the scale for anything under 0.1, and the trailing-zero stripping in getDecimal() turns 100.00 into 1E+2, a negative scale. DecimalType rejects both, so extraction threw Decimal scale must be between 0 and the precision 1. Reachable on Spark 4.1+ pushdown, which accepts a string target and any try_variant_get.

A negative scale is rescaled to zero and the precision widened to the scale, matching Spark's Decimal.set(BigDecimal). checkDecimal caps both at 38 on read, so this stays in range.

Two things it does not close, both owned by open PRs:

Tests

GenericVariantTest for both shapes and the scale-38 boundary, PaimonShreddingUtilsTest for the pushdown path.

Written with Claude Code; verification is mine.

VariantGet took the precision and scale straight off the BigDecimal that
getDecimal() returns. precision() counts the digits of the unscaled value,
so it is below the scale for anything under 0.1, and the trailing zero
stripping in getDecimal() turns 100.00 into 1E+2, a negative scale.
DecimalType rejects both, so extracting such a value threw "Decimal scale
must be between 0 and the precision 1".

Rescale a negative scale to zero and widen the precision to the scale,
which is bit for bit what Spark's Decimal.set(BigDecimal) does. The reader
caps scale and precision at 38 in GenericVariantUtil.checkDecimal, so the
widened precision stays inside DecimalType.
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.

1 participant