1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

MCOL-271 empty strings should not be NULLs (#2794)

This patch improves handling of NULLs in textual fields in ColumnStore.
Previously empty strings were considered NULLs and it could be a problem
if data scheme allows for empty strings. It was also one of major
reasons of behavior difference between ColumnStore and other engines in
MariaDB family.

Also, this patch fixes some other bugs and incorrect behavior, for
example, incorrect comparison for "column <= ''" which evaluates to
constant True for all purposes before this patch.
This commit is contained in:
Sergey Zefirov
2023-03-30 17:26:45 +01:00
committed by Roman Nozdrin
parent 0ea592da80
commit b53c231ca6
417 changed files with 12459 additions and 3520 deletions

View File

@ -162,7 +162,7 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
// Turn on Null flags or skip based on respect nulls
flags[k] = 0;
if ((!cc && fRow.isNullValue(colIn) == true) || (cc && cc->type() == ConstantColumn::NULLDATA))
if ((!cc && fRow.isNullValue(colIn) == true) || (cc && cc->isNull()))
{
if (!bRespectNulls)
{
@ -450,11 +450,11 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
case CalpontSystemCatalog::TEXT:
case CalpontSystemCatalog::BLOB:
{
string valIn;
utils::NullString valIn;
if (cc)
{
valIn = cc->getStrVal(fRow, isNull);
valIn = cc->getStrVal(fRow, isNull); // XXX: we probably need to change Distinctmap.
}
else
{
@ -548,7 +548,7 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut, int64_t b, i
static const static_any::any& ullTypeId = (unsigned long long)1;
static const static_any::any& floatTypeId = (float)1;
static const static_any::any& doubleTypeId = (double)1;
static const std::string typeStr("");
static const std::string typeStr;
static const static_any::any& strTypeId = typeStr;
CDT colDataType = fRow.getColType(colOut);
@ -661,7 +661,7 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut, int64_t b, i
if (valOut.compatible(strTypeId))
{
std::string strOut = valOut.cast<std::string>();
strOut = valOut.cast<std::string>();
// Convert the string to numeric type, just in case.
intOut = atol(strOut.c_str());
uintOut = strtoul(strOut.c_str(), NULL, 10);
@ -756,11 +756,12 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut, int64_t b, i
case execplan::CalpontSystemCatalog::BLOB:
if (valOut.empty())
{
setValue(colDataType, b, e, c, (string*)NULL);
setValue(colDataType, b, e, c, (utils::NullString*)NULL);
}
else
{
setValue(colDataType, b, e, c, &strOut);
utils::NullString nullStrOut(strOut);
setValue(colDataType, b, e, c, &nullStrOut);
}
break;
@ -845,7 +846,7 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
// Turn on Null flags or skip based on respect nulls
flags[k] = 0;
if ((!cc && fRow.isNullValue(colIn) == true) || (cc && cc->type() == ConstantColumn::NULLDATA))
if ((!cc && fRow.isNullValue(colIn) == true) || (cc && cc->isNull()))
{
if (!bRespectNulls)
{
@ -1112,11 +1113,11 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
case CalpontSystemCatalog::TEXT:
case CalpontSystemCatalog::BLOB:
{
string valIn;
utils::NullString valIn;
if (cc)
{
valIn = cc->getStrVal(fRow, isNull);
valIn = cc->getStrVal(fRow, isNull); // XXX: the same problem with distinct.
}
else
{
@ -1127,7 +1128,7 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
// Currently, distinct only works on the first parameter.
if (k == 0 && fDistinct)
{
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
std::pair<static_any::any, uint64_t> val = make_pair(valIn.isNull() ? nullptr : valIn.safeString(""), 1);
std::pair<DistinctMap::iterator, bool> distinct;
distinct = fDistinctMap.insert(val);
if (distinct.second == false)
@ -1138,7 +1139,7 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
}
}
datum.columnData = valIn;
datum.columnData = valIn.isNull() ? nullptr : valIn.safeString("");
break;
}