1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-07 03:22:57 +03:00

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)
This commit is contained in:
Akhmad O.
2025-05-19 21:41:28 +02:00
committed by GitHub
parent a4b138625e
commit e0f3bf8322
4 changed files with 25 additions and 11 deletions

View File

@@ -2,10 +2,16 @@ DROP DATABASE IF EXISTS mcol_5386;
CREATE DATABASE mcol_5386; CREATE DATABASE mcol_5386;
USE mcol_5386; USE mcol_5386;
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1;
create table t1(c decimal(19)) engine=columnstore; create table t1(c decimal(38)) engine=columnstore;
insert into t1(c) values (-2); insert into t1(c) values (11111111111111111111111111111111111111);
select bit_or(c), bit_xor(c), bit_and(c) from t1; select bit_or(c), bit_xor(c), bit_and(c) from t1;
bit_or(c) bit_xor(c) bit_and(c) 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 TABLE IF EXISTS t1;
DROP DATABASE mcol_5386; DROP DATABASE mcol_5386;

View File

@@ -8,8 +8,15 @@ USE mcol_5386;
--disable_warnings --disable_warnings
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1;
--enable_warnings --enable_warnings
create table t1(c decimal(19)) engine=columnstore; create table t1(c decimal(38)) engine=columnstore;
insert into t1(c) values (-2); 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; select bit_or(c), bit_xor(c), bit_and(c) from t1;
--disable_warnings --disable_warnings

View File

@@ -1538,21 +1538,24 @@ void RowAggregation::doBitOp(const Row& rowIn, int64_t colIn, int64_t colOut, in
case execplan::CalpontSystemCatalog::MEDINT: case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::INT: case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::BIGINT: 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::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL:
{ {
valIn = rowIn.getIntField(colIn); valIn = rowIn.getIntField<8>(colIn);
if ((fRowGroupIn.getScale())[colIn] != 0) if ((fRowGroupIn.getScale())[colIn] != 0)
{ {
valIn = rowIn.getIntField(colIn);
valIn /= IDB_pow[fRowGroupIn.getScale()[colIn] - 1]; valIn /= IDB_pow[fRowGroupIn.getScale()[colIn] - 1];
if (valIn > 0) if (valIn > 0)
valIn += 5; valIn += 5;
else if (valIn < 0) else if (valIn < 0)
valIn -= 5; valIn -= 5;
valIn /= 10; valIn /= 10;
} }

View File

@@ -919,8 +919,6 @@ inline int64_t Row::getIntField(uint32_t colIndex) const
case 8: return *((int64_t*)&data[offsets[colIndex]]); 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."); default: idbassert(0); throw std::logic_error("Row::getIntField(): bad length.");
} }
} }