[ 
https://issues.apache.org/jira/browse/IMPALA-12035?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17722010#comment-17722010
 ] 

ASF subversion and git services commented on IMPALA-12035:
----------------------------------------------------------

Commit e54c636385282a7f1453d022adc932438a49b032 in impala's branch 
refs/heads/master from Daniel Becker
[ https://gitbox.apache.org/repos/asf?p=impala.git;h=e54c63638 ]

IMPALA-12035: Impala accepts very big numbers but fails to store them correctly

The statement
 select cast(9999999999999999999999 as BIGINT)
correctly fails with the following message:
 ERROR: UDF ERROR: Decimal expression overflowed

However, if the number is much bigger, no error is produced:
 select 
cast(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
   as BIGINT)

The root cause of the problem is this:
- In the first case, the literal (9999999999999999999999) can fit into a
  DECIMAL and therefore is interpreted as such. This DECIMAL can't fit
  into a BIGINT, and this is checked, so the cast fails.

- In the second case, the literal can't fit in a DECIMAL, so it is
  interpreted as a DOUBLE instead. This is not unreasonable as it fits
  in the range of DOUBLE, although of course there may be loss of
  precision. However, there is no check when casting from DOUBLE to
  BIGINT, and because the value is out of range for BIGINT this invokes
  undefined behaviour (probably leading to an incorrect value).

This change adds checks to casts
 - from floating point types to integer types
 - from double to float

These casts can invoke undefined behaviour in C++ and were not checked
before this change.

If the checks fail, an ERROR is raised.

Testing:
 - Added unit tests in expr-tests.cc for the new checks

Change-Id: Ibd97dee3c793a5caa95b1fe5d22b27b8c0f8275d
Reviewed-on: http://gerrit.cloudera.org:8080/19856
Reviewed-by: Impala Public Jenkins <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>


> Impala accepts very big numbers but fails to store them correctly
> -----------------------------------------------------------------
>
>                 Key: IMPALA-12035
>                 URL: https://issues.apache.org/jira/browse/IMPALA-12035
>             Project: IMPALA
>          Issue Type: Bug
>            Reporter: Bakai Ádám
>            Assignee: Daniel Becker
>            Priority: Major
>
> I tried  to insert rows very big bigints, and it worked as expected with big 
> integers (error message, no new row stored), but it didn’t work as expected 
> with ridiculously big integers( no error message, stored incorrect value). 
> Here are the commands used:
> {code:java}
> drop TABLE my_first_table2;
> CREATE TABLE my_first_table2
> (
>   id BIGINT,
>   name STRING,
>   PRIMARY KEY(id)
> );
> INSERT INTO my_first_table2 VALUES (cast(9 as BIGINT), "sarah");
> -- this works just fine as expected
> INSERT INTO my_first_table2 VALUES (cast(9999999999999999999999 as BIGINT), 
> "sarah");
> -- ERROR: UDF ERROR: Decimal expression overflowed which is expected since it 
> is over bigint max value (source: 
> https://impala.apache.org/docs/build/plain-html/topics/impala_bigint.html#:~:text=Range%3A%20%2D9223372036854775808%20..,9223372036854775807.
>  )
> INSERT INTO my_first_table2 VALUES 
> (cast(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
>  as BIGINT), "sarah");
> -- this succeeds and doesn't throw the same error as the previous command 
> which is concerning
> select * from my_first_table2;
> -- there are two rows in the table, and the id is incorrect in one of them  
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to