From e0f3bf83222192d74165522a805d825147d1bb48 Mon Sep 17 00:00:00 2001 From: "Akhmad O." <96055449+AestheticAkhmad@users.noreply.github.com> Date: Mon, 19 May 2025 21:41:28 +0200 Subject: [PATCH] fix(MCOL-5386): Bitwise aggregation functions do not work with wide decimals (updated previous PR) (#3522) * fix(MCOL-5386): Bitwise aggregation functions do not work with wide decimals (updated previous PR) * MCOL-5386: Added test for Decimal(18) --- mysql-test/columnstore/bugfixes/mcol_5386.result | 12 +++++++++--- mysql-test/columnstore/bugfixes/mcol_5386.test | 11 +++++++++-- utils/rowgroup/rowaggregation.cpp | 11 +++++++---- utils/rowgroup/rowgroup.h | 2 -- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/mysql-test/columnstore/bugfixes/mcol_5386.result b/mysql-test/columnstore/bugfixes/mcol_5386.result index be7da80c1..501e57634 100644 --- a/mysql-test/columnstore/bugfixes/mcol_5386.result +++ b/mysql-test/columnstore/bugfixes/mcol_5386.result @@ -2,10 +2,16 @@ DROP DATABASE IF EXISTS mcol_5386; CREATE DATABASE mcol_5386; USE mcol_5386; DROP TABLE IF EXISTS t1; -create table t1(c decimal(19)) engine=columnstore; -insert into t1(c) values (-2); +create table t1(c decimal(38)) engine=columnstore; +insert into t1(c) values (11111111111111111111111111111111111111); select bit_or(c), bit_xor(c), bit_and(c) from t1; bit_or(c) bit_xor(c) bit_and(c) -18446744073709551614 18446744073709551614 18446744073709551614 +10324568879994270151 10324568879994270151 10324568879994270151 +DROP TABLE IF EXISTS t1; +create table t1(c decimal(18)) engine=columnstore; +insert into t1(c) values (999999999999999999); +select bit_or(c), bit_xor(c), bit_and(c) from t1; +bit_or(c) bit_xor(c) bit_and(c) +999999999999999999 999999999999999999 999999999999999999 DROP TABLE IF EXISTS t1; DROP DATABASE mcol_5386; diff --git a/mysql-test/columnstore/bugfixes/mcol_5386.test b/mysql-test/columnstore/bugfixes/mcol_5386.test index ab81c0177..67621d8c8 100644 --- a/mysql-test/columnstore/bugfixes/mcol_5386.test +++ b/mysql-test/columnstore/bugfixes/mcol_5386.test @@ -8,8 +8,15 @@ USE mcol_5386; --disable_warnings DROP TABLE IF EXISTS t1; --enable_warnings -create table t1(c decimal(19)) engine=columnstore; -insert into t1(c) values (-2); +create table t1(c decimal(38)) engine=columnstore; +insert into t1(c) values (11111111111111111111111111111111111111); +select bit_or(c), bit_xor(c), bit_and(c) from t1; + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +create table t1(c decimal(18)) engine=columnstore; +insert into t1(c) values (999999999999999999); select bit_or(c), bit_xor(c), bit_and(c) from t1; --disable_warnings diff --git a/utils/rowgroup/rowaggregation.cpp b/utils/rowgroup/rowaggregation.cpp index a4d266da0..5ba56399a 100644 --- a/utils/rowgroup/rowaggregation.cpp +++ b/utils/rowgroup/rowaggregation.cpp @@ -1538,21 +1538,24 @@ void RowAggregation::doBitOp(const Row& rowIn, int64_t colIn, int64_t colOut, in case execplan::CalpontSystemCatalog::MEDINT: case execplan::CalpontSystemCatalog::INT: case execplan::CalpontSystemCatalog::BIGINT: + { + valIn = rowIn.getIntField(colIn); + break; + } + // According to SQL specification, the result must fit in int64_t, + // therefore, the upper 8 bytes for data types >= 8 bytes are ignored case execplan::CalpontSystemCatalog::DECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL: { - valIn = rowIn.getIntField(colIn); - + valIn = rowIn.getIntField<8>(colIn); if ((fRowGroupIn.getScale())[colIn] != 0) { - valIn = rowIn.getIntField(colIn); valIn /= IDB_pow[fRowGroupIn.getScale()[colIn] - 1]; if (valIn > 0) valIn += 5; else if (valIn < 0) valIn -= 5; - valIn /= 10; } diff --git a/utils/rowgroup/rowgroup.h b/utils/rowgroup/rowgroup.h index 4fb6ff001..f797bd9a9 100644 --- a/utils/rowgroup/rowgroup.h +++ b/utils/rowgroup/rowgroup.h @@ -919,8 +919,6 @@ inline int64_t Row::getIntField(uint32_t colIndex) const case 8: return *((int64_t*)&data[offsets[colIndex]]); - case 16: return *((int128_t*)&data[offsets[colIndex]]); - default: idbassert(0); throw std::logic_error("Row::getIntField(): bad length."); } }