Hive
  1. Hive
  2. HIVE-5800

Hive is inconsistent when handling strings in arithmetic operations

    Details

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

      Description

      Currently Hive is inconsistent in dealing with strings involved in arithmetic operations. For instance:

      hive> desc test;
      OK
      i                   	int                 	None                
      b                   	boolean             	None                
      d                   	double              	None                
      s                   	string              	None                
      dec                 	decimal(5,2)        	None                
      Hive> explain select dec/s from test;
      ...
      STAGE PLANS:
        Stage: Stage-1
          Map Reduce
            Alias -> Map Operator Tree:
              test 
                TableScan
                  alias: test
                  Select Operator
                    expressions:
                          expr: (dec / s)
                          type: decimal(65,30)
                    outputColumnNames: _col0
      hive> explain select dec*s from test;
      ...
      STAGE PLANS:
        Stage: Stage-1
          Map Reduce
            Alias -> Map Operator Tree:
              test 
                TableScan
                  alias: test
                  Select Operator
                    expressions:
                          expr: (dec * s)
                          type: double
      

      MySQL consistently treats string in arithmetic operations as double (not an exact numeric type) and derives the operator result type accordingly. Hive should also be consistent.

      
      

        Activity

        Xuefu Zhang created issue -
        Xuefu Zhang made changes -
        Field Original Value New Value
        Description Currently Hive is inconsistent in dealing with strings involved in arithmetic operations. For instance:
        {code}
        hive> desc test;
        OK
        i int None
        b boolean None
        d double None
        s string None
        dec decimal(5,2) None
        Hive> explain select dec/s from test;
        ...
        STAGE PLANS:
          Stage: Stage-1
            Map Reduce
              Alias -> Map Operator Tree:
                test
                  TableScan
                    alias: test
                    Select Operator
                      expressions:
                            expr: (dec / s)
                            type: decimal(65,30)
                      outputColumnNames: _col0
        hive> explain select dec*s from test;
        ...
        STAGE PLANS:
          Stage: Stage-1
            Map Reduce
              Alias -> Map Operator Tree:
                test
                  TableScan
                    alias: test
                    Select Operator
                      expressions:
                            expr: (dec * s)
                            type: double
        {code}
        MySQL consistently treats string in arithmetic operations as double and derives the operator result type accordingly. Hive should also be consistent.
        {code}

        {code}
        Currently Hive is inconsistent in dealing with strings involved in arithmetic operations. For instance:
        {code}
        hive> desc test;
        OK
        i int None
        b boolean None
        d double None
        s string None
        dec decimal(5,2) None
        Hive> explain select dec/s from test;
        ...
        STAGE PLANS:
          Stage: Stage-1
            Map Reduce
              Alias -> Map Operator Tree:
                test
                  TableScan
                    alias: test
                    Select Operator
                      expressions:
                            expr: (dec / s)
                            type: decimal(65,30)
                      outputColumnNames: _col0
        hive> explain select dec*s from test;
        ...
        STAGE PLANS:
          Stage: Stage-1
            Map Reduce
              Alias -> Map Operator Tree:
                test
                  TableScan
                    alias: test
                    Select Operator
                      expressions:
                            expr: (dec * s)
                            type: double
        {code}
        MySQL consistently treats string in arithmetic operations as double (not an exact numeric type) and derives the operator result type accordingly. Hive should also be consistent.
        {code}

        {code}
        Hide
        Xuefu Zhang added a comment -

        This is addressed via HIVE-5856.

        hive> explain select dec/s from test;
        ...
        
        STAGE PLANS:
          Stage: Stage-1
            Map Reduce
              Alias -> Map Operator Tree:
                test 
                  TableScan
                    alias: test
                    Select Operator
                      expressions:
                            expr: (dec / s)
                            type: double
                      outputColumnNames: _col0
        
        Show
        Xuefu Zhang added a comment - This is addressed via HIVE-5856 . hive> explain select dec/s from test; ... STAGE PLANS: Stage: Stage-1 Map Reduce Alias -> Map Operator Tree: test TableScan alias: test Select Operator expressions: expr: (dec / s) type: double outputColumnNames: _col0
        Hide
        Xuefu Zhang added a comment -

        Typo above. via HIVE-5356.

        Show
        Xuefu Zhang added a comment - Typo above. via HIVE-5356 .
        Xuefu Zhang made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 0.13.0 [ 12324986 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        27d 15h 24m 1 Xuefu Zhang 09/Dec/13 21:38

          People

          • Assignee:
            Xuefu Zhang
            Reporter:
            Xuefu Zhang
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development