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

Hive standard avg UDAF returns double as the return type for some exact input types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Patch Available
    • Major
    • Resolution: Unresolved
    • 0.12.0
    • None
    • Types, UDF
    • None
    • Incompatible change

    Description

      For standard, no-partial avg result, hive currently returns double as the result type.

      hive> desc test;
      OK
      d                   	int                 	None                
      Time taken: 0.051 seconds, Fetched: 1 row(s)
      hive> explain select avg(`d`) from test;  
      ...
            Reduce Operator Tree:
              Group By Operator
                aggregations:
                      expr: avg(VALUE._col0)
                bucketGroup: false
                mode: mergepartial
                outputColumnNames: _col0
                Select Operator
                  expressions:
                        expr: _col0
                        type: double
      

      However, exact types including integers and decimal should yield exact type. Here is what MySQL does:

      mysql> desc test;
      +-------+--------------+------+-----+---------+-------+
      | Field | Type         | Null | Key | Default | Extra |
      +-------+--------------+------+-----+---------+-------+
      | i     | int(11)      | YES  |     | NULL    |       |
      | b     | tinyint(1)   | YES  |     | NULL    |       |
      | d     | double       | YES  |     | NULL    |       |
      | s     | varchar(5)   | YES  |     | NULL    |       |
      | dd    | decimal(5,2) | YES  |     | NULL    |       |
      +-------+--------------+------+-----+---------+-------+
      mysql> create table test62 as select avg(i) from test;
      mysql> desc test62;
      +-------+---------------+------+-----+---------+-------+
      | Field | Type          | Null | Key | Default | Extra |
      +-------+---------------+------+-----+---------+-------+
      | avg(i) | decimal(14,4) | YES  |     | NULL    |       |
      +-------+---------------+------+-----+---------+-------+
      1 row in set (0.00 sec)
      

      Attachments

        1. HIVE-5878.1.patch
          21 kB
          Xuefu Zhang
        2. HIVE-5878.patch
          2 kB
          Xuefu Zhang

        Issue Links

          Activity

            People

              xuefuz Xuefu Zhang
              xuefuz Xuefu Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: