Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-2233

Impala should not choose a function signature that results in loss of precision

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • Impala 2.1, Impala 2.2
    • Impala 2.3.0
    • None

    Description

      When arguments to a function require casting because they don't match an exact function signature, the chosen signature should not result in loss of precision of the input arguments. (If loss of precision is unavoidable an error or warning should be given.)

      Example of current behavior

      Query: select greatest(0, cast('99999.8888' as decimal(30, 10)))
      +---------------------------------------------------+
      | greatest(0, cast('99999.8888' as decimal(30,10))) |
      +---------------------------------------------------+
      | 99999.890625                                      |
      +---------------------------------------------------+
      
      Query: create table foo as select greatest(0, cast('99999.8888' as decimal(30, 10)))
      +-------------------+
      | summary           |
      +-------------------+
      | Inserted 1 row(s) |
      +-------------------+
      Fetched 1 row(s) in 3.72s
      
      Query: describe foo
      +------+-------+---------+
      | name | type  | comment |
      +------+-------+---------+
      | _c0  | float |         |
      +------+-------+---------+
      

      Postgres and mysql both preserve the precision

      mysql> select greatest(0, cast('99999.8888' as decimal(30, 10)));
      +----------------------------------------------------+
      | greatest(0, cast('99999.8888' as decimal(30, 10))) |
      +----------------------------------------------------+
      |                                   99999.8888000000 |
      +----------------------------------------------------+
      
      mysql> create table foo as select greatest(0, cast('99999.8888' as decimal(30, 10)));
      Query OK, 1 row affected (0.02 sec)
      Records: 1  Duplicates: 0  Warnings: 0
      
      mysql> desc foo;
      +----------------------------------------------------+----------------+------+-----+--------------+-------+
      | Field                                              | Type           | Null | Key | Default      | Extra |
      +----------------------------------------------------+----------------+------+-----+--------------+-------+
      | greatest(0, cast('99999.8888' as decimal(30, 10))) | decimal(30,10) | NO   |     | 0.0000000000 |       |
      +----------------------------------------------------+----------------+------+-----+--------------+-------+
      

      Attachments

        Issue Links

          Activity

            People

              tarmstrong Tim Armstrong
              caseyc casey
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: