Hive
  1. Hive
  2. HIVE-5825

Case statement type checking too restrictive for parameterized types

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.13.0
    • Component/s: UDF
    • Labels:
      None

      Description

      explain select
      case when (key = '0') then 123.456BD else 0.0BD end
      from src limit 2

      FAILED: SemanticException [Error 10016]: Line 3:44 Argument type mismatch '0.0BD': The expression after ELSE should have the same type as those after THEN: "decimal(6,3)" is expected but "decimal(1,0)" is found

      The return type checking is too strict and won't allow different decimal types to be returned if they are not the exact same type (precision/scale). There are similar issues with char/varchar length, but even in the general case it seems odd that you wouldn't be able to specify 1 and 0.0 in the same case statement.

      I would propose setting returnOIResolver so that it is able to convert the return values to common type.

        Activity

        Jason Dere created issue -
        Hide
        Jason Dere added a comment -

        Patch attached. case/when UDFs now allow differing types and will determine a common type to use if the types are different.

        Show
        Jason Dere added a comment - Patch attached. case/when UDFs now allow differing types and will determine a common type to use if the types are different.
        Jason Dere made changes -
        Field Original Value New Value
        Attachment HIVE-5825.1.patch [ 12614000 ]
        Jason Dere made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Hide
        Hive QA added a comment -

        Overall: +1 all checks pass

        Here are the results of testing the latest attachment:
        https://issues.apache.org/jira/secure/attachment/12614000/HIVE-5825.1.patch

        SUCCESS: +1 4608 tests passed

        Test results: http://bigtop01.cloudera.org:8080/job/PreCommit-HIVE-Build/320/testReport
        Console output: http://bigtop01.cloudera.org:8080/job/PreCommit-HIVE-Build/320/console

        Messages:

        Executing org.apache.hive.ptest.execution.PrepPhase
        Executing org.apache.hive.ptest.execution.ExecutionPhase
        Executing org.apache.hive.ptest.execution.ReportingPhase
        

        This message is automatically generated.

        ATTACHMENT ID: 12614000

        Show
        Hive QA added a comment - Overall : +1 all checks pass Here are the results of testing the latest attachment: https://issues.apache.org/jira/secure/attachment/12614000/HIVE-5825.1.patch SUCCESS: +1 4608 tests passed Test results: http://bigtop01.cloudera.org:8080/job/PreCommit-HIVE-Build/320/testReport Console output: http://bigtop01.cloudera.org:8080/job/PreCommit-HIVE-Build/320/console Messages: Executing org.apache.hive.ptest.execution.PrepPhase Executing org.apache.hive.ptest.execution.ExecutionPhase Executing org.apache.hive.ptest.execution.ReportingPhase This message is automatically generated. ATTACHMENT ID: 12614000
        Hide
        Xuefu Zhang added a comment -

        Jason Dere Thanks for working on this. Please provide RB link when the patch is ready to be reviewed.

        Show
        Xuefu Zhang added a comment - Jason Dere Thanks for working on this. Please provide RB link when the patch is ready to be reviewed.
        Hide
        Jason Dere added a comment -
        Show
        Jason Dere added a comment - RB at https://reviews.apache.org/r/15607/
        Hide
        Xuefu Zhang added a comment -

        +1

        Show
        Xuefu Zhang added a comment - +1
        Hide
        Xuefu Zhang added a comment -

        Patch committed to trunk. Thank Jason for the contribution.

        Show
        Xuefu Zhang added a comment - Patch committed to trunk. Thank Jason for the contribution.
        Xuefu Zhang made changes -
        Status Patch Available [ 10002 ] Resolved [ 5 ]
        Fix Version/s 0.13.0 [ 12324986 ]
        Resolution Fixed [ 1 ]
        Hide
        Doug Sedlak added a comment -

        Here is a possible instance of this issue, can you run this case to see it is addressed by this JIRA in Hive 13? Thanks!

        Create a standard textual linefeed delimited HDFS file with 1 row and 1 column, with contents like:
        FEB

        Issue the following DDL against the above data, filling in location [hdfs_path] appropriately:
        CREATE EXTERNAL TABLE `HIVE_5825` ( month VARCHAR(3) ) STORED AS TEXTFILE LOCATION [hdfs_path]

        Issue the following SQL, which fails in Hive 12:
        select case when COUNT > COUNT(`month`) then ' ' else MIN(`month`) end from HIVE_5825

        The Hive 12 failure message generated is:
        java.sql.SQLException: Error while processing statement: FAILED: SemanticException [Error 10016]: Line 1:57 Argument type mismatch '`month`': The expression after ELSE should have the same type as those after THEN: "string" is expected but "varchar(3)" is found

        Show
        Doug Sedlak added a comment - Here is a possible instance of this issue, can you run this case to see it is addressed by this JIRA in Hive 13? Thanks! Create a standard textual linefeed delimited HDFS file with 1 row and 1 column, with contents like: FEB Issue the following DDL against the above data, filling in location [hdfs_path] appropriately: CREATE EXTERNAL TABLE `HIVE_5825` ( month VARCHAR(3) ) STORED AS TEXTFILE LOCATION [hdfs_path] Issue the following SQL, which fails in Hive 12: select case when COUNT > COUNT(`month`) then ' ' else MIN(`month`) end from HIVE_5825 The Hive 12 failure message generated is: java.sql.SQLException: Error while processing statement: FAILED: SemanticException [Error 10016] : Line 1:57 Argument type mismatch '`month`': The expression after ELSE should have the same type as those after THEN: "string" is expected but "varchar(3)" is found
        Hide
        Jason Dere added a comment -

        Hi Doug Sedlak, yes that query looks like it compiles/runs without error

        Show
        Jason Dere added a comment - Hi Doug Sedlak , yes that query looks like it compiles/runs without error

          People

          • Assignee:
            Jason Dere
            Reporter:
            Jason Dere
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development