← Back to Pull requests

feat(spark): add Spark-compatible date_from_unix_date function #74

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

Closes #152.

Summary


  • Adds Spark's date_from_unix_date(days), ported from DataFusion Comet's datetime_funcs/date_from_unix_date.rs. It is the inverse of unix_date.

  • The argument is an INT. Like Spark, other integer, floating-point, decimal and string inputs are cast to INT, so fractions are truncated toward zero (1.7 gives 1970-01-02) and '100' gives 1970-04-11. BOOLEAN is rejected. NULL gives NULL.

  • Returns Date32, nullable only when the input is, as in Spark. The array path reinterprets the Int32 buffer as Date32 without copying.

  • Every INT is a valid date. A non-INT input that is out of the INT range (2147483648) or is not a valid number ('abc') raises an error from the cast, which matches Spark with ANSI mode on.

  • Documents the function with #[user_doc] and implements documentation(), following the guidelines in CONTRIBUTING.md (see #58).
  • Known gaps


    With ANSI mode off, Spark wraps an out-of-range BIGINT (unix_date(date_from_unix_date(2147483648)) is -2147483648) and returns NULL for a malformed string. DataFusion's cast errors in both cases. These need ANSI-aware casting (#88) and are recorded as commented-out queries in the slt.

    Testing


  • datetime/date_from_unix_date.slt, covering literal and column inputs, Comet's test cases, the INT range ends, overflow, strings, fractional inputs and BOOLEAN. The values for 0, 1000 and NULL come from Spark's date.sql.out golden file. The rest were verified against PySpark 4.2.0, and the PySpark slt runner passes on the file.

  • Very large day counts such as 2147483647 are valid but cannot be printed by Arrow's date formatter, so the slt checks them through a unix_date round trip.

  • cargo clippy --all-targets --all-features -- -D warnings, cargo test -p datafusion-spark and cargo test -p datafusion-spark-sqllogictest pass.
  • 🤖 Generated with Claude Code

    Diff: 239 lines (+179 / -60) across 2 files Reviewer: kosiew Review duration: 5531m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 239 lines diff across 2 files
    0.37
    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.328
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #74"
    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: 37.2% (MEDIUM) · Higher = larger blast radius
    37.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: 14.7% · Safe to merge
    14.7%