← Back to Pull requests

[SPARK-57833][SQL] Support nanosecond-precision timestamps in timestampadd #58855

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

What changes were proposed in this pull request?

Extend timestampadd(unit, quantity, timestamp) to accept nanosecond-precision timestamp endpoints (TIMESTAMP_NTZ(p) / TIMESTAMP_LTZ(p), p in [7, 9]).

  • Widen TimestampAdd.inputTypes to TypeCollection(AnyTimestampType, AnyTimestampNanoType) so a nanosecond argument is no longer implicitly cast to microseconds (which silently dropped the sub-microsecond fraction). The result keeps the input's nanosecond type.

  • For units of MICROSECOND or coarser, the addition runs on the microsecond grid (reusing the existing calendar/DST/overflow handling) and the sub-microsecond fraction is carried through unchanged.

  • Add a NANOSECOND unit (the token already exists for interval literals; it is added to the shared datetimeUnit grammar rule): the fraction absorbs the quantity and whole microseconds carry into epochMicros. Overflow surfaces as DATETIME_OVERFLOW. NANOSECOND is meaningful only for a nanosecond-precision timestamp; on a microsecond timestamp it is rejected as an invalid unit.
  • Why are the changes needed?

    Part of the nanosecond-precision timestamp umbrella (SPARK-56822). Without this, timestampadd rejected nanosecond timestamp arguments by casting them to microseconds, silently losing the sub-microsecond digits.

    Does this PR introduce any user-facing change?

    Yes. timestampadd now accepts nanosecond-precision timestamps and preserves their sub-microsecond fraction, and supports a new NANOSECOND unit for nanosecond-precision inputs.

    How was this patch tested?

    New unit test in DateExpressionsSuite and golden file tests.

    Was this patch authored or co-authored using generative AI tooling?

    Co-Authored-by: Claude Opus 5

    Diff: 220 lines (+165 / -55) across 2 files Reviewer: stevomitric Review duration: 2905m
    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 · 220 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.323
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #58855"
    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: 36.8% (MEDIUM) · Higher = larger blast radius
    36.8%
    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.5% · Safe to merge
    14.5%
    Repository