You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The interface ExpressionOptimizerFactory in Presto SPI allows customization of expression optimization. NativeExpressionOptimizerFactory implements this interface to provide a NativeExpressionOptimizer in this PR, this allows Presto C++ to constant fold expressions in the native execution engine Velox. NativeExpressionOptimizer uses helper class NativeSidecarExpressionInterpreter to collect all input RowExpressions from the query to be optimized (by constant folding) and delegates expression optimization to the Presto C++ sidecar via a http request to the endpoint v1/expressions. The Presto C++ sidecar receives an array of Presto protocol RowExpressions to be optimized in the body of this http request and returns a list of optimized RowExpressions to the Presto coordinator (via the native sidecar plugin).
Description
For each input RowExpression received by the Presto C++ sidecar, helper class RowExpressionOptimizer from the PR is used to optimize it with the following steps:
The optimized RowExpression from 1 is now the input RowExpression which is to be constant folded in Velox (the optimization rules from 1 will subsequently be moved to Velox)
The input protocol::RowExpression is converted to a Velox typed expression using VeloxExprConverter
This typed expression is compiled in Velox with constant folding enabled to get a Velox exec::Expr
The constant folded Velox expression is converted back to a Presto protocol RowExpression using the helper class RowExpressionConverter (to be added in PR)
During expression compilation in Velox with the constant folding optimization enabled (in step 4), any error encountered during evaluation of the constant expression (such as with expression divide(0,0)) is suppressed with a try/catch block in the function tryFoldIfConstant, and the input expression is returned as-is.
In Presto java, RowExpressions are constant folded during planning in RowExpressionInterpreter.java and any exceptions encountered during constant folding are replaced by a FailFunction (instance of Presto protocol CallExpression) in the function processWithExceptionHandling.
In order to support the same behavior in Presto C++, Velox's expression compiler needs to indicate any errors encountered during constant folding with a suitable error code (such as StandardErrorCode in presto-spi). The Velox change is prototyped in this PR. With this change in Velox's expression compiler, RowExpressionConverter (to be added in PR) could convert the Velox FailFunction to Presto FailFunction (instance of protocol CallExpression) appropriately. This would help achieve consistency between Presto and Presto C++ for constant folding.
Opening this issue to discuss approaches for handling exceptions during constant folding of expressions using the native execution engine.
Background
The interface
ExpressionOptimizerFactory
in Presto SPI allows customization of expression optimization.NativeExpressionOptimizerFactory
implements this interface to provide aNativeExpressionOptimizer
in this PR, this allows Presto C++ to constant fold expressions in the native execution engine Velox.NativeExpressionOptimizer
uses helper classNativeSidecarExpressionInterpreter
to collect all inputRowExpression
s from the query to be optimized (by constant folding) and delegates expression optimization to the Presto C++ sidecar via a http request to the endpointv1/expressions
. The Presto C++ sidecar receives an array of Presto protocolRowExpression
s to be optimized in the body of this http request and returns a list of optimizedRowExpression
s to the Presto coordinator (via the native sidecar plugin).Description
For each input
RowExpression
received by the Presto C++ sidecar, helper classRowExpressionOptimizer
from the PR is used to optimize it with the following steps:RowExpression
is an instance ofSpecialFormExpression
, it is optimized using rules borrowed from functionvisitSpecialForm
inRowExpressionInterpreter.java
.RowExpression
from1
is now the inputRowExpression
which is to be constant folded in Velox (the optimization rules from1
will subsequently be moved to Velox)protocol::RowExpression
is converted to a Velox typed expression usingVeloxExprConverter
exec::Expr
RowExpression
using the helper classRowExpressionConverter
(to be added in PR)During expression compilation in Velox with the constant folding optimization enabled (in step 4), any error encountered during evaluation of the constant expression (such as with expression
divide(0,0)
) is suppressed with atry/catch
block in the functiontryFoldIfConstant
, and the input expression is returned as-is.In Presto java,
RowExpression
s are constant folded during planning inRowExpressionInterpreter.java
and any exceptions encountered during constant folding are replaced by aFailFunction
(instance of Presto protocolCallExpression
) in the functionprocessWithExceptionHandling
.In order to support the same behavior in Presto C++, Velox's expression compiler needs to indicate any errors encountered during constant folding with a suitable error code (such as StandardErrorCode in
presto-spi
). The Velox change is prototyped in this PR. With this change in Velox's expression compiler,RowExpressionConverter
(to be added in PR) could convert the VeloxFailFunction
to PrestoFailFunction
(instance of protocolCallExpression
) appropriately. This would help achieve consistency between Presto and Presto C++ for constant folding.Opening this issue to discuss approaches for handling exceptions during constant folding of expressions using the native execution engine.
cc: @aditi-pandit @tdcmeehan @majetideepak @czentgr
The text was updated successfully, but these errors were encountered: