← Back to Pull requests

fix(spark): quote writes a timestamp with a space like Spark #422

Open
unknown opened this pull request with 347 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 26, 2026 08:16 UTC
Author

Which issue does this PR close?

  • Closes #96.
  • Rationale for this change

    quote of a timestamp returned ISO 8601 with a T separator and kept trailing fractional zeros (for example '2024-01-15T12:30:45.120'), because DataFusion coerced the argument to Utf8 using Arrow's cast. Spark's Quote takes a STRING via ImplicitCastInputTypes, so Spark casts timestamps with yyyy-MM-dd HH:mm:ss[.fraction] in the session time zone and drops trailing zeros of the fraction.

    What changes are included in this PR?

  • Unwrap Dictionary types in SparkQuote::coerce_types, keep timestamp inputs as Timestamp(Microsecond, tz), and format them with spark_cast in invoke_with_args using datafusion.execution.time_zone (UTC when unset). Other non-string types still use DataFusion's cast, and other functions that coerce timestamps to strings stay tracked under #347 and #95.

  • Change SparkQuote from Volatility::Immutable to Volatility::Stable to match spark_cast and timestamp_micros, since timestamp output depends on the session time zone and should not be folded before execution in prepared statements or views.

  • Update #[user_doc] on SparkQuote and regenerate docs/functions/scalar/string.md.
  • Are these changes tested?

  • crates/sqllogictest/test_files/string/quote.slt covers three areas: timestamp formatting across units, fractional seconds, pre-1970 dates, NULLs and multi-row batches; session time zone handling for TIMESTAMP and TIMESTAMP_NTZ (including America/Los_Angeles); and dictionary-encoded string and timestamp inputs.

  • Unit tests in crates/spark/src/function/string/quote.rs check Volatility::Stable, dictionary unwrapping in coerce_types (including LargeUtf8 and Utf8View), and unsupported session time zone handling (TIMESTAMP_NTZ succeeds while zoned TIMESTAMP errors).

  • Expected results were verified against Apache Spark 4.2.0 using crates/sqllogictest/scripts/pyspark_slt_runner.py: all translatable records ran and passed on Spark 4.2.0, while 5 Arrow-only records without a Spark equivalent (sub-microsecond nanosecond truncation, a column time zone differing from the session zone, and dictionary-encoded timestamps) are marked skipif spark.
  • Are there any user-facing changes?

    Yes. quote on timestamp inputs now follows Spark's string output instead of Arrow's ISO 8601 format; millisecond and nanosecond timestamps are cast to microseconds first, so nanosecond inputs drop digits below a microsecond. There are no breaking changes to the public Rust API.

    AI Disclosure

    Grok Bot, working for dragonknightk, assisted with the changes, the description, and the verification. All content was reviewed by a human, and the submitter understands and can maintain these changes.

    Diff: 347 lines (+260 / -87) across 4 files Reviewer: andygrove Review duration: 7853m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 347 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.350
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #422"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.4% (MEDIUM) · Higher = larger blast radius
    42.4%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.6% · Safe to merge
    22.6%