You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-07 03:22:57 +03:00
MCOL-641 Replaced IDB_Decima.__v union with int128_t attribute.
Moved all tests into ./test Introduced ./datatypes directory
This commit is contained in:
19
tests/CMakeLists.txt
Normal file
19
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
include_directories( ${ENGINE_COMMON_INCLUDES} )
|
||||
|
||||
if (WITH_ROWGROUP_UT)
|
||||
add_executable(rowgroup_tests rowgroup-tests.cpp)
|
||||
target_link_libraries(rowgroup_tests ${ENGINE_LDFLAGS} ${GTEST_LIBRARIES} ${ENGINE_EXEC_LIBS} ${MARIADB_CLIENT_LIBS})
|
||||
install(TARGETS rowgroup_tests DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-platform)
|
||||
endif()
|
||||
|
||||
if (WITH_ARITHMETICOPERATOR_UT)
|
||||
add_executable(arithmeticoperator_tests arithmeticoperator-tests.cpp)
|
||||
target_link_libraries(arithmeticoperator_tests ${ENGINE_LDFLAGS} ${GTEST_LIBRARIES} ${ENGINE_EXEC_LIBS} ${MARIADB_CLIENT_LIBS})
|
||||
install(TARGETS rowgroup_tests DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-platform)
|
||||
endif()
|
||||
|
||||
if (WITH_DATACONVERT_UT)
|
||||
add_executable(dataconvert_tests dataconvert-tests.cpp)
|
||||
target_link_libraries(dataconvert_tests ${ENGINE_LDFLAGS} ${GTEST_LIBRARIES} ${ENGINE_EXEC_LIBS} ${MARIADB_CLIENT_LIBS})
|
||||
install(TARGETS dataconvert_tests DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-platform)
|
||||
endif()
|
27
tests/arithmeticoperator-tests.cpp
Normal file
27
tests/arithmeticoperator-tests.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/* Copyright (C) 2020 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
#include <gtest/gtest.h> // googletest header file
|
||||
|
||||
using int128_t = __int128;
|
||||
using uint128_t = unsigned __int128;
|
||||
//using CSCDataType = execplan::CalpontSystemCatalog::ColDataType;
|
||||
|
||||
TEST(SimpleCheck, check1)
|
||||
{
|
||||
EXPECT_EQ(true, true);
|
||||
}
|
670
tests/dataconvert-tests.cpp
Normal file
670
tests/dataconvert-tests.cpp
Normal file
@@ -0,0 +1,670 @@
|
||||
/* Copyright (C) 2020 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
#include <bitset>
|
||||
using namespace std;
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
#include "dataconvert.h"
|
||||
using namespace dataconvert;
|
||||
#include "joblisttypes.h"
|
||||
#include "columnwidth.h"
|
||||
|
||||
using CSCDataType = execplan::CalpontSystemCatalog::ColDataType;
|
||||
|
||||
TEST(DataConvertTest, Strtoll128)
|
||||
{
|
||||
char *ep = NULL;
|
||||
bool saturate = false;
|
||||
string str;
|
||||
int128_t val, valMax;
|
||||
bitset<64> b1, b2, b3, b4;
|
||||
|
||||
// test empty
|
||||
str = "";
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
EXPECT_EQ(val, 0);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
|
||||
// test simple values
|
||||
str = "123";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
EXPECT_EQ(val, 123);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
str = " 123";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
EXPECT_EQ(val, 123);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
str = " 123.45";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
EXPECT_EQ(val, 123);
|
||||
EXPECT_NE(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
str = "-123";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
EXPECT_EQ(val, -123);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
str = " -123";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
EXPECT_EQ(val, -123);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
str = " -123.45";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
EXPECT_EQ(val, -123);
|
||||
EXPECT_NE(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
|
||||
// test max/min values
|
||||
// test max
|
||||
str = "170141183460469231731687303715884105727";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&val));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&val) + 1);
|
||||
valMax = ((((((((int128_t)170141183 * 1000000000) + 460469231) * 1000000000) + 731687303) * 1000000000 ) + 715884105) * 1000) + 727;
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
// test min
|
||||
str = "-170141183460469231731687303715884105728";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&val));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&val) + 1);
|
||||
valMax = ((((((((int128_t)170141183 * 1000000000) + 460469231) * 1000000000) + 731687303) * 1000000000 ) + 715884105) * 1000) + 727;
|
||||
valMax = -valMax - 1;
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_FALSE(saturate);
|
||||
|
||||
// test saturation
|
||||
// test saturation to max
|
||||
str = "170141183460469231731687303715884105728";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&val));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&val) + 1);
|
||||
valMax = ((((((((int128_t)170141183 * 1000000000) + 460469231) * 1000000000) + 731687303) * 1000000000 ) + 715884105) * 1000) + 727;
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_TRUE(saturate);
|
||||
// test saturation to min
|
||||
str = "-170141183460469231731687303715884105729";
|
||||
saturate = false;
|
||||
val = strtoll128(str.c_str(), saturate, &ep);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&val));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&val) + 1);
|
||||
valMax = ((((((((int128_t)170141183 * 1000000000) + 460469231) * 1000000000) + 731687303) * 1000000000 ) + 715884105) * 1000) + 727;
|
||||
valMax = -valMax - 1;
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_EQ(*ep, '\0');
|
||||
EXPECT_TRUE(saturate);
|
||||
}
|
||||
|
||||
TEST(DataConvertTest, NumberIntValue)
|
||||
{
|
||||
CalpontSystemCatalog::ColType ct;
|
||||
int128_t res, valMax;
|
||||
string data;
|
||||
bool noRoundup = false;
|
||||
bool pushWarning;
|
||||
bitset<64> b1, b2, b3, b4;
|
||||
|
||||
// tests for signed decimal
|
||||
// behaviour of number_int_value for unsigned decimal
|
||||
// is similar to the signed case.
|
||||
ct.colDataType = CalpontSystemCatalog::DECIMAL;
|
||||
// test with decimal(38,0)
|
||||
ct.precision = 38;
|
||||
ct.scale = 0;
|
||||
// test simple values
|
||||
//data = "";
|
||||
data = "0";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 0);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "1234";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 1234);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "12.0";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 12);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "12.34";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 12);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-1234";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, -1234);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "-12.34";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, -12);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test max
|
||||
data = "99999999999999999999999999999999999999";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test min
|
||||
data = "-99999999999999999999999999999999999999";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test rounding
|
||||
data = "12.56";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 13);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-12.56";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, -13);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test saturation
|
||||
data = "999999999999999999999999999999999999999"; // data has 39 9's
|
||||
// valMax has 38 9's
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-999999999999999999999999999999999999999"; // data has 39 9's
|
||||
// valMax has 38 9's
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test scientific notation
|
||||
data = "1.23e37";
|
||||
valMax = ((((((((int128_t)123000000 * 1000000000) + 0) * 1000000000) + 0) * 1000000000 ) + 0) * 100) + 0;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "1.23e38";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
|
||||
// test with decimal(38,10)
|
||||
ct.scale = 10;
|
||||
data = "0";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 0);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "1234";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 12340000000000);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "12.0";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 120000000000);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "12.34";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 123400000000);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "-1234";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, -12340000000000);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "-12.34";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, -123400000000);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test max
|
||||
data = "9999999999999999999999999999.9999999999";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test min
|
||||
data = "-9999999999999999999999999999.9999999999";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test rounding
|
||||
data = "12.11111111119";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 121111111112);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-12.11111111119";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, -121111111112);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test saturation
|
||||
data = "99999999999999999999999999999"; // data has 29 9's
|
||||
// valMax has 38 9's
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-99999999999999999999999999999"; // data has 29 9's
|
||||
// valMax has 38 9's
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test scientific notation
|
||||
data = "1.23e9";
|
||||
valMax = ((((int128_t)123000000 * 1000000000) + 0) * 100);
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "1.23e28";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test with decimal(38,38)
|
||||
ct.scale = 38;
|
||||
data = "0";
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
EXPECT_EQ(res, 0);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "1.234";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "0.123";
|
||||
valMax = ((((((((int128_t)123000000 * 1000000000) + 0) * 1000000000) + 0) * 1000000000 ) + 0) * 100) + 0;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "-1.234";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-0.123";
|
||||
valMax = ((((((((int128_t)123000000 * 1000000000) + 0) * 1000000000) + 0) * 1000000000 ) + 0) * 100) + 0;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test max
|
||||
data = "0.99999999999999999999999999999999999999";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test min
|
||||
data = "-0.99999999999999999999999999999999999999";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
// test rounding
|
||||
data = "0.199999999999999999999999999999999999999";
|
||||
valMax = ((((((((int128_t)200000000 * 1000000000) + 0) * 1000000000) + 0) * 1000000000 ) + 0) * 100) + 0;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-0.199999999999999999999999999999999999999";
|
||||
valMax = ((((((((int128_t)200000000 * 1000000000) + 0) * 1000000000) + 0) * 1000000000 ) + 0) * 100) + 0;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test saturation
|
||||
data = "99999999999999999999999999999"; // data has 29 9's
|
||||
// valMax has 38 9's
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
data = "-99999999999999999999999999999"; // data has 29 9's
|
||||
// valMax has 38 9's
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
valMax = -valMax;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
// test scientific notation
|
||||
data = "123e-4";
|
||||
valMax = ((((((((int128_t)123000000 * 1000000000) + 0) * 1000000000) + 0) * 1000000000 ) + 0) * 10) + 0;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_FALSE(pushWarning);
|
||||
data = "123e-2";
|
||||
valMax = ((((((((int128_t)999999999 * 1000000000) + 999999999) * 1000000000) + 999999999) * 1000000000 ) + 999999999) * 100) + 99;
|
||||
pushWarning = false;
|
||||
number_int_value(data, ct, pushWarning, noRoundup, res);
|
||||
b1 = *(reinterpret_cast<const uint64_t*>(&res));
|
||||
b2 = *(reinterpret_cast<const uint64_t*>(&res) + 1);
|
||||
b3 = *(reinterpret_cast<const uint64_t*>(&valMax));
|
||||
b4 = *(reinterpret_cast<const uint64_t*>(&valMax) + 1);
|
||||
EXPECT_EQ(b1, b3);
|
||||
EXPECT_EQ(b2, b4);
|
||||
EXPECT_TRUE(pushWarning);
|
||||
}
|
||||
|
||||
TEST(DataConvertTest, atoiCheck) {
|
||||
std::vector<int128_t> expected;
|
||||
std::vector<std::string> decimalAsStringVec;
|
||||
decimalAsStringVec.push_back("99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("-99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("0");
|
||||
decimalAsStringVec.push_back("-0.042");
|
||||
expected.push_back(10000000000000000000ULL*(uint128_t)9999999999999999999ULL
|
||||
+9999999999999999999ULL);
|
||||
expected.push_back(-1*expected[0]);
|
||||
expected.push_back(0);
|
||||
expected.push_back(-42);
|
||||
for (int i=0; i < expected.size(); i++) {
|
||||
int128_t value;
|
||||
dataconvert::atoi128(decimalAsStringVec[i], value);
|
||||
EXPECT_EQ(expected[i], value);
|
||||
EXPECT_NE(expected[i], value-1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DataConvertTest, DecimalToStringCheckScale3) {
|
||||
std::vector<std::string> expected;
|
||||
std::vector<std::string> decimalAsStringVec;
|
||||
// scale 3
|
||||
uint8_t scale3 = 3;
|
||||
decimalAsStringVec.push_back("99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("-99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("0");
|
||||
decimalAsStringVec.push_back("-0.042");
|
||||
expected.push_back("99999999999999999999999999999999999.999");
|
||||
expected.push_back("-99999999999999999999999999999999999.999");
|
||||
expected.push_back("0.000");
|
||||
expected.push_back("-0.042");
|
||||
char buf[42];
|
||||
CSCDataType type = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
for (int i=0; i < expected.size(); i++) {
|
||||
int128_t value = -4;
|
||||
memset(buf, 0, 42);
|
||||
dataconvert::atoi128(decimalAsStringVec[i], value);
|
||||
dataconvert::DataConvert::decimalToString(&value, scale3, buf,
|
||||
utils::precisionByWidth(sizeof(value))+4, type);
|
||||
EXPECT_EQ(expected[i], std::string(buf));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DataConvertTest, DecimalToStringCheckScale10) {
|
||||
std::vector<std::string> expected;
|
||||
std::vector<std::string> decimalAsStringVec;
|
||||
// scale 3
|
||||
uint8_t scale3 = 10;
|
||||
decimalAsStringVec.push_back("10000000009");
|
||||
decimalAsStringVec.push_back("-10000000009");
|
||||
decimalAsStringVec.push_back("0");
|
||||
decimalAsStringVec.push_back("-10000000010");
|
||||
expected.push_back("1.0000000009");
|
||||
expected.push_back("-1.0000000009");
|
||||
expected.push_back("0.0000000000");
|
||||
expected.push_back("-1.0000000010");
|
||||
char buf[42];
|
||||
CSCDataType type = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
for (int i=0; i < expected.size(); i++) {
|
||||
int128_t value = -4;
|
||||
memset(buf, 0, 42);
|
||||
dataconvert::atoi128(decimalAsStringVec[i], value);
|
||||
dataconvert::DataConvert::decimalToString(&value, scale3, buf,
|
||||
utils::precisionByWidth(sizeof(value))+4, type);
|
||||
EXPECT_EQ(expected[i], std::string(buf));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DataConvertTest, DecimalToStringCheckScale37) {
|
||||
std::vector<std::string> expected;
|
||||
std::vector<std::string> decimalAsStringVec;
|
||||
uint8_t scale37 = 37;
|
||||
decimalAsStringVec.push_back("99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("-99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("0");
|
||||
decimalAsStringVec.push_back("-42");
|
||||
decimalAsStringVec.push_back("-19999999999999999999999999999999999999");
|
||||
expected.push_back("9.9999999999999999999999999999999999999");
|
||||
expected.push_back("-9.9999999999999999999999999999999999999");
|
||||
expected.push_back("0.0000000000000000000000000000000000000");
|
||||
expected.push_back("-0.0000000000000000000000000000000000042");
|
||||
expected.push_back("-1.9999999999999999999999999999999999999");
|
||||
char buf[42];
|
||||
CSCDataType type = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
for (int i=0; i < expected.size(); i++) {
|
||||
int128_t value = -4;
|
||||
memset(buf, 0, 41);
|
||||
dataconvert::atoi128(decimalAsStringVec[i], value);
|
||||
dataconvert::DataConvert::decimalToString(&value, scale37, buf,
|
||||
utils::precisionByWidth(sizeof(value))+4, type);
|
||||
EXPECT_EQ(expected[i], std::string(buf));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DataConvertTest, DecimalToStringCheckScale38) {
|
||||
std::vector<std::string> expected;
|
||||
std::vector<std::string> decimalAsStringVec;
|
||||
uint8_t scale38 = 38;
|
||||
decimalAsStringVec.push_back("99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("-99999999999999999999999999999999999999");
|
||||
decimalAsStringVec.push_back("0");
|
||||
decimalAsStringVec.push_back("-42");
|
||||
expected.push_back("0.99999999999999999999999999999999999999");
|
||||
expected.push_back("-0.99999999999999999999999999999999999999");
|
||||
expected.push_back("0.00000000000000000000000000000000000000");
|
||||
expected.push_back("-0.00000000000000000000000000000000000042");
|
||||
char buf[42];
|
||||
CSCDataType type = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
for (int i=0; i < expected.size(); i++) {
|
||||
int128_t value = -4;
|
||||
memset(buf, 0, 41);
|
||||
dataconvert::atoi128(decimalAsStringVec[i], value);
|
||||
dataconvert::DataConvert::decimalToString(&value, scale38, buf,
|
||||
utils::precisionByWidth(sizeof(value))+4, type);
|
||||
EXPECT_EQ(expected[i], std::string(buf));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DataConvertTest, ConvertColumnData) {
|
||||
}
|
||||
|
243
tests/rowgroup-tests.cpp
Normal file
243
tests/rowgroup-tests.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
/* Copyright (C) 2020 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
#include <gtest/gtest.h> // googletest header file
|
||||
#include <iostream>
|
||||
|
||||
#include "rowgroup.h"
|
||||
#include "columnwidth.h"
|
||||
#include "joblisttypes.h"
|
||||
#include "dataconvert.h"
|
||||
|
||||
#define WIDE_DEC_PRECISION 38U
|
||||
#define INITIAL_ROW_OFFSET 2
|
||||
|
||||
using int128_t = __int128;
|
||||
using uint128_t = unsigned __int128;
|
||||
using CSCDataType = execplan::CalpontSystemCatalog::ColDataType;
|
||||
|
||||
class RowDecimalTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
uint32_t precision = WIDE_DEC_PRECISION;
|
||||
uint32_t oid =3001;
|
||||
|
||||
std::vector<CSCDataType>types;
|
||||
std::vector<decltype(precision)>precisionVec;
|
||||
std::vector<uint32_t> roids, tkeys, cscale;
|
||||
types.push_back(execplan::CalpontSystemCatalog::DECIMAL);
|
||||
types.push_back(execplan::CalpontSystemCatalog::UDECIMAL);
|
||||
for (size_t i=0; i <= 3; i++) {
|
||||
types.push_back(execplan::CalpontSystemCatalog::DECIMAL);
|
||||
}
|
||||
precisionVec.push_back(precision);
|
||||
precisionVec.push_back(precision);
|
||||
precisionVec.push_back(18);
|
||||
precisionVec.push_back(9);
|
||||
precisionVec.push_back(4);
|
||||
precisionVec.push_back(2);
|
||||
std::vector<uint32_t>widthVec;
|
||||
uint32_t offset = INITIAL_ROW_OFFSET;
|
||||
offsets.push_back(offset);
|
||||
for (size_t i=0; i < types.size(); i++) {
|
||||
uint8_t width = utils::widthByPrecision(precisionVec[i]);
|
||||
widthVec.push_back(width);
|
||||
offset += width;
|
||||
offsets.push_back(offset);
|
||||
roids.push_back(oid+i);
|
||||
tkeys.push_back(i+1); cscale.push_back(0);
|
||||
}
|
||||
/*offsets.push_back(INITIAL_ROW_OFFSET);
|
||||
offsets.push_back(16+INITIAL_ROW_OFFSET);
|
||||
offsets.push_back(16*2+INITIAL_ROW_OFFSET);
|
||||
roids.push_back(oid); roids.push_back(oid+1);
|
||||
tkeys.push_back(1); tkeys.push_back(1);
|
||||
cscale.push_back(0); cscale.push_back(0);*/
|
||||
|
||||
rowgroup::RowGroup inRG(roids.size(), //column count
|
||||
offsets, //oldOffset
|
||||
roids, // column oids
|
||||
tkeys, //keys
|
||||
types, // types
|
||||
cscale, //scale
|
||||
precisionVec, // precision
|
||||
20, // sTableThreshold
|
||||
false //useStringTable
|
||||
);
|
||||
|
||||
rg = inRG;
|
||||
rgD.reinit(rg);
|
||||
rg.setData(&rgD);
|
||||
|
||||
rg.initRow(&r);
|
||||
rg.initRow(&rOutMappingCheck);
|
||||
rowSize = r.getSize();
|
||||
rg.getRow(0, &r);
|
||||
|
||||
int128_t nullValue = 0;
|
||||
int128_t bigValue = 0;
|
||||
uint64_t* uint128_pod = reinterpret_cast<uint64_t*>(&nullValue);
|
||||
uint128_pod[0] = joblist::UBIGINTNULL;
|
||||
uint128_pod[1] = joblist::UBIGINTEMPTYROW;
|
||||
bigValue = -static_cast<int128_t>(0xFFFFFFFF)*0xFFFFFFFFFFFFFFFF;
|
||||
sValueVector.push_back(nullValue);
|
||||
sValueVector.push_back(-42);
|
||||
sValueVector.push_back(bigValue);
|
||||
sValueVector.push_back(0);
|
||||
sValueVector.push_back(nullValue-1);
|
||||
|
||||
uValueVector.push_back(nullValue);
|
||||
uValueVector.push_back(42);
|
||||
uValueVector.push_back(bigValue);
|
||||
uValueVector.push_back(0);
|
||||
uValueVector.push_back(nullValue-1);
|
||||
|
||||
s8ValueVector.push_back(joblist::TINYINTNULL);
|
||||
s8ValueVector.push_back(-0x79);
|
||||
s8ValueVector.push_back(0);
|
||||
s8ValueVector.push_back(0x81);
|
||||
s8ValueVector.push_back(joblist::TINYINTNULL-1);
|
||||
|
||||
s16ValueVector.push_back(joblist::SMALLINTNULL);
|
||||
s16ValueVector.push_back(-0x79);
|
||||
s16ValueVector.push_back(0);
|
||||
s16ValueVector.push_back(0x81);
|
||||
s16ValueVector.push_back(joblist::SMALLINTNULL-1);
|
||||
|
||||
s32ValueVector.push_back(joblist::INTNULL);
|
||||
s32ValueVector.push_back(-0x79);
|
||||
s32ValueVector.push_back(0);
|
||||
s32ValueVector.push_back(0x81);
|
||||
s32ValueVector.push_back(joblist::INTNULL-1);
|
||||
|
||||
s64ValueVector.push_back(joblist::BIGINTNULL);
|
||||
s64ValueVector.push_back(-0x79);
|
||||
s64ValueVector.push_back(0);
|
||||
s64ValueVector.push_back(0x81);
|
||||
s64ValueVector.push_back(joblist::BIGINTNULL-1);
|
||||
|
||||
for(size_t i = 0; i < sValueVector.size(); i++) {
|
||||
r.setBinaryField_offset(&sValueVector[i],
|
||||
sizeof(sValueVector[0]), offsets[0]);
|
||||
r.setBinaryField_offset(&uValueVector[i],
|
||||
sizeof(uValueVector[0]), offsets[1]);
|
||||
r.setIntField(s64ValueVector[i], 2);
|
||||
r.setIntField(s32ValueVector[i], 3);
|
||||
r.setIntField(s16ValueVector[i], 4);
|
||||
r.setIntField(s8ValueVector[i], 5);
|
||||
r.nextRow(rowSize);
|
||||
}
|
||||
rowCount = sValueVector.size();
|
||||
}
|
||||
// void TearDown() override {}
|
||||
|
||||
rowgroup::Row r;
|
||||
rowgroup::Row rOutMappingCheck;
|
||||
rowgroup::RowGroup rg;
|
||||
rowgroup::RGData rgD;
|
||||
uint32_t rowSize;
|
||||
size_t rowCount;
|
||||
std::vector<int128_t> sValueVector;
|
||||
std::vector<uint128_t> uValueVector;
|
||||
std::vector<int64_t> s8ValueVector;
|
||||
std::vector<int64_t> s16ValueVector;
|
||||
std::vector<int64_t> s32ValueVector;
|
||||
std::vector<int64_t> s64ValueVector;
|
||||
std::vector<uint32_t> offsets;
|
||||
};
|
||||
|
||||
TEST_F(RowDecimalTest, NonNULLValuesCheck) {
|
||||
rg.getRow(1, &r);
|
||||
for (size_t i = 1; i <= sValueVector.size(); i++) {
|
||||
EXPECT_FALSE(r.isNullValue(0));
|
||||
EXPECT_FALSE(r.isNullValue(1));
|
||||
EXPECT_FALSE(r.isNullValue(2));
|
||||
EXPECT_FALSE(r.isNullValue(3));
|
||||
EXPECT_FALSE(r.isNullValue(4));
|
||||
EXPECT_FALSE(r.isNullValue(5));
|
||||
r.nextRow(rowSize);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RowDecimalTest, initToNullANDisNullValueValueCheck) {
|
||||
rg.getRow(0, &r);
|
||||
r.initToNull();
|
||||
EXPECT_TRUE(r.isNullValue(0));
|
||||
EXPECT_TRUE(r.isNullValue(1));
|
||||
EXPECT_TRUE(r.isNullValue(2));
|
||||
EXPECT_TRUE(r.isNullValue(3));
|
||||
EXPECT_TRUE(r.isNullValue(4));
|
||||
EXPECT_TRUE(r.isNullValue(5));
|
||||
}
|
||||
|
||||
TEST_F(RowDecimalTest, getBinaryFieldCheck) {
|
||||
rg.getRow(0, &r);
|
||||
uint128_t* u128Value;
|
||||
int128_t* s128Value;
|
||||
// std::remove_reference<decltype(*u128Value)>::type uType;
|
||||
// std::remove_reference<decltype(*s128Value)>::type sType;
|
||||
|
||||
for (size_t i = 0; i < sValueVector.size(); i++) {
|
||||
s128Value = r.getBinaryField<int128_t>(0);
|
||||
EXPECT_EQ(sValueVector[i], *s128Value);
|
||||
u128Value = r.getBinaryField<uint128_t>(1);
|
||||
EXPECT_EQ(uValueVector[i], *u128Value);
|
||||
//EXPECT_EQ(s64ValueVector[i], r.getIntField(2));
|
||||
//EXPECT_EQ(s32ValueVector[i],r.getIntField(3));
|
||||
//EXPECT_EQ(r.getIntField(4),s16ValueVector[i]);
|
||||
//EXPECT_EQ(r.getIntField(5),s8ValueVector[i]);
|
||||
r.nextRow(rowSize);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RowDecimalTest, toStringCheck) {
|
||||
std::vector<std::string> exemplarVector;
|
||||
exemplarVector.push_back(std::string("0: NULL NULL NULL NULL NULL NULL "));
|
||||
exemplarVector.push_back(std::string("0: -42 42 -121 -121 -121 -121 "));
|
||||
exemplarVector.push_back(std::string("0: -79228162495817593515539431425 -79228162495817593515539431425 0 0 0 0 "));
|
||||
exemplarVector.push_back(std::string("0: 0 0 129 129 129 -127 "));
|
||||
exemplarVector.push_back(std::string("0: -3 -3 9223372036854775807 2147483647 32767 127 "));
|
||||
|
||||
rg.getRow(0, &r);
|
||||
r.initToNull();
|
||||
for (auto &el: exemplarVector) {
|
||||
EXPECT_EQ(el, r.toString());
|
||||
r.nextRow(rowSize);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RowDecimalTest, toCSVCheck) {
|
||||
}
|
||||
|
||||
TEST_F(RowDecimalTest, applyMappingCheck) {
|
||||
int mapping[] = {0, 1, -1, -1, -1, -1};
|
||||
rg.getRow(1, &r);
|
||||
rg.getRow(2, &rOutMappingCheck);
|
||||
int128_t* s128Value = rOutMappingCheck.getBinaryField<int128_t>(0);
|
||||
uint128_t* u128Value = rOutMappingCheck.getBinaryField<uint128_t>(1);
|
||||
EXPECT_NE(sValueVector[1], *s128Value);
|
||||
EXPECT_NE(uValueVector[1], *u128Value);
|
||||
applyMapping(mapping, r, &rOutMappingCheck);
|
||||
s128Value = rOutMappingCheck.getBinaryField<int128_t>(0);
|
||||
EXPECT_EQ(sValueVector[1], *s128Value);
|
||||
u128Value = rOutMappingCheck.getBinaryField<uint128_t>(1);
|
||||
EXPECT_EQ(uValueVector[1], *u128Value);
|
||||
}
|
||||
|
||||
// WIP
|
||||
TEST_F(RowDecimalTest, RowEqualsCheck) {
|
||||
}
|
Reference in New Issue
Block a user