← Back to Pull requests

[fix](nereids) Prevent PushDownProject from extracting expressions with free lambda arguments #69938

Open
unknown opened this pull request with 434 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 02, 2026 02:26 UTC
Author

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. PushDownProject then descends into its children via rewriteDownShortCircuit.

Because Expression.getInputSlots() (Expression.java:73-74) deliberately excludes ArrayItemSlot, a PreferPushDownProject sub-expression inside the lambda body that only references the lambda parameter p (such as element_at(p, 1)) has an empty getInputSlots() set. Both PushDownProject.pushDownProjectInExpressions and PushdownProjectHelper.pushDownExpression treat child.getOutputSet().containsAll(emptySet) as satisfied by the first child (join.left()) and extract element_at(p, 1) out of its enclosing Lambda into a child LogicalProject, leaving p unbound:

Before:

LogicalProject(k, element_at(element_at(array_filter(arr, array_map(p -> #x = k, arr)), 1), 2) AS v)
  LogicalJoin(CROSS_JOIN)
    left:  LogicalProject(k, element_at(p, 1) AS #x)   <-- 'p' (ArrayItemSlot) is unbound here!
             LogicalOneRowRelation(k)
    right: LogicalOneRowRelation(arr)

During physical plan translation (PhysicalPlanTranslator.visitPhysicalProject -> ExpressionTranslator.visitArrayItemSlot), p is not present in lambdaSlotToColumnRef (which is only populated while translating visitArrayMap), returning null and failing with a NullPointerException in Expr.extractSlots.

After:

LogicalProject(k, element_at(element_at(array_filter(arr, array_map(p -> element_at(p, 1) = k, arr)), 1), 2) AS v)
  LogicalJoin(CROSS_JOIN)
    left:  LogicalOneRowRelation(k)
    right: LogicalOneRowRelation(arr)

Fix:

  • Guard both PreferPushDownProject rewrite sites in PushDownProject (pushDownProjectInExpressions and PushdownProjectHelper.pushDownExpression) with !hasFreeLambdaArgument(e).

  • hasFreeLambdaArgument uses an O(1) containsType(ArrayItemSlot.class) fast path and tracks bound lambda parameter ExprIds lexically across nested Lambdas (checking ArrayItemReference.getArrayExpression() in the outer scope before binding the lambda's own parameters).

  • Complete, self-contained higher-order expressions whose relational inputs come from a single child continue to be pushed down as before.
  • cc @matanper @morrySnow @924060929 @englefly

    Release note

    None

    Check List (For Author)

  • Test <!-- At least one of them must be included. -->

  • - [ ] 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? -->

  • Behavior changed:

  • - [x] No.
    - [ ] Yes. <!-- Explain the behavior change -->

  • Does this need documentation?

  • - [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)

  • Confirm the release note

  • Confirm test cases

  • Confirm document

  • Add branch pick label <!-- Add branch pick label that this PR should merge into -->
  • Diff: 434 lines (+325 / -109) across 5 files Reviewer: morrySnow Review duration: 44779m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.2% (MEDIUM) · Higher = larger blast radius
    52.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.8% · Safe to merge
    30.8%
    Repository