-
Notifications
You must be signed in to change notification settings - Fork 96
fix(isthmus)!: reject RANGE offsets that cannot be retyped to the ordering column #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ public class WindowBoundConverter { | |
| * @return the corresponding Substrait {@link WindowBound} | ||
| * @throws IllegalStateException if the bound is not one of CURRENT ROW, UNBOUNDED, PRECEDING, or | ||
| * FOLLOWING | ||
| * @throws UnsupportedOperationException if a RANGE offset's integral literal cannot be retyped to | ||
| * the ordering expression's type without breaking {@code add(T, D) -> T} | ||
| */ | ||
| public static WindowBound toWindowBound( | ||
| RexWindowBound rexWindowBound, | ||
|
|
@@ -82,10 +84,21 @@ private static Expression normalizeIntegralOffset( | |
| // The spec requires a BOUNDS_TYPE_ROWS offset_expr to be int64. | ||
| return ExpressionCreator.i64(false, value.get()); | ||
| } | ||
| // BOUNDS_TYPE_RANGE: keep add(T, D) -> T defined for the ordering expression's type T. | ||
| // BOUNDS_TYPE_RANGE: keep add(T, D) -> T defined for the ordering expression's type T. If the | ||
| // ordering type is unknown, there is nothing to retype against, so the literal is left as-is. | ||
| return orderingType | ||
| .map(typeConverter::toSubstrait) | ||
| .flatMap(type -> integralLiteralOfType(type, value.get())) | ||
| .map( | ||
| type -> | ||
| integralLiteralOfType(type, value.get()) | ||
| .orElseThrow( | ||
| () -> | ||
| new UnsupportedOperationException( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reword this to say what isthmus cannot build rather than what the spec forbids. The |
||
| "RANGE window offset " | ||
| + value.get() | ||
| + " cannot be represented as the ordering expression's type " | ||
| + type | ||
| + " without breaking add(T, D) -> T"))) | ||
| .orElse(offset); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for a zero offset before retyping — a zero offset needs no representation in the ordering expression's type, so it should never reach this guard. On this branch
order by d55 range between 0 preceding(DECIMAL(5,5)) throws wheremainreturnsCurrentRow, becausedigitCount(0)is 1 and1 + 5 > 5; the same move also turns the currentPreceding{0}output forDECIMAL(10,2)andDOUBLEordering columns into theCurrentRowthe spec asks for.In
toWindowBound, replacing lines 49-61 with:keeps the rejection this PR is adding (
100000over aSMALLINTcolumn still throws) and leavesWindowBoundConverterTestandWindowFunctionTestgreen.