You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
feat(datatypes): MCOL-4632 and MCOL-4648, fix cast leads to NULL.
Remove redundant cast. As C-style casts with a type name in parantheses are interpreted as static_casts this literally just changes the interpretation around (and forces an implicit cast to match the return value of the function). Switch UBIGINTNULL and UBIGINTEMPTYROW constants for consistency. Make consistent with relation between BIGINTNULL and BIGINTEMPTYROW & make adapted cast behaviour due to NULL markers more intuitive. (After this change we can simply block the highest possible uint64_t value and if a cast results in it, print the next lower value (2^64 - 2). Previously, (2^64 - 1) was able to be printed, but (2^64 - 2) as being blocked by the UBIGINTNULL constant was not, making finding the appropiate replacement value to give out more confusing. Introduce MAX_MCS_UBIGINT and MIN_MCS_BIGINT and adapt casts. Adapt casting to BIGINT to remove NULL marker error. Add bugfix regression test for MCOL 4632 Add regression test for mcol_4648 Revert "Switch UBIGINTNULL and UBIGINTEMPTYROW constants for consistency." This reverts commit 83eac11b18937ecb0b4c754dd48e4cb47310f620. Due to backwards compatability issues. Refactor casting to MCS[U]Int to datatype functions. Update regression tests to include other affected datatypes. Apply formatting. Refactor according to PR review Remove redundant new constant, switch to using already existing constant. Adapt nullstring casting to EMPTYROW markers for backwards compatability. Adapt tests for backward compatability behaviour allowing text datatypes to be casted to EMPTYROW constant. Adapt mcol641-functions test according to bug fix. Update tests according to new expected behaviour. Adapt tests to new understanding of issue. Update comments/documentation for MCOL_4632 test. Adapt to new cast limit logic. Make bracketing consistent. Adapt previous regression test to new expected behaviour.
This commit is contained in:
@ -21,10 +21,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include "exceptclasses.h"
|
||||
#include "conststring.h"
|
||||
#include "mcs_datatype_basic.h"
|
||||
|
||||
namespace utils
|
||||
{
|
||||
@ -42,7 +44,8 @@ class NullString
|
||||
{
|
||||
idbassert(str != nullptr || length == 0);
|
||||
|
||||
if (str) {
|
||||
if (str)
|
||||
{
|
||||
mStrPtr.reset(new std::string((const char*)str, length));
|
||||
}
|
||||
}
|
||||
@ -64,6 +67,28 @@ class NullString
|
||||
}
|
||||
return ConstString(mStrPtr->c_str(), mStrPtr->length());
|
||||
}
|
||||
uint64_t toMCSUInt64() const
|
||||
{
|
||||
if (isNull())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint64_t val = static_cast<uint64_t>(strtoul(str(), 0, 0));
|
||||
//@Bug 4632 and 4648: Don't return marker value for NULL, but allow return of marker value for EMPTYROW.
|
||||
return val == joblist::UBIGINTNULL ? MAX_UBIGINT : val;
|
||||
}
|
||||
int64_t toMCSInt64() const
|
||||
{
|
||||
if (isNull())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int64_t val = static_cast<int64_t>(atoll(str()));
|
||||
//@Bug 4632 and 4648: Don't return marker value for NULL, but allow return of marker value for EMPTYROW.
|
||||
return std::max(val, static_cast<int64_t>(joblist::BIGINTEMPTYROW));
|
||||
}
|
||||
const char* str() const
|
||||
{
|
||||
if (!mStrPtr)
|
||||
@ -119,7 +144,7 @@ class NullString
|
||||
}
|
||||
NullString& rtrimZero()
|
||||
{
|
||||
return *this; // TODO
|
||||
return *this; // TODO
|
||||
}
|
||||
// this can be used to safely get a string value, with default value for NULL substitution.
|
||||
// it does not raise anything and provides some nonsensical default value for you that will be
|
||||
@ -163,7 +188,7 @@ class NullString
|
||||
}
|
||||
// XXX: here we implement what Row::equals expects.
|
||||
// It is not SQL-NULL-handling compatible, please beware.
|
||||
bool operator ==(const NullString& a) const
|
||||
bool operator==(const NullString& a) const
|
||||
{
|
||||
if (!mStrPtr && !a.mStrPtr)
|
||||
{
|
||||
@ -180,7 +205,7 @@ class NullString
|
||||
// fall to std::string equality.
|
||||
return (*mStrPtr) == (*a.mStrPtr);
|
||||
}
|
||||
bool operator ==(const std::string& a) const
|
||||
bool operator==(const std::string& a) const
|
||||
{
|
||||
if (!mStrPtr)
|
||||
{
|
||||
@ -189,7 +214,7 @@ class NullString
|
||||
// fall to std::string equality.
|
||||
return (*mStrPtr) == a;
|
||||
}
|
||||
bool operator <(const NullString& a) const
|
||||
bool operator<(const NullString& a) const
|
||||
{
|
||||
// order NULLs first.
|
||||
if (isNull() > a.isNull())
|
||||
@ -205,13 +230,12 @@ class NullString
|
||||
// fall to std::string equality.
|
||||
return (*mStrPtr) < (*a.mStrPtr);
|
||||
}
|
||||
return false; // both are NULLs.
|
||||
return false; // both are NULLs.
|
||||
}
|
||||
bool operator >(const NullString& a) const
|
||||
bool operator>(const NullString& a) const
|
||||
{
|
||||
return a < (*this);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace utils.
|
||||
|
||||
} // namespace utils.
|
||||
|
@ -118,7 +118,7 @@ int64_t Func_cast_signed::getIntVal(Row& row, FunctionParm& parm, bool& isNull,
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
{
|
||||
return (int64_t)parm[0]->data()->getUintVal(row, isNull);
|
||||
return datatypes::TUInt64(parm[0]->data()->getUintVal(row, isNull)).toMCSInt64();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -127,15 +127,13 @@ int64_t Func_cast_signed::getIntVal(Row& row, FunctionParm& parm, bool& isNull,
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
datatypes::TDouble d(parm[0]->data()->getDoubleVal(row, isNull));
|
||||
return d.toMCSSInt64Round();
|
||||
return datatypes::TDouble(parm[0]->data()->getDoubleVal(row, isNull)).toMCSSInt64Round();
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
datatypes::TLongDouble d(parm[0]->data()->getLongDoubleVal(row, isNull));
|
||||
return d.toMCSSInt64Round();
|
||||
return datatypes::TLongDouble(parm[0]->data()->getLongDoubleVal(row, isNull)).toMCSSInt64Round();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -143,22 +141,14 @@ int64_t Func_cast_signed::getIntVal(Row& row, FunctionParm& parm, bool& isNull,
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
const auto& value = parm[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
{
|
||||
isNull = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return atoll(value.str());
|
||||
return parm[0]->data()->getStrVal(row, isNull).toMCSInt64();
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
return parm[0]->data()->getDecimalVal(row, isNull).toSInt64Round();
|
||||
return parm[0]->data()->getDecimalVal(row, isNull).toMCSInt64Round();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -224,7 +214,7 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row, FunctionParm& parm, bool& isNu
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
{
|
||||
return (int64_t)parm[0]->data()->getUintVal(row, isNull);
|
||||
return parm[0]->data()->getUintVal(row, isNull);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -243,15 +233,13 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row, FunctionParm& parm, bool& isNu
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
datatypes::TDouble d(parm[0]->data()->getDoubleVal(row, isNull));
|
||||
return d.toMCSUInt64Round();
|
||||
return datatypes::TDouble(parm[0]->data()->getDoubleVal(row, isNull)).toMCSUInt64Round();
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
datatypes::TLongDouble d(parm[0]->data()->getLongDoubleVal(row, isNull));
|
||||
return d.toMCSUInt64Round();
|
||||
return datatypes::TLongDouble(parm[0]->data()->getLongDoubleVal(row, isNull)).toMCSUInt64Round();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -259,24 +247,14 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row, FunctionParm& parm, bool& isNu
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
const auto& value = parm[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
if (isNull)
|
||||
{
|
||||
isNull = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t ret = strtoul(value.str(), 0, 0);
|
||||
return ret;
|
||||
return parm[0]->data()->getStrVal(row, isNull).toMCSUInt64();
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
|
||||
return d.toUInt64Round();
|
||||
return parm[0]->data()->getDecimalVal(row, isNull).toMCSUInt64Round();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -659,7 +637,8 @@ int64_t Func_cast_date::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& parm
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
val = dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull).safeString(""));
|
||||
val =
|
||||
dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull).safeString(""));
|
||||
|
||||
if (val == -1)
|
||||
isNull = true;
|
||||
@ -821,7 +800,8 @@ int64_t Func_cast_datetime::getDatetimeIntVal(rowgroup::Row& row, FunctionParm&
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
{
|
||||
val = dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull).safeString(""));
|
||||
val =
|
||||
dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull).safeString(""));
|
||||
|
||||
if (val == -1)
|
||||
isNull = true;
|
||||
|
Reference in New Issue
Block a user