[fix](nereids) Prevent PushDownProject from extracting expressions with free lambda arguments #69938
All Vouch review confidence checks passed
Residual risk 0.31 = Change Risk (0.52) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 434 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.363
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #69938"
general
weight: 0.35
morrySnow
What problem does this PR solve?
Issue Number: close #69930
Related PR: N/A
Problem Summary:
When an enclosing higher-order function (such as
ARRAY_FIRST(p -> STRUCT_ELEMENT(p, 1) = k, arr)) references slots from both sides of a join, it cannot be pushed down as a whole.PushDownProjectthen descends into its children viarewriteDownShortCircuit.Because
Expression.getInputSlots()(Expression.java:73-74) deliberately excludesArrayItemSlot, aPreferPushDownProjectsub-expression inside the lambda body that only references the lambda parameterp(such aselement_at(p, 1)) has an emptygetInputSlots()set. BothPushDownProject.pushDownProjectInExpressionsandPushdownProjectHelper.pushDownExpressiontreatchild.getOutputSet().containsAll(emptySet)as satisfied by the first child (join.left()) and extractelement_at(p, 1)out of its enclosingLambdainto a childLogicalProject, leavingpunbound:Before:
During physical plan translation (
PhysicalPlanTranslator.visitPhysicalProject->ExpressionTranslator.visitArrayItemSlot),pis not present inlambdaSlotToColumnRef(which is only populated while translatingvisitArrayMap), returningnulland failing with aNullPointerExceptioninExpr.extractSlots.After:
Fix:
PreferPushDownProjectrewrite sites inPushDownProject(pushDownProjectInExpressionsandPushdownProjectHelper.pushDownExpression) with!hasFreeLambdaArgument(e).hasFreeLambdaArgumentuses an O(1)containsType(ArrayItemSlot.class)fast path and tracks bound lambda parameterExprIds lexically across nestedLambdas (checkingArrayItemReference.getArrayExpression()in the outer scope before binding the lambda's own parameters).cc @matanper @morrySnow @924060929 @englefly
Release note
None
Check List (For Author)
- [ ] Regression test
- [x] Unit Test (
PushDownProjectTest)- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- [x] No.
- [ ] Yes. <!-- Explain the behavior change -->
- [x] No.
- [ ] Yes. <!-- Add document PR link here. eg: https://github.com/apache/doris-website/pull/1214 -->
Check List (For Reviewer who merge this PR)