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

Comparison of timestamp fails if only date part is provided.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.2.0
    • Component/s: Hive, UDF
    • Labels:
      None

      Description

      Summary : If a query needs to compare two timestamp with one timestamp provided in "YYYY-MM-DD" format, skipping the time part, it returns incorrect result.

      Steps to reproduce :

      1. Start a hive-cli.
      2. Fire up the query -> select cast("2016-12-31 12:00:00" as timestamp) > "2016-12-30";
      3. Expected result : true
      4. Actual result : NULL

      Detailed description :
      If two primitives of different type needs to compared, a common comparator type is chosen. Prior to 2.1, Common type Text was chosen to compare Timestamp type and Text type.

      In version 2.1, Common type Timestamp is chosen to compare Timestamp type and Text type. This leads to converting Text type (YYYY-MM-DD) into java.sql.Timestamp which throws exception saying the input is not in proper format. The exception is suppressed and a null is returned.

      Code below from org.apache.hadoop.hive.ql.exec.FunctionRegistry

      if (pgA == PrimitiveGrouping.STRING_GROUP && pgB == PrimitiveGrouping.DATE_GROUP) {
            return b;
          }
          // date/timestamp is higher precedence than String_GROUP
          if (pgB == PrimitiveGrouping.STRING_GROUP && pgA == PrimitiveGrouping.DATE_GROUP) {
            return a;
          }
      

      The bug was introduced in HIVE-13381

        Attachments

        1. HIVE-15291.1.patch
          0.8 kB
          Dhiraj Kumar
        2. HIVE-15291.2.patch
          2 kB
          Dhiraj Kumar
        3. HIVE-15291.3.patch
          2 kB
          Dhiraj Kumar
        4. HIVE-15291.4.patch
          4 kB
          Dhiraj Kumar

          Issue Links

            Activity

              People

              • Assignee:
                dhiraj.kumar Dhiraj Kumar
                Reporter:
                dhiraj.kumar Dhiraj Kumar
              • Votes:
                3 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: