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

Implicit casts to integers from decimals with higher precision sometimes allowed

    XMLWordPrintableJSON

Details

    Description

      The edge cases are handled incorrectly. E.g. DECIMAL(3,0) has range [-999,999] but can be implicitly cast to TINYINT with range [-128,127]. DECIMAL(2,0) and DECIMAL(4,0) are handled correctly.

      [tarmstrong-box.ca.cloudera.com:21000] > create table tinyints(x tinyint);Query: create table tinyints(x tinyint)
      
      Fetched 0 row(s) in 0.04s
      [tarmstrong-box.ca.cloudera.com:21000] > insert into tinyints values(CAST(99 as DECIMAL(2,0)));
      Query: insert into tinyints values(CAST(99 as DECIMAL(2,0)))
      Inserted 1 row(s) in 4.35s
      [tarmstrong-box.ca.cloudera.com:21000] > insert into tinyints values(CAST(1000 as DECIMAL(4,0)));
      Query: insert into tinyints values(CAST(1000 as DECIMAL(4,0)))
      ERROR: AnalysisException: Possible loss of precision for target table 'default.tinyints'.
      Expression 'cast(1000 as decimal(4,0))' (type: DECIMAL(4,0)) would need to be cast to TINYINT for column 'x'
      
      [tarmstrong-box.ca.cloudera.com:21000] > insert into tinyints values(CAST(999 as DECIMAL(3,0)));
      Query: insert into tinyints values(CAST(999 as DECIMAL(3,0)))
      Inserted 1 row(s) in 0.11s
      [tarmstrong-box.ca.cloudera.com:21000] > select * from tinyints;
      Query: select * from tinyints
      +-----+
      | x   |
      +-----+
      | 99  |
      | -25 |
      +-----+
      Fetched 2 row(s) in 0.33s
      

      Attachments

        Activity

          People

            tarmstrong Tim Armstrong
            tarmstrong Tim Armstrong
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: