Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-18304

datediff() UDF returns a wrong result when dealing with a (date, string) input

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 2.3.0
    • Component/s: UDF
    • Labels:
      None

      Description

      for date type argument, datediff() use DateConverter to convert input to a java Date object,
      for example, a '2017-12-18' will get 2017-12-18T00:00:00.000+0800
      for string type argument, datediff() use TextConverter to convert a string to date,
      for '2012-01-01' we will get 2012-01-01T08:00:00.000+0800
      now, datediff() will return a number less than the real date diff
      we should use TextConverter to deal with date input too.

      reproduce:

      select datediff(cast('2017-12-18' as date), '2012-01-01'); --2177
      
      select datediff('2017-12-18', '2012-01-01'); --2178
      

        Attachments

        1. 0001.patch
          2 kB
          Hengyu Dai

          Activity

            People

            • Assignee:
              hengyu.dai Hengyu Dai
              Reporter:
              hengyu.dai Hengyu Dai
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: