← Back to Pull requests

test: run sqllogictests with and without constant folding #316

Closed
unknown closed this pull request without merging on Nov 19, 2026 11:56 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 12:18 UTC
Author

Which issue does this PR close?

None. It adds the test coverage that found #305–#315.

Rationale for this change

A Spark function can run in two ways. When every argument is a literal, the simplify_expressions optimizer rule constant-folds the call while planning. That calls ScalarUDFImpl::simplify (if the function has one) and evaluates the result on a one-row batch. Otherwise the call runs through invoke_with_args during execution. That is also the only path for engines such as Comet that build physical expressions directly.

Most .slt queries are literal-only, such as SELECT f(1), so today they only test the first path. invoke_with_args must always work, and simplify is an optional optimization. This PR runs the tests through both paths.

What changes are included in this PR?

  • The runner runs every .slt file twice:

  • - simplify: the default optimizer, as before.
    - evaluate: the same optimizer rules with simplify_expressions replaced by a rule that rewrites only DataFusion's rewrite-only functions (arrow_cast, arrow_try_cast, cast_to_type, try_cast_to_type, nvl2). The tests use those to build typed inputs, and their invoke_with_args always errors. Every other call, including literal-only calls of the Spark functions, runs through invoke_with_args.
  • Each run gets its mode as an .slt label, so a record can be marked skipif evaluate. (skipif rather than onlyif simplify, because the PySpark runner skips onlyif records that are not for spark.)

  • --mode=simplify or --mode=evaluate runs a single mode. Results print as PASS [evaluate] path.

  • A panic in one file is reported as that file failing, instead of aborting the whole run.

  • Each record that cannot run in evaluate mode yet is marked skipif evaluate, with a note at the top of the file linking its issue.

  • --complete runs only in simplify mode, so each file is rewritten once.

  • test_files/README.md documents the two modes.
  • What evaluate mode found

    Eight functions have no working invoke_with_args: they error unless simplify rewrites them first. Their records are marked skipif evaluate.

    | Function | Issue |
    |---|---|
    | if | #305 |
    | unix_date | #306 |
    | date_diff | #307 |
    | date_trunc | #309 |
    | time_trunc | #310 |
    | trunc | #311 |
    | add_months | #312 |
    | base64 | #313 |

    Two bugs in the invoke_with_args path, each with one query marked skipif evaluate:

  • #314: concat_ws panics when all arguments are scalars and number_rows > 1. This is the same pattern #68 fixed in hash.

  • #315: make_dt_interval declares a non-nullable result but can return NULL.
  • Are these changes tested?

    cargo test -p datafusion-spark-sqllogictest runs all 257 files in both modes (514 runs). To check which files need the evaluate path, I temporarily ran each failing file record by record, so a file's first failure didn't hide the rest. Every evaluate-mode failure is one of the issues above. The skipif evaluate marks do not change what the PySpark runner runs.

    Are there any user-facing changes?

    No. CI's sqllogictest job takes longer because every file now runs twice.

    Diff: 397 lines (+297 / -100) across 4 files Reviewer: kosiew Review duration: 4297m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 397 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.358
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #316"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 43.2% (MEDIUM) · Higher = larger blast radius
    43.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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 17.1% · Safe to merge
    17.1%