Skip to content

Implement Spark-compatible CAST from timestamp to numeric types #352

Closed

Description

@andygrove

What is the problem the feature request solves?

We need to implement CAST from timestamp to numeric to match Spark's behavior.

We can break this into multiple issues if needed.

The following example is casting timestamp c to different numeric types.

scala> spark.sql("select c, cast(c as boolean), cast(c as byte), cast(c as short), cast(c as int), cast(c as long), cast(c as decimal) from t3").show
+-------------------+----+---+-----+----------+----------+----------+
|                  c|   c|  c|    c|         c|         c|         c|
+-------------------+----+---+-----+----------+----------+----------+
|2024-01-01 00:00:00|true|-16|25328|1704092400|1704092400|1704092400|
|2023-12-12 00:00:00|true|-16| 1264|1702364400|1702364400|1702364400|
+-------------------+----+---+-----+----------+----------+----------+

Describe the potential solution

No response

Additional context

No response

Activity

  1. andygrove commented on Apr 30, 2024

    @andygrove
    MemberAuthor

    Also, Spark returns timestamp in seconds and Comet returns timestamp in microseconds.

    // input: 2023-12-31 10:00:00.0, expected: 1.7040456E9, actual: 1.7040456E15
    
  2. andygrove commented on Jun 16, 2025

    @andygrove
    MemberAuthor

    Closing this since it seems like an edge case that users should not be using

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions