← Back to Pull requests

test: replace arrow_cast with :: casts where a SQL type is equivalent #76

Closed
unknown closed this pull request without merging on Nov 23, 2026 16:49 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 00:41 UTC
Author

Which issue does this PR close?

N/A. Follow-up to #54 (the PySpark runner skips any query that calls arrow_cast, because Spark has no such function).

Rationale for this change

Many .slt queries use arrow_cast only to pick a type that has a plain SQL name. Writing those as :: casts makes the tests easier to read, and Spark can run them, so the PySpark runner checks these queries instead of skipping them.

What changes are included in this PR?

arrow_cast(x, 'T') becomes x::SQLTYPE in 58 files (482 lines) when DataFusion maps the SQL type to exactly the same Arrow type and Spark accepts the type name:

| Arrow type | SQL type |
|---|---|
| Int8 / Int16 / Int32 / Int64 | TINYINT / SMALLINT / INT / BIGINT |
| Float32 / Float64 | FLOAT / DOUBLE |
| Boolean, Binary, Date32 | BOOLEAN, BINARY, DATE |
| Utf8View | STRING |
| Decimal128(p, s), p ≤ 38 | DECIMAL(p, s) |
| List(Int32) | ARRAY<INT> |

:: binds tighter than unary minus, so negative literals and expressions are wrapped in parentheses, for example (-128)::TINYINT. Without them, -128::TINYINT casts 128 first and overflows.

Spark cannot cast an integer to DATE, so an arrow_cast(n, 'Date32') of an integer day count becomes date_from_unix_date(n) rather than n::DATE. A test that reads a DATE result back as a day count uses unix_date(...), because Spark's CAST of a DATE to INT returns NULL.

arrow_cast is kept where no SQL type gives the same Arrow type:

  • Utf8, because STRING and VARCHAR map to Utf8View by default

  • unsigned integers, Float16, Large, View, Date64, Time32, Decimal32/Decimal64/Decimal256, FixedSize*, Dictionary, Struct and Map

  • timestamps with a precision or a time zone, and Time64

  • Utf8View casts of a column that is already Utf8View (in bround.slt and positive.slt), where column1::STRING gets the same name as plain column1 and DataFusion rejects the duplicate projection
  • Are these changes tested?

    Only test files changed. cargo test -p datafusion-spark-sqllogictest passes, apart from math/expm1.slt, which also fails on main on macOS and is fixed by #359. The PySpark runner now checks the converted queries on Spark 4.2, and none of them adds a new difference from Spark.

    Are there any user-facing changes?

    No.

    Diff: 296 lines (+222 / -74) across 3 files Reviewer: kosiew Review duration: 15368m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 296 lines diff across 3 files
    0.40
    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%
    56%
    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.341
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #76"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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.0% (MEDIUM) · Higher = larger blast radius
    40.0%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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.3% · Safe to merge
    17.3%