Skip to content

fix(MCOL-4628): SET double_col=decimal_col returns an error #3531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: stable-23.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion dbcon/joblist/jlf_execplantojoblist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1743,11 +1743,18 @@ const JobStepVector doSimpleFilter(SimpleFilter* sf, JobInfo& jobInfo)

#else
bool isNull = cc->isNull();

if (ct.isWideDecimalType())
{
convertValueNum(constval.safeString(""), ct, isNull, rf, jobInfo.timeZone, value128);
}
else if (cc->resultType().colDataType == CalpontSystemCatalog::DECIMAL && cc->resultType().scale > 0)
{
convertValueNum(constval.safeString(""), cc->resultType(), isNull, rf, jobInfo.timeZone, value);
}
else
{
convertValueNum(constval.safeString(""), ct, isNull, rf, jobInfo.timeZone, value);
}

if (ct.colDataType == CalpontSystemCatalog::FLOAT && !isNull)
{
Expand Down
77 changes: 77 additions & 0 deletions mysql-test/columnstore/bugfixes/mcol_4628.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
DROP DATABASE IF EXISTS mcol_4628;
CREATE DATABASE mcol_4628;
USE mcol_4628;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;
i d
2 1.5
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.7);
UPDATE t1 SET i=d;
SELECT * FROM t1;
i d
2 1.7
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.4);
UPDATE t1 SET i=d;
SELECT * FROM t1;
i d
1 1.4
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, -0.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;
i d
0 -0.5
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT UNSIGNED, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 0.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;
i d
1 0.5
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT UNSIGNED, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;
i d
2 1.5
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT UNSIGNED, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.4);
UPDATE t1 SET i=d;
SELECT * FROM t1;
i d
1 1.4
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i SMALLINT) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (-762);
INSERT INTO t1 VALUES (-761);
INSERT INTO t1 VALUES (761);
INSERT INTO t1 VALUES (762);
SELECT * FROM t1 WHERE i > -762.5;
i
-762
-761
761
762
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i SMALLINT) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (-762);
INSERT INTO t1 VALUES (-761);
INSERT INTO t1 VALUES (761);
INSERT INTO t1 VALUES (762);
SELECT * FROM t1 WHERE i > -762.2;
i
-762
-761
761
762
DROP DATABASE mcol_4628;
86 changes: 86 additions & 0 deletions mysql-test/columnstore/bugfixes/mcol_4628.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
-- source ../include/have_columnstore.inc
--disable_warnings
DROP DATABASE IF EXISTS mcol_4628;
--enable_warnings
CREATE DATABASE mcol_4628;
USE mcol_4628;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.7);
UPDATE t1 SET i=d;
SELECT * FROM t1;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.4);
UPDATE t1 SET i=d;
SELECT * FROM t1;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, -0.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT UNSIGNED, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 0.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT UNSIGNED, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.5);
UPDATE t1 SET i=d;
SELECT * FROM t1;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT UNSIGNED, d DOUBLE) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (0, 1.4);
UPDATE t1 SET i=d;
SELECT * FROM t1;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i SMALLINT) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (-762);
INSERT INTO t1 VALUES (-761);
INSERT INTO t1 VALUES (761);
INSERT INTO t1 VALUES (762);
SELECT * FROM t1 WHERE i > -762.5;

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i SMALLINT) ENGINE=ColumnStore;
INSERT INTO t1 VALUES (-762);
INSERT INTO t1 VALUES (-761);
INSERT INTO t1 VALUES (761);
INSERT INTO t1 VALUES (762);
SELECT * FROM t1 WHERE i > -762.2;

--disable_warnings
DROP DATABASE mcol_4628;
--enable_warnings
16 changes: 8 additions & 8 deletions tests/dataconvert-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ TEST(DataConvertTest, NumberIntValue)
pushWarning = false;
number_int_value(data, typecode, ct, pushWarning, noRoundup, res);
EXPECT_EQ(res, 12);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
data = "-1234";
pushWarning = false;
number_int_value(data, typecode, ct, pushWarning, noRoundup, res);
Expand All @@ -197,7 +197,7 @@ TEST(DataConvertTest, NumberIntValue)
pushWarning = false;
number_int_value(data, typecode, ct, pushWarning, noRoundup, res);
EXPECT_EQ(res, -12);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
// test max
data = "99999999999999999999999999999999999999";
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000) +
Expand Down Expand Up @@ -234,12 +234,12 @@ TEST(DataConvertTest, NumberIntValue)
pushWarning = false;
number_int_value(data, typecode, ct, pushWarning, noRoundup, res);
EXPECT_EQ(res, 13);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
data = "-12.56";
pushWarning = false;
number_int_value(data, typecode, ct, pushWarning, noRoundup, res);
EXPECT_EQ(res, -13);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
// test saturation
data = "999999999999999999999999999999999999999"; // data has 39 9's
// valMax has 38 9's
Expand Down Expand Up @@ -367,12 +367,12 @@ TEST(DataConvertTest, NumberIntValue)
pushWarning = false;
number_int_value(data, typecode, ct, pushWarning, noRoundup, res);
EXPECT_EQ(res, 121111111112);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
data = "-12.11111111119";
pushWarning = false;
number_int_value(data, typecode, ct, pushWarning, noRoundup, res);
EXPECT_EQ(res, -121111111112);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
// test saturation
data = "99999999999999999999999999999"; // data has 29 9's
// valMax has 38 9's
Expand Down Expand Up @@ -532,7 +532,7 @@ TEST(DataConvertTest, NumberIntValue)
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
EXPECT_EQ(b1, b3);
EXPECT_EQ(b2, b4);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
data = "-0.199999999999999999999999999999999999999";
valMax = ((((((((int128_t)200000000 * 1000000000) + 0) * 1000000000) + 0) * 1000000000) + 0) * 100) + 0;
valMax = -valMax;
Expand All @@ -544,7 +544,7 @@ TEST(DataConvertTest, NumberIntValue)
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
EXPECT_EQ(b1, b3);
EXPECT_EQ(b2, b4);
EXPECT_TRUE(pushWarning);
EXPECT_FALSE(pushWarning);
// test saturation
data = "99999999999999999999999999999"; // data has 29 9's
// valMax has 38 9's
Expand Down
30 changes: 18 additions & 12 deletions utils/dataconvert/dataconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ void number_int_value(const string& data, cscDataType typeCode,
string frnStr = "";
size_t dp = valStr.find('.');
int roundup = 0;
bool isNegative = valStr.find('-') != string::npos;

if (dp != string::npos)
{
Expand All @@ -262,13 +263,16 @@ void number_int_value(const string& data, cscDataType typeCode,
}

intVal = dataconvert::string_to_ll<T>(intStr, pushwarning);
//@Bug 3350 negative value round up.
intVal += intVal >= 0 ? roundup : -roundup;
bool dummy = false;
T frnVal = (frnStr.length() > 0) ? dataconvert::string_to_ll<T>(frnStr, dummy) : 0;

if (frnVal != 0)
pushwarning = true;
if (intVal == 0 && isNegative)
{
if (roundup == 1)
roundup = 0;
}
else
{
intVal += intVal >= 0 ? roundup : -roundup;
}

switch (typeCode)
{
Expand Down Expand Up @@ -498,7 +502,7 @@ template void number_int_value<int128_t>(const std::string& data, cscDataType ty

uint64_t number_uint_value(const string& data, cscDataType typeCode,
const datatypes::SystemCatalog::TypeAttributesStd& /*ct*/, bool& pushwarning,
bool /*noRoundup*/)
bool noRoundup)
{
// copy of the original input
string valStr(data);
Expand Down Expand Up @@ -595,11 +599,13 @@ uint64_t number_uint_value(const string& data, cscDataType typeCode,

uint64_t uintVal = dataconvert::string_to_ull(intStr, pushwarning);

bool dummy = false;
uint64_t frnVal = (frnStr.length() > 0) ? dataconvert::string_to_ull(frnStr, dummy) : 0;

if (frnVal != 0)
pushwarning = true;
if (!frnStr.empty() && !noRoundup)
{
if (!frnStr.empty() && frnStr[0] >= '5')
{
uintVal += 1;
}
}

switch (typeCode)
{
Expand Down