[SPARK-57833][SQL] Support nanosecond-precision timestamps in timestampadd #58855
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
stevomitric
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]).TimestampAdd.inputTypestoTypeCollection(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.NANOSECONDunit (the token already exists for interval literals; it is added to the shareddatetimeUnitgrammar rule): the fraction absorbs the quantity and whole microseconds carry intoepochMicros. Overflow surfaces asDATETIME_OVERFLOW.NANOSECONDis 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,
timestampaddrejected nanosecond timestamp arguments by casting them to microseconds, silently losing the sub-microsecond digits.Does this PR introduce any user-facing change?
Yes.
timestampaddnow accepts nanosecond-precision timestamps and preserves their sub-microsecond fraction, and supports a newNANOSECONDunit for nanosecond-precision inputs.How was this patch tested?
New unit test in
DateExpressionsSuiteand golden file tests.Was this patch authored or co-authored using generative AI tooling?
Co-Authored-by: Claude Opus 5