feat: add GetTimestamp support via codegen dispatcher#4454
Open
andygrove wants to merge 1 commit into
Open
Conversation
Routes Spark's GetTimestamp expression through the existing codegen dispatcher so that to_timestamp(s, fmt), to_date(s, fmt), to_timestamp_ntz(s, fmt), and try_to_timestamp(s, fmt) execute natively in Comet instead of falling back to Spark. GetTimestamp depends on Spark's full SimpleDateFormat / TimestampFormatter parsing semantics, including time parser policies, ANSI mode, timezone handling, and locale awareness. datafusion-spark has no equivalent function. The codegen dispatcher runs Spark's own doGenCode inside the Comet pipeline, which guarantees identical behavior across Spark 3.4, 3.5, and 4.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #.
Rationale for this change
Spark's
GetTimestampexpression powers the format-based variants ofto_timestamp(s, fmt),to_date(s, fmt),to_timestamp_ntz(s, fmt), andtry_to_timestamp(s, fmt). Until now Comet had no serde for it, so any plan containing those calls fell back to Spark for the enclosing operator.A native re-implementation would have to mirror Spark's full
SimpleDateFormat/TimestampFormatterparsing semantics, including time parser policy (LEGACY/CORRECTED/EXCEPTION), ANSI failure modes, timezone handling, and locale awareness. The upstreamdatafusion-sparkcrate has no equivalent function, so a from-scratch native implementation would be a large project unlikely to be 100% Spark-compatible without significant follow-up work.The closely-related
ToUnixTimestampalready uses the codegen dispatcher (CometCodegenDispatch) to run Spark's owndoGenCodeinside the Comet pipeline. WiringGetTimestampthe same way produces bit-exact results today and works uniformly across Spark 3.4, 3.5, and 4.0.What changes are included in this PR?
object CometGetTimestamp extends CometCodegenDispatch[GetTimestamp]inspark/src/main/scala/org/apache/comet/serde/datetime.scala.classOf[GetTimestamp] -> CometGetTimestampin thetemporalExpressionsmap inQueryPlanSerde.scala.spark/src/test/resources/sql-tests/expressions/datetime/get_timestamp.sqlcoversto_timestamp(s, fmt),to_date(s, fmt),to_timestamp_ntz(s, fmt),try_to_timestamp(s, fmt), NULLs, parse errors, column references, literals, and column-as-format.spark/src/test/resources/sql-tests/expressions/datetime/get_timestamp_ansi.sqlcovers ANSI mode error throwing withexpect_error(CANNOT_PARSE_TIMESTAMP)and the non-throwingtry_to_timestampfallback.The
implement-comet-expressionskill was used to scaffold the implementation.How are these changes tested?
Both new test files pass. The existing
to_timestamp_*,try_to_timestamp_*, and related SQL file tests continue to pass under the same profile (12 tests total).