← Back to Pull requests

GH-55614: [C++][Gandiva] Build the expression cache key from the expression tree #55608

Open
unknown opened this pull request with 304 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 14, 2026 08:40 UTC
Author

Rationale for this change

The cache key is built from Expression::ToString(). Different expressions can print the same text, so the second Projector::Make reuses the compiled code of the first. The result is wrong, with no error. Four cases on main:

  • a AND (b OR c) and (a AND b) OR c print the same text.

  • String literals are not escaped, so two IF expressions can print the same text.

  • The key has no output field type. An int64 output skips validation after an int32 one was compiled, and returns garbage.

  • The key ignores the nullability of the fields in the expression. A field node with the wrong nullability is rejected on the first Make, but accepted when a valid one was compiled before.
  • What changes are included in this PR?

    The PR has the tests first, then the fix in expression_cache_key.h.

    The fix builds the key with a visitor over the expression tree, with the output field type. It is a compact binary form. Every node starts with a tag, tokens carry their length, and child lists carry their count. Types and names that repeat are written once and then as a short reference. It also sorts IN lists and finds like by node, not by text. The key handles null child nodes, so it no longer crashes before validation.

    Are these changes tested?

    Yes. 15 new tests: key unit tests in cache_test.cc, and end-to-end tests for Projector and Filter in projector_test.cc, filter_test.cc, boolean_expr_test.cc, if_expr_test.cc and projector_build_validation_test.cc. They cover the cases above, IN value lists, type parameters, floating point literals, null child nodes, and two schemas that differ only in nullability.

    On main, 12 of them fail (one crashes with SIGSEGV). Three pass on both keys: FloatingPointBitsAndNulls, because float and double literals already print their bits, and the two tests for schemas that differ only in nullability, which record current behavior.

    See the comments for the time to build the key and its size.

    Are there any user-facing changes?

    No.

    This PR contains a "Critical Fix". It fixes a bug that returned incorrect data without an error.

    Was AI used for this PR?

    AI tools helped investigate the bug and write the fix, tests, and description.

    PR code and description written by:

  • Human

  • AI
  • Reviewed before submission by:

  • Human

  • AI

  • Not reviewed
  • GitHub Issue: Closes #55614
  • Diff: 304 lines (+228 / -76) across 3 files Reviewer: kou Review duration: 20536m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 304 lines diff across 3 files
    0.40
    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%
    46%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.342
    Real PR Conversation Timeline
    1 comments
    "Review active on #55608"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 21.4% · Safe to merge
    21.4%
    Repository