Files
impala/testdata/workloads/functional-query/queries/QueryTest/decimal-insert-overflow-exprs.test
wzhou-code 410c3e79e4 IMPALA-10564: Return error when inserting an invalid decimal value
When using CTAS statements or INSERT-SELECT statements to insert rows to
table with decimal columns, Impala insert NULL for overflowed decimal
values, instead of returning error. This issue happens when the data
expression for the decimal column in SELECT sub-query consists at least
one alias.
This issue is similar as IMPALA-6340, but IMPALA-6340 only fixed the
issue for the cases with the data expression for the decimal columns as
constants.

This patch fixed the issue by calling RuntimeState::CheckQueryState()
in the end of HdfsTableWriter::AppendRows() and KuduTableSink::Send().
If there is an invalid decimal error, the query will be failed without
inserting NULL for decimal column.
We did not change the behaviour for decimal_v1. NULL will be inserted
to the table for invalid decimal values with warning message.

Tests:
 - Added unit-tests for INSERT-SELECT and CTAS statements with
   overflowed decimal values to be inserted into tables. The
   overflowed decimal values are expressed as a constant expression,
   or as an expression with aliases.
   Also added cases to verify behaviour of decimal_v1 is unchanged.
 - Passed exhaustive tests.

Change-Id: I64ce4ed194af81ef06401ffc1124e12f05b8da98
Reviewed-on: http://gerrit.cloudera.org:8080/17168
Reviewed-by: Thomas Tauber-Marshall <tmarshall@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
2021-03-23 22:52:38 +00:00

117 lines
4.2 KiB
Plaintext

====
---- QUERY
# Verify that decimal value, which is expressed with constant decimal expression and its
# value is not overflowed, is inserted into the table.
set decimal_v2=true;
insert into table overflowed_decimal_tbl_1
select 1, cast(cast(65496456343.9565 as decimal (28,7))*44658*2.111
as decimal (28,10));
---- RESULTS
: 1
====
---- QUERY
# Verify that decimal value, which is expressed with decimal expression with one
# alias and its value is not overflowed, is inserted into the table.
set decimal_v2=true;
insert into table overflowed_decimal_tbl_1
select 2, cast(a*44658*2.111 as decimal (28,10)) from
(select cast(65496456.9565 as decimal (28,7)) as a) q;
---- RESULTS
: 1
====
---- QUERY
# Verify that decimal value, which is expressed with decimal expression with three
# aliases and its value is not overflowed, is inserted into the table.
set decimal_v2=true;
insert into table overflowed_decimal_tbl_1
select 3, cast(a*b*c as decimal (28,10)) from
(select cast(65496456.9565 as decimal (28,7)) as a,
cast(44658 as decimal (28,7)) as b,
cast(2.111 as decimal (28,7)) as c) q;
---- RESULTS
: 1
====
---- QUERY
# Verify that overflow behaviour of decimal_v1 is unchanged.
# Verify decimal value, which is expressed with constant decimal expression
# and its value is overflowed, is inserted into the table as NULL when
# decimal_v2 is set as false.
set decimal_v2=false;
insert into table overflowed_decimal_tbl_1
select 4, cast(cast(654964569154.9565 as decimal (28,7))*44658554984*2.111
as decimal (28,10));
select count(*) from overflowed_decimal_tbl_1 where d_28 is null;
---- RESULTS
1
====
---- QUERY
# Verify that overflow behaviour of decimal_v1 is unchanged.
# Verify that decimal value, which is expressed with decimal expression with one
# alias and its value is overflowed, is inserted into the table as NULL when
# decimal_v2 is set as false.
set decimal_v2=false;
insert into table overflowed_decimal_tbl_1
select 5, cast(a*44658554984*2.111 as decimal (28,10)) from
(select cast(654964569154.9565 as decimal (28,7)) as a) q;
select count(*) from overflowed_decimal_tbl_1 where d_28 is null;
---- RESULTS
2
====
---- QUERY
# Verify that overflow behaviour of decimal_v1 is unchanged.
# Verify that decimal value, which is expressed with decimal expression with three
# alias and its value is overflowed, is inserted into the table as NULL when
# decimal_v2 is set as false.
set decimal_v2=false;
insert into table overflowed_decimal_tbl_1
select 6, cast(a*b*c as decimal (28,10)) from
(select cast(654964569154.9565 as decimal (28,7)) as a,
cast(44658554984 as decimal (28,7)) as b,
cast(2.111 as decimal (28,7)) as c) q;
select count(*) from overflowed_decimal_tbl_1 where d_28 is null;
---- RESULTS
3
====
---- QUERY
# Verify that decimal value, which is expressed with constant decimal expression
# and its value is overflowed, cause query aborted with an error.
set decimal_v2=true;
insert into table overflowed_decimal_tbl_1
select 7, cast(cast(654964569154.9565 as decimal (28,7))*44658554984*2.111
as decimal (28,10));
---- CATCH
Decimal expression overflowed
====
---- QUERY
# Verify that decimal value, which is expressed with decimal expression with one
# alias and its value is overflowed, cause query aborted with an error.
set decimal_v2=true;
insert into table overflowed_decimal_tbl_1
select 8, cast(a*44658554984*2.111 as decimal (28,10)) from
(select cast(654964569154.9565 as decimal (28,7)) as a) q;
---- CATCH
Decimal expression overflowed
====
---- QUERY
# Verify that decimal value, which is expressed with decimal expression with three
# aliases and its value is overflowed, cause query aborted with an error.
set decimal_v2=true;
insert into table overflowed_decimal_tbl_1
select 9, cast(a*b*c as decimal (28,10)) from
(select cast(654964569154.9565 as decimal (28,7)) as a,
cast(44658554984 as decimal (28,7)) as b,
cast(2.111 as decimal (28,7)) as c) q;
---- CATCH
Decimal expression overflowed
====
---- QUERY
# Verify that decimal value, which is expressed with selection from another table
# and its value is overflowed, cause query aborted with an error.
set decimal_v2=true;
insert into table overflowed_decimal_tbl_2
select i, cast(d_28*d_28*d_28 as decimal (28,10))
from overflowed_decimal_tbl_1 where d_28 is not null;
---- CATCH
Decimal expression overflowed
====