Skip to content

feat(core): evaluate return-type programs and inline arithmetic - #1288

Open
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:issue-1242-return-program
Open

feat(core): evaluate return-type programs and inline arithmetic#1288
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:issue-1242-return-program

Conversation

@alexandrefimov

@alexandrefimov alexandrefimov commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Decimal arithmetic functions declare their return type as assignments followed by a final type expression. The evaluator currently rejects these programs, so their precision and scale cannot be derived from the function declaration.

Evaluate sequential assignments and arithmetic inside type parameters using the existing argument bindings. Support integer arithmetic, min/max, comparisons, boolean operations and conditionals from spec v0.102.0. Use signed 64-bit intermediate values and reject arithmetic overflow or narrowing outside the type parameter's 32-bit range.

Integer division truncates toward zero. AND/OR evaluate both operands, while conditionals evaluate only the selected branch, matching substrait-go's evaluator.

This enables 11 of the 15 catalog return programs: eight decimal arithmetic and three rounding variants. Four temporal variants still reference integer_parameter(precision) without binding precision from an argument type and remain unsupported.

Unary abs in return expressions also remains unsupported.

Refs #1242

Decimal arithmetic functions declare their return type as assignments followed by a final type expression. The evaluator currently rejects these programs, so their precision and scale cannot be derived from the function declaration.

Evaluate sequential assignments and arithmetic inside type parameters using the existing argument bindings. Support integer arithmetic, min/max, comparisons, boolean operations and conditionals from [spec v0.102.0](https://github.com/substrait-io/substrait/blob/v0.102.0/site/docs/expressions/scalar_functions.md#return-type-expressions). Use signed 64-bit intermediate values and reject arithmetic overflow or narrowing outside the type parameter's 32-bit range.

Integer division truncates toward zero. AND/OR evaluate both operands, while conditionals evaluate only the selected branch, matching [substrait-go's evaluator](https://github.com/substrait-io/substrait-go/blob/cb2d6e648bc0ee1549e354dbfe705d9f8a1ce2b1/types/type_derivation.go).

This enables 11 of the 15 catalog return programs: eight decimal arithmetic and three rounding variants. Four temporal variants still reference integer_parameter(precision) without binding precision from an argument type and remain unsupported.

Refs substrait-io#1242
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