Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-30766

Wrong truncation of old timestamps to hours and days

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.0.0
    • SQL
    • None

    Description

      The date_trunc() function incorrectly truncates old timestamps to HOUR and DAY:

      scala> import  org.apache.spark.sql.functions._
      import org.apache.spark.sql.functions._
      
      scala> :paste
      // Entering paste mode (ctrl-D to finish)
      
      Seq("0010-01-01 01:02:03.123456").toDF()
          .select($"value".cast("timestamp").as("ts"))
          .select(date_trunc("HOUR", $"ts").cast("string"))
          .show(false)
      
      // Exiting paste mode, now interpreting.
      
      +------------------------------------+
      |CAST(date_trunc(HOUR, ts) AS STRING)|
      +------------------------------------+
      |0010-01-01 01:30:17                 |
      +------------------------------------+
      

      the result must be 0010-01-01 01:00:00

      scala> :paste
      // Entering paste mode (ctrl-D to finish)
      
      Seq("0010-01-01 01:02:03.123456").toDF()
          .select($"value".cast("timestamp").as("ts"))
          .select(date_trunc("DAY", $"ts").cast("string"))
          .show(false)
      
      // Exiting paste mode, now interpreting.
      
      +-----------------------------------+
      |CAST(date_trunc(DAY, ts) AS STRING)|
      +-----------------------------------+
      |0010-01-01 23:30:17                |
      +-----------------------------------+
      

      the result must be 0010-01-01 00:00:00

      Attachments

        Issue Links

          Activity

            People

              maxgekk Max Gekk
              maxgekk Max Gekk
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: