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

Hive UDF pow limits the second input to integer when the first input is a decimal

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.12.0
    • 0.13.0
    • Types, UDF
    • None

    Description

      For example,

      hive> desc test;
      OK
      i                   	int                 	None                
      b                   	boolean             	None                
      d                   	double              	None                
      s                   	string              	None                
      dec                 	decimal(5,2)        	None                
      hive> explain select pow(dec, 2.5) from test;
      FAILED: SemanticException [Error 10014]: Line 1:15 Wrong arguments '2.5': No matching method for class org.apache.hadoop.hive.ql.udf.UDFPower with (decimal(5,2), double). Possible choices: _FUNC_(decimal(65,30), int)  _FUNC_(double, double)  _FUNC_(double, int)  
      

      This seems too restrictive. MySQL, on the other hand, supports fractional power as the second input.

      mysql> select pow(d, 2.5) from test;
      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    |       |
      +-------+--------------+------+-----+---------+-------+
      5 rows in set (0.00 sec)
      
      mysql> select pow(dd, 2.5) from test;
      +-------------------+
      | pow(dd, 2.5)      |
      +-------------------+
      | 2570.215713318881 |
      +-------------------+
      1 row in set (0.00 sec)
      

      Hive should also support this.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: