Skip to content

fix(spark): report interval_year overflow instead of wrapping - #1140

Open
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:issue-1138-interval-year-overflow
Open

fix(spark): report interval_year overflow instead of wrapping#1140
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:issue-1138-interval-year-overflow

Conversation

@alexandrefimov

Copy link
Copy Markdown
Contributor

ToSparkExpression.visit(IntervalYearLiteral) flattened years and months with unchecked Int arithmetic. Both operands are int32 on the wire and Spark's physical type is a months Int, so unlike the day-time case nothing widens the multiply: above 178,956,970 years it wrapped, and a large positive interval came out negative — 178,956,971 years as −2,147,483,644 months, Int.MaxValue years as −12.

Far outside the spec's 10,000-year bound, so it takes a producer already well past it, and #1129 remains the primary fix — a per-component check in core would make this unreachable rather than merely loud. What makes it worth fixing here anyway is that #1128 hardened the day-time literal eight lines above, so the two adjacent conversions in the same visitor took opposite stances on the same arithmetic.

Closes #1138.

years and months are both int32 on the wire and Spark's physical type
is a months Int, so nothing widens the arithmetic the way the day-time
literal is widened. Above 178,956,970 years the product wrapped, and a
large positive interval came out negative — Int.MaxValue years became
-12 months.

Far outside the spec's 10,000-year bound, so it takes a producer that
is already well past it; the point is that the two adjacent literal
conversions now take the same stance on the same arithmetic.
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.

spark: interval_year literal conversion silently wraps on Int overflow

1 participant