Skip to content

[Bug] make_timestamp does not throw under spark.sql.ansi.enabled=true #4679

Closed

Description

@andygrove

Describe the bug

MakeTimestamp honours spark.sql.ansi.enabled in Spark 3.4 / 3.5 / 4.0: under ANSI mode it throws on an invalid (year, month, day, hour, min, sec[, timezone]) argument (ansiDateTimeArgumentOutOfRange / invalidFractionOfSecondError), and returns NULL only when ANSI is disabled.

The Comet wiring (CometMakeTimestamp, spark/src/main/scala/org/apache/comet/serde/datetime.scala) does not check failOnError. CometMakeTimestamp is a bare CometCodegenDispatch[MakeTimestamp] with no ANSI gating, so under ANSI mode Comet returns NULL where Spark would throw.

This is the same shape as the make_date ANSI divergence captured in #4451 (make_date_ansi.sql).

Steps to reproduce

With spark.sql.ansi.enabled=true, evaluate make_timestamp with an out-of-range argument (for example an invalid month or a seconds value outside the valid fraction range). Spark throws; Comet returns NULL.

Expected behavior

Under spark.sql.ansi.enabled=true, Comet should match Spark and throw on invalid arguments. The support level should be gated appropriately until a fix lands, and a make_timestamp_ansi.sql regression test should be added once the fix is in place (analogous to make_date_ansi.sql).

Additional context

Split out from #4502 (item 4), surfaced by the audit-comet-expression skill run in #4448. Cross-references #4451.

Activity

  1. self-assigned this
    on Jun 19, 2026
  2. added
    priority:criticalData corruption, silent wrong results, security issues
    and removed on Jun 22, 2026
  3. marvelshan commented on Jun 27, 2026

    @marvelshan
    Contributor

    Sorry! @comphead I didn't notice that you'd self-assigned it

  4. andygrove commented on Jun 29, 2026

    @andygrove
    MemberAuthor

    Verified empirically on Spark 4.1 (ANSI on by default): make_timestamp already throws under ANSI for invalid arguments, matching Spark, so this is not a divergence on the current codebase.

    Root cause of the stale report: CometMakeTimestamp is a codegen-dispatch serde, and spark.comet.exec.scalaUDF.codegen.enabled defaults to true. The dispatcher compiles Spark's own MakeTimestamp.doGenCode into the per-batch kernel, so under ANSI it produces the same throw site as Spark, and the JVM-UDF path propagates the exception (native/spark-expr/src/jvm_udf/mod.rs check_exception) rather than returning NULL. No failOnError gating is needed.

    This was resolved by #4417 (merged 2026-05-26), which added the codegen-dispatch date/time path and the make_timestamp_ansi.sql regression test, predating this issue (filed 2026-06-18); the audit that split this out from #4502 did not account for #4417.

    Confirmed passing:

    • make_timestamp_ansi.sql (month/day/hour out-of-range throw, plus a sentinel checkSparkAnswerAndOperator query proving native execution, so the throws are not vacuous Spark fallbacks).
    • A local probe of the seconds cases this issue called out: make_timestamp(..., 61) throws SecondOfMinute and make_timestamp(..., 60.5) throws the fraction-of-second error, both matching Spark, with the sentinel confirming native execution.

    Closing as already resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions