This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 613b0bd5523 [fix](decimal) fix decimal overflow caused by null value
(#28260)
613b0bd5523 is described below
commit 613b0bd552340635d780f7711414735d6e257c48
Author: TengJianPing <[email protected]>
AuthorDate: Wed Dec 13 14:53:39 2023 +0800
[fix](decimal) fix decimal overflow caused by null value (#28260)
---
be/src/vec/columns/column_nullable.cpp | 10 +++
be/src/vec/columns/column_nullable.h | 2 +
be/src/vec/functions/function.cpp | 17 ++++-
.../data/datatype_p0/decimalv3/fix-overflow.out | 4 ++
.../datatype_p0/decimalv3/fix-overflow.groovy | 73 ++++++++++++++++++++++
5 files changed, 104 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/columns/column_nullable.cpp
b/be/src/vec/columns/column_nullable.cpp
index ecf330bead3..98ce01dd572 100644
--- a/be/src/vec/columns/column_nullable.cpp
+++ b/be/src/vec/columns/column_nullable.cpp
@@ -50,6 +50,16 @@ ColumnNullable::ColumnNullable(MutableColumnPtr&&
nested_column_, MutableColumnP
_need_update_has_null = true;
}
+void ColumnNullable::update_null_data() {
+ const auto& null_map_data = _get_null_map_data();
+ auto s = size();
+ for (size_t i = 0; i < s; ++i) {
+ if (null_map_data[i]) {
+ nested_column->replace_column_data_default(i);
+ }
+ }
+}
+
MutableColumnPtr ColumnNullable::get_shrinked_column() {
return
ColumnNullable::create(get_nested_column_ptr()->get_shrinked_column(),
get_null_map_column_ptr());
diff --git a/be/src/vec/columns/column_nullable.h
b/be/src/vec/columns/column_nullable.h
index 10b0951ab8b..8eb1f4eedb0 100644
--- a/be/src/vec/columns/column_nullable.h
+++ b/be/src/vec/columns/column_nullable.h
@@ -83,6 +83,8 @@ public:
return Base::create(std::forward<Args>(args)...);
}
+ void update_null_data();
+
MutableColumnPtr get_shrinked_column() override;
const char* get_family_name() const override { return "Nullable"; }
diff --git a/be/src/vec/functions/function.cpp
b/be/src/vec/functions/function.cpp
index 031b8e755b4..b92f5453bfe 100644
--- a/be/src/vec/functions/function.cpp
+++ b/be/src/vec/functions/function.cpp
@@ -99,8 +99,21 @@ ColumnPtr wrap_in_nullable(const ColumnPtr& src, const
Block& block, const Colum
return ColumnNullable::create(src,
ColumnUInt8::create(input_rows_count, 0));
}
- return
ColumnNullable::create(src_not_nullable->convert_to_full_column_if_const(),
- result_null_map_column);
+ bool update_null_data = false;
+ auto full_column = src_not_nullable->convert_to_full_column_if_const();
+ if (const auto* nullable = check_and_get_column<const
ColumnNullable>(full_column.get())) {
+ const auto& nested_column = nullable->get_nested_column();
+ update_null_data = nested_column.is_numeric() ||
nested_column.is_column_decimal();
+ } else {
+ update_null_data = full_column->is_numeric() ||
full_column->is_column_decimal();
+ }
+ auto result_column = ColumnNullable::create(full_column,
result_null_map_column);
+ if (update_null_data) {
+ auto* res_nullable_column =
+
assert_cast<ColumnNullable*>(std::move(*result_column).mutate().get());
+ res_nullable_column->update_null_data();
+ }
+ return result_column;
}
NullPresence get_null_presence(const Block& block, const ColumnNumbers& args) {
diff --git a/regression-test/data/datatype_p0/decimalv3/fix-overflow.out
b/regression-test/data/datatype_p0/decimalv3/fix-overflow.out
index 4bd52d46e49..ba2250c9b72 100644
--- a/regression-test/data/datatype_p0/decimalv3/fix-overflow.out
+++ b/regression-test/data/datatype_p0/decimalv3/fix-overflow.out
@@ -2,3 +2,7 @@
-- !sql --
1.1 \N \N
+-- !select_insert --
+a \N
+b 0.00
+
diff --git a/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy
b/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy
index 7b8ef17007d..0a285189cbc 100644
--- a/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy
+++ b/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy
@@ -31,4 +31,77 @@ suite("fix-overflow") {
qt_sql """
select l.k1, r.k1, l.k1 * r.k1 from fix_overflow_l l left join
fix_overflow_r r on l.k1=r.k1;
"""
+
+ sql """
+ drop TABLE if exists `fix_overflow_null1`;
+ """
+ sql """
+ CREATE TABLE `fix_overflow_null1`
+ (
+ `country` varchar(20),
+ `financing_amount` decimalv3(20, 2)
+ )
+ DISTRIBUTED BY HASH(`country`) BUCKETS 10
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+ """
+ sql """
+ insert into fix_overflow_null1 values("a", null), ("b",
976109703976856034.13);
+ """
+
+ sql """
+ drop TABLE if exists `fix_overflow_null2`;
+ """
+ sql """
+ CREATE TABLE `fix_overflow_null2`
+ (
+ `country` varchar(20),
+ `financing_amount` decimalv3(20, 2)
+ )
+ DISTRIBUTED BY HASH(`country`) BUCKETS 10
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+ """
+
+ sql """
+ insert into fix_overflow_null2
+ select
+ *
+ from
+ (
+ with temp as (
+ select
+ sum(financing_amount) / 100000000 as amount,
+ country
+ from
+ fix_overflow_null1
+ group by
+ country
+ )
+ select
+ t1.country,
+ IF(
+ 1 + (t1.amount - t2.amount) / ABS(t2.amount) > 0,
+ POW(
+ 1 + (t1.amount - t2.amount) / ABS(t2.amount),
+ 1 / 5
+ ) - 1,
+ - POW(
+ -(
+ 1 + (t1.amount - t2.amount) / ABS(t2.amount)
+ ),
+ 1 / 5
+ ) - 1
+ ) as past_5_cagr
+ from
+ temp t1
+ left join temp t2 on
+ t2.country = t1.country
+ ) as ret;
+ """
+ qt_select_insert """
+ select * from fix_overflow_null2 order by 1,2;
+ """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]