Skip to content

feat(native): Add endpoint for expression optimization in sidecar#26475

Merged
aditi-pandit merged 6 commits intoprestodb:masterfrom
pramodsatya:expr_opt
Dec 8, 2025
Merged

feat(native): Add endpoint for expression optimization in sidecar#26475
aditi-pandit merged 6 commits intoprestodb:masterfrom
pramodsatya:expr_opt

Conversation

@pramodsatya
Copy link
Contributor

@pramodsatya pramodsatya commented Oct 30, 2025

Description

To support constant folding and consistent semantics between the Presto Java coordinator and the Presto C++ worker, it is necessary to use consistent expression evaluation. To support this, a native expression evaluation endpoint, v1/expressions, has been added to the Presto C++ sidecar. This endpoint leverages the ExprOptimizer in Velox to optimize Presto expressions.

The optimized Velox core::TypedExpr returned by Velox's ExprOptimizer is converted to a Presto protocol::RowExpression in the Presto native sidecar with helper class VeloxToPrestoExprConverter. The end to end flow between the coordinator and sidecar is as follows:

RowExpression == (PrestoToVeloxExpr) ==> TypedExpr == (Velox ExprOptimizer optimize() API) ==> optimized TypedExpr == (VeloxToPrestoExprConverter) ==> optimized RowExpression

When OptimizerLevel is EVALUATED and an error is encountered during expression evaluation, it is converted to NativeSidecarFailureInfo with presto protocol. The list of optimized RowExpressions and NativeSidecarFailureInfos is returned along with their corresponding indices in the input expressions list. With the fuzzer testing (see test plan), we expect this endpoint to be ready for production workloads.

Motivation and Context

The native-sidecar-plugin will implement the ExpressionOptimizer interface from Presto SPI to utilize the v1/expressions endpoint on the sidecar for optimizing Presto expressions using the native expression evaluation engine.

The primary goal is to achieve consistency between C++ and Java semantics for expression optimization. With this change, C++ functions including UDFs can be used for constant folding of expressions in the Presto planner.
Please refer to RFC-0006.

Test Plan

Tests have been added by abstracting testcases from TestRowExpressionInterpreter to an interface AbstractTestExpressionInterpreter. This test interface is implemented in TestNativeExpressionInterpreter to test the v1/expressions endpoint on the sidecar end to end.

This feature is still in Beta, and to support production workloads with complete certainty, the Velox expression fuzzer will be extended to test this endpoint with fuzzer generated expressions in a follow-up PR. This should surface any remaining bugs, such as in VeloxToPrestoExpr.
Note: The Velox ExprOptimizer and logical rewrites are already tested with fuzzer.

Release Notes

Prestissimo (Native Execution) Changes
* Add http endpoint `v1/expressions` in sidecar for expression optimization. See :doc:`/presto_cpp/sidecar`.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Oct 30, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @pramodsatya, your pull request is larger than the review limit of 150000 diff characters

@pramodsatya pramodsatya force-pushed the expr_opt branch 2 times, most recently from d3f5a74 to 4224f36 Compare October 30, 2025 23:00
@pramodsatya pramodsatya marked this pull request as ready for review October 30, 2025 23:00
@prestodb-ci prestodb-ci requested review from a team and pratyakshsharma and removed request for a team October 30, 2025 23:00
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @pramodsatya, your pull request is larger than the review limit of 150000 diff characters

@pramodsatya
Copy link
Contributor Author

@aditi-pandit, @tdcmeehan, could you please take a look?

@pramodsatya pramodsatya force-pushed the expr_opt branch 2 times, most recently from 8034891 to 69c7c37 Compare November 5, 2025 18:37
Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pramodsatya. Have bunch of comments.

@pramodsatya
Copy link
Contributor Author

Thanks @aditi-pandit, made the changes as suggested. Could you PTAL?

@pramodsatya pramodsatya force-pushed the expr_opt branch 2 times, most recently from 02fa18e to b809033 Compare December 3, 2025 07:47
@pramodsatya
Copy link
Contributor Author

Thanks @aditi-pandit, addressed the comments, could you please take another look?

Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pramodsatya. Code looks good to me.

@czentgr : Do you want to give it a read as well ? If it looks good, then we can get Tim to approve on the Java part as well.

steveburnett
steveburnett previously approved these changes Dec 5, 2025
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! (docs)
Pull branch, local doc build. Thanks!

czentgr
czentgr previously approved these changes Dec 5, 2025
aditi-pandit
aditi-pandit previously approved these changes Dec 8, 2025
Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pramodsatya

tdcmeehan
tdcmeehan previously approved these changes Dec 8, 2025
Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pramodsatya for all the iterations.

@pramodsatya pramodsatya requested a review from tdcmeehan December 8, 2025 07:17
@aditi-pandit aditi-pandit merged commit 18323c3 into prestodb:master Dec 8, 2025
143 of 202 checks passed
@pramodsatya pramodsatya deleted the expr_opt branch December 8, 2025 21:23
pdabre12 added a commit that referenced this pull request Dec 12, 2025
)

## Description
Add a `ExpressionOptimizer` which delegates to the native sidecar
process to evaluate expressions with Velox.

## Motivation and Context
#26475 added support for an
endpoint in the sidecar for constant folding expressions. This follows
up on that by adding an expression interpreter to call that endpoint.

For more context:
[RFC-0006](https://github.com/prestodb/rfcs/blob/main/RFC-0006-expression-eval.md).

## Impact
No impact by default as the old in-memory evaluation is the default.

## Test Plan
Tests have been added.

## Contributor checklist

- [x] Please make sure your submission complies with our [contributing
guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md),
in particular [code
style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style)
and [commit
standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [x] PR description addresses the issue accurately and concisely. If
the change is non-trivial, a GitHub Issue is referenced.
- [x] Documented new properties (with its default value), SQL syntax,
functions, or other functionality.
- [x] If release notes are required, they follow the [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [x] Adequate tests were added if applicable.
- [x] CI passed.

## Release Notes
Please follow [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines)
and fill in the release notes below.

```
== RELEASE NOTES ==

Prestissimo (Native Execution) Changes
* Add a native expression optimizer for optimizing expressions in the sidecar.
```

---------

Co-authored-by: Timothy Meehan <tdm@fb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants