Skip to content

test: promote try_to_date/try_to_timestamp SQL tests to native coverage#4973

Open
u70b3 wants to merge 2 commits into
apache:mainfrom
u70b3:test/promote-try-datetime-native
Open

test: promote try_to_date/try_to_timestamp SQL tests to native coverage#4973
u70b3 wants to merge 2 commits into
apache:mainfrom
u70b3:test/promote-try-datetime-native

Conversation

@u70b3

@u70b3 u70b3 commented Jul 18, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Closes #4556.

Rationale for this change

Investigation of #4556 showed that the reported fallback of try_to_date / try_to_timestamp does not exist on current main. All four functions (to_date, to_timestamp, and their try_ variants) are RuntimeReplaceable and are expanded by Spark's ReplaceExpressions before Comet sees the plan. In non-ANSI mode the expansions are identical between the try_ and non-try_ forms:

  • no format: Cast(..., EvalMode.LEGACY) (EvalMode.fromBoolean(false) is LEGACY, not TRY)
  • with format: Cast(GetTimestamp(..., failOnError = false))

Comet already accelerates both building blocks (native Cast; GetTimestamp via the codegen dispatcher since #4454), so there is no serde gap to close. The 15 spark_answer_only markers in try_datetime.sql were conservative annotations introduced in #4555 — that mode only compares answers without asserting native execution — and predate the GetTimestamp dispatch support.

What changes are included in this PR?

  • try_datetime.sql: flip the 15 try_to_date / try_to_timestamp queries from spark_answer_only to the default query mode (native coverage + answer check). The 3 try_make_timestamp markers are unchanged; they belong to try_make_timestamp returns wrong values for invalid inputs instead of NULL #4554.
  • docs/.../expressions.md: support matrix entries for try_to_date / try_to_timestamp 🔜 -> ✅.
  • docs/.../expression-audits/datetime_funcs.md: add audit entries for both functions.

How are these changes tested?

./mvnw test -Pspark-4.1 -Dtest=none \
  -Dsuites="org.apache.comet.CometSqlFileTestSuite try_datetime" -DwildcardSuites=none

passes with all 15 queries executing fully native (the default query mode asserts an all-Comet plan and compares answers against Spark). This directly verifies the issue's acceptance criteria: native execution with NULL-on-invalid-input behavior matching Spark.

…verage

Investigation of apache#4556 showed the reported fallback does not exist on
current main: in non-ANSI mode Spark's ReplaceExpressions expands
try_to_date/try_to_timestamp to the exact same tree as to_date/
to_timestamp (Cast(..., LEGACY) or GetTimestamp(failOnError=false)),
which Comet already accelerates. The 15 spark_answer_only markers were
conservative annotations from apache#4555 (that mode only compares answers
without asserting native execution), not measured fallbacks.

Flip the 15 try_to_date/try_to_timestamp queries to default query mode
(native coverage + answer check), keeping the 3 try_make_timestamp
markers which belong to apache#4554. Verified on Spark 4.1:
CometSqlFileTestSuite try_datetime passes with all queries running
fully native.

Also update the expression support matrix (try_to_date/try_to_timestamp
🔜 -> ✅) and add audit entries.

Closes apache#4556
@u70b3
u70b3 force-pushed the test/promote-try-datetime-native branch from 9ae7f62 to b8b08e5 Compare July 18, 2026 04:32

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending CI. Thanks @u70b3

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

try_to_date / try_to_timestamp fall back to Spark even though to_date / to_timestamp are accelerated

2 participants