apache / doris

Apache Doris is an easy-to-use, high performance and unified analytics database.
https://doris.apache.org
Apache License 2.0
12.77k stars 3.29k forks source link

[Bug] cast decimal(6,3) to decimal(6,4) failed #31522

Open zxealous opened 8 months ago

zxealous commented 8 months ago

Search before asking

Version

2.0.5

What's Wrong?

case:

create table test_cast_decimal_in_table (
  k1 tinyint, 
  k2 decimal(6, 3) NULL, 
  k3 char(5) NULL, 
  k4 date NULL, 
  k5 datetime NULL, 
  k6 double sum
) engine = olap distributed by hash(k1) buckets 2 properties (
  "replication_allocation" = "tag.location.default: 1", 
  "storage_type" = "column"
);

insert into test_cast_decimal_in_table values(1, 123.23, 'a', '2019-01-01', '2019-01-01 01:00:00', 6.6);
insert into test_cast_decimal_in_table values(1, 1.1267, 'a', '2019-01-01', '2019-01-01 01:00:00', 6.6);
insert into test_cast_decimal_in_table values(1, 123.1234, 'a', '2019-01-01', '2019-01-01 01:00:00', 6.6);

select cast(k2 as decimal(6, 4))from test_cast_decimal_in_table order by k2 limit 1

the case on 2.0.5:

MySQL [test]> select cast(k2 as decimal(6, 4))from test_cast_decimal_in_table order by k2 limit 1;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.81.85.90)[CANCELLED][E-124][E-124] Arithmetic overflow

    0#  doris::get_stack_trace[abi:cxx11](int) at /home/disk2/zcy/baidu/bdg/doris/PALO-2.0/be/src/util/stack_util.cpp:51
    1#  doris::Exception::Exception(int, std::basic_string_view<char, std::char_traits<char> >) at /home/disk2/zcy/baidu/bdg/doris/PALO-2.0/be/src/common/exception.cpp:27
    2#  auto doris::vectorized::convert_decimal_cols<doris::vectorized::DataTypeDecimal<doris::vectorized::Decimal<int> >, doris::vectorize

the case on master is right:

MySQL [test]> select cast(k2 as decimal(6, 4))from test_cast_decimal_in_table order by k2 limit 1;
+-----------------------------+
| cast(k2 as DECIMALV3(6, 4)) |
+-----------------------------+
|                      1.1270 |
+-----------------------------+
1 row in set (0.033 sec)

What You Expected?

work well

How to Reproduce?

No response

Anything Else?

No response

Are you willing to submit PR?

Code of Conduct

liugddx commented 8 months ago

Let me see

cambyzju commented 8 months ago

检查下:check_overflow_for_decimal session变量,master和2.0的配置是否一致。

我这边测了下,master & 2.0 都会返回失败。

原因是:'123.123' 如果转成 '123.1230' 确实超出了decimal(6, 4)的范围

zxealous commented 8 months ago

检查下:check_overflow_for_decimal session变量,master和2.0的配置是否一致。

我这边测了下,master & 2.0 都会返回失败。

原因是:'123.123' 如果转成 '123.1230' 确实超出了decimal(6, 4)的范围

看了下我这边master和2.0 check_overflow_for_decimal这个变量都是true,master能够查出,2.0不能查出。 我这边的版本: master: 4f5d405fc3 2.0: 655c9353d1