-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Use built-in functions for constant folding in ValuesStatsRule #25076
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
Conversation
|
@pramodsatya : Thanks for debugging this. ReplaceConstantVariableReferencesWithConstants and ValuesStatsRule are 2 independent rules imo. So I don't think we should use the config of one for the other. ValuesStatsRule should be disabled for native execution since its relying on evaluating the constant values at the co-ordinator, when we should actually use the worker (or side-car when it supports it) . But disabling now might be too disruptive. @rschlussel @amitkdutta : Would be great to hear your thoughts on this. |
ee0c976 to
6471ae9
Compare
Thanks for pointing it out @aditi-pandit, I had used |
rschlussel
left a comment
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.
I thought currently even if you are using the sidecar, constant evaluation and constant folding will happen in Java with the "java equivalent" functions. Is that not the case?
| VariableReferenceExpression variable = node.getOutputVariables().get(variableId); | ||
| List<Object> symbolValues = getVariableValues(node, variableId, session, variable.getType()); | ||
| statsBuilder.addVariableStatistics(variable, buildVariableStatistics(symbolValues, session, variable.getType())); | ||
| if (!isNativeExecutionEnabled(session)) { |
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.
this is disabling for all nativeExecution, not just sidecar
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.
This check is just a placeholder, will revert it once the right check/fix is figured out.
@rschlussel, yes that is mostly right, I have added the specific testcase that is failing in the PR description, could you please share if disabling the constant expression evaluation in |
|
So it seems this issue is because we swap out the default function namespace to whatever is listed by the sidecar as being registered in Velox. Without #24126, you can't constant fold at all because no function is eligible to be evaluated in the Presto coordinator (they're C++ functions and there's no mechanism to evaluate C++ functions yet). We could probably tactically add a hacky We could also just wait for native constant folding to land. |
I'd vote to add the temporary solution to support constant folding in the coordinator for now. We'd like to be able to enable sidecar in production, but no constant folding will be a deal breaker. We'd also want to do more testing for sidecar constant folding before enabling it once it lands and have some stretch of time where we can disable it without removing other sidecar features, because constant folding has the possibility of correctness bugs, so it's a riskier change to incorporate. |
|
fyi @amitkdutta |
|
The option to temporarily use a hacked ExpressionOptimizer that goes back to the Java namespace is definitely useful. It will help us also to turn of/off the constant folding logic without much disruption. Given all the redesign requested for constant folding, it will take several cycles to get it right I feel. |
|
Thanks for the feedback, will modify the ExpressionOptimizer to use Java namespace for function eval. |
6471ae9 to
4100bd1
Compare
Description
When the optimizer computes plan stats for the rewritten plan, the rule
ValuesStatsRuleattempts to evaluate variables to constants in function getVariableValues. C++ functions should not be used to constant fold inValuesStatsRulewhen native function namespace manager is used in sidecar until constant folding is supported by sidecar. Enable use of built-in functions for constant folding in defaultRowExpressionOptimizerand use built-in functions to evaluate constants inValuesStatsRule.Motivation and Context
When the native CTE tests are run with the sidecar enabled, the testcase
testPersistentCteForVarbinaryTypefails with the following error:This is because the plan optimizer attempts to evaluate CallExpressions in the query plan, such as
from_base64('Qm9iIEpvaG5zb24='), to ConstantExpressions when calculating plan stats inValuesStatsRule. This evaluation will fail when native function implementations are used by the sidecar, since the function implementation type will beCPPand these functions will not be evaluated in the coordinator.ValuesStatsRuleshould use built-in functions for evaluating constant expressions until the sidecar supports expression evaluation with native engine (WIP: #24126).Test Plan
Please refer to commit, comprehensive e2e tests for function analysis with native sidecar will be added in #24717.
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.