1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-06-16 14:20:56 +03:00

Dataconvert::decimalToString badly fails w/o 20th member of mcs_pow_10 so I returned it

WF::percentile runtime threw an exception b/c of wrong DT deduced from its argument

Replaced literals with constants

Tought WF_sum_avg::checkSumLimit to use refs instead of values
This commit is contained in:
Roman Nozdrin
2020-08-27 17:04:29 +00:00
parent af80081c94
commit 1c3a34a3d0
13 changed files with 76 additions and 143 deletions

View File

@ -82,7 +82,7 @@ constexpr uint8_t MAXLEGACYWIDTH = 8U;
constexpr uint8_t MAXSCALEINC4AVG = 4U; constexpr uint8_t MAXSCALEINC4AVG = 4U;
constexpr int8_t IGNOREPRECISION = -1; constexpr int8_t IGNOREPRECISION = -1;
const int64_t mcs_pow_10[19] = const uint64_t mcs_pow_10[20] =
{ {
1ULL, 1ULL,
10ULL, 10ULL,
@ -103,6 +103,7 @@ const int64_t mcs_pow_10[19] =
10000000000000000ULL, 10000000000000000ULL,
100000000000000000ULL, 100000000000000000ULL,
1000000000000000000ULL, 1000000000000000000ULL,
10000000000000000000ULL,
}; };
const int128_t mcs_pow_10_128[20] = const int128_t mcs_pow_10_128[20] =
{ {

View File

@ -52,8 +52,6 @@ using namespace rowgroup;
#include "joblisttypes.h" #include "joblisttypes.h"
using namespace joblist; using namespace joblist;
#include "widedecimalutils.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#define strcasecmp stricmp #define strcasecmp stricmp
#endif #endif
@ -389,7 +387,8 @@ void WindowFunctionColumn::adjustResultType()
if (boost::iequals(fFunctionName, "SUM") || if (boost::iequals(fFunctionName, "SUM") ||
boost::iequals(fFunctionName, "AVG") || boost::iequals(fFunctionName, "AVG") ||
boost::iequals(fFunctionName, "AVG_DISTINCT")) boost::iequals(fFunctionName, "AVG_DISTINCT") ||
boost::iequals(fFunctionName, "PERCENTILE"))
{ {
if (fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::DECIMAL || if (fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::DECIMAL ||
fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::UDECIMAL) fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::UDECIMAL)
@ -689,7 +688,7 @@ void WindowFunctionColumn::evaluate(Row& row, bool& isNull)
case 16: case 16:
{ {
int128_t dec = row.getInt128Field(fInputIndex); int128_t dec = row.getInt128Field(fInputIndex);
if (utils::isWideDecimalNullValue(dec)) if (dec == datatypes::Decimal128Null)
isNull = true; isNull = true;
else else
{ {

View File

@ -21,6 +21,7 @@
#include "moda.h" #include "moda.h"
#include "bytestream.h" #include "bytestream.h"
#include "objectreader.h" #include "objectreader.h"
#include "columnwidth.h"
using namespace mcsv1sdk; using namespace mcsv1sdk;
@ -186,7 +187,7 @@ mcsv1_UDAF::ReturnCode moda::init(mcsv1Context* context,
{ {
context->setColWidth(8); context->setColWidth(8);
} }
else else if (utils::widthByPrecision(colTypes[0].precision))
{ {
context->setColWidth(16); context->setColWidth(16);
} }

View File

@ -962,11 +962,15 @@ inline long double Row::getLongDoubleField(uint32_t colIndex) const
return *((long double*) &data[offsets[colIndex]]); return *((long double*) &data[offsets[colIndex]]);
} }
// !!! Never ever try to remove inline from this f() b/c it returns
// non-integral 16 byte DT
inline int128_t Row::getInt128Field(uint32_t colIndex) const inline int128_t Row::getInt128Field(uint32_t colIndex) const
{ {
return *((int128_t*) &data[offsets[colIndex]]); return *((int128_t*) &data[offsets[colIndex]]);
} }
// !!! Never ever try to remove inline from this f() b/c it returns
// non-integral 16 byte DT
inline uint128_t Row::getUint128Field(uint32_t colIndex) const inline uint128_t Row::getUint128Field(uint32_t colIndex) const
{ {
return *((uint128_t*) &data[offsets[colIndex]]); return *((uint128_t*) &data[offsets[colIndex]]);

View File

@ -856,11 +856,11 @@ bool EqualCompData::operator()(Row::Pointer a, Row::Pointer b)
case CalpontSystemCatalog::UDECIMAL: case CalpontSystemCatalog::UDECIMAL:
{ {
// equal compare. ignore sign and null // equal compare. ignore sign and null
if (fRow1.getColumnWidth(*i) < 16) if (fRow1.getColumnWidth(*i) < datatypes::MAXDECIMALWIDTH)
{ {
eq = (fRow1.getUintField(*i) == fRow2.getUintField(*i)); eq = (fRow1.getUintField(*i) == fRow2.getUintField(*i));
} }
else else if (fRow1.getColumnWidth(*i) == datatypes::MAXDECIMALWIDTH)
{ {
eq = (fRow1.getUint128Field(*i) == fRow2.getUint128Field(*i)); eq = (fRow1.getUint128Field(*i) == fRow2.getUint128Field(*i));
} }

View File

@ -78,11 +78,11 @@ boost::shared_ptr<WindowFunctionType> WF_count<T>::makeFunction(int id, const st
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL: case CalpontSystemCatalog::UDECIMAL:
{ {
if (wc->functionParms()[0]->resultType().colWidth < 16) if (wc->functionParms()[0]->resultType().colWidth < datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_count<int64_t>(id, name)); func.reset(new WF_count<int64_t>(id, name));
} }
else else if (wc->functionParms()[0]->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_count<int128_t>(id, name)); func.reset(new WF_count<int128_t>(id, name));
} }

View File

@ -85,11 +85,11 @@ boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
{ {
if (wc->functionParms()[0]->resultType().colWidth < 16) if (wc->functionParms()[0]->resultType().colWidth < datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_lead_lag<int64_t>(id, name)); func.reset(new WF_lead_lag<int64_t>(id, name));
} }
else else if (wc->functionParms()[0]->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_lead_lag<int128_t>(id, name)); func.reset(new WF_lead_lag<int128_t>(id, name));
} }

View File

@ -84,31 +84,19 @@ boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, cons
} }
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL:
{ {
if (wc->functionParms()[0]->resultType().colWidth < 16) if (wc->functionParms()[0]->resultType().colWidth < datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_nth_value<int64_t>(id, name)); func.reset(new WF_nth_value<int64_t>(id, name));
} }
else else if (wc->functionParms()[0]->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_nth_value<int128_t>(id, name)); func.reset(new WF_nth_value<int128_t>(id, name));
} }
break; break;
} }
case CalpontSystemCatalog::UDECIMAL:
{
if (wc->functionParms()[0]->resultType().colWidth < 16)
{
func.reset(new WF_nth_value<uint64_t>(id, name));
}
else
{
func.reset(new WF_nth_value<uint128_t>(id, name));
}
break;
}
case CalpontSystemCatalog::DOUBLE: case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE: case CalpontSystemCatalog::UDOUBLE:
{ {

View File

@ -46,6 +46,8 @@ using namespace ordering;
#include "constantcolumn.h" #include "constantcolumn.h"
using namespace execplan; using namespace execplan;
#include "mcs_decimal.h"
#include "windowfunctionstep.h" #include "windowfunctionstep.h"
using namespace joblist; using namespace joblist;
@ -89,31 +91,19 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
} }
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL:
{ {
if (wc->functionParms()[0]->resultType().colWidth < 16) if (wc->resultType().colWidth < datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_percentile<int64_t>(id, name)); func.reset(new WF_percentile<int64_t>(id, name));
} }
else else if (wc->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_percentile<int128_t>(id, name)); func.reset(new WF_percentile<int128_t>(id, name));
} }
break; break;
} }
case CalpontSystemCatalog::UDECIMAL:
{
if (wc->functionParms()[0]->resultType().colWidth < 16)
{
func.reset(new WF_percentile<uint64_t>(id, name));
}
else
{
func.reset(new WF_percentile<uint128_t>(id, name));
}
break;
}
case CalpontSystemCatalog::DOUBLE: case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE: case CalpontSystemCatalog::UDOUBLE:
{ {

View File

@ -82,30 +82,18 @@ boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const st
} }
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL:
{ {
if (wc->functionParms()[0]->resultType().colWidth < 16) if (wc->functionParms()[0]->resultType().colWidth < datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_stats<int64_t>(id, name)); func.reset(new WF_stats<int64_t>(id, name));
} }
else else if (wc->functionParms()[0]->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_stats<int128_t>(id, name)); func.reset(new WF_stats<int128_t>(id, name));
} }
break; break;
} }
case CalpontSystemCatalog::UDECIMAL:
{
if (wc->functionParms()[0]->resultType().colWidth < 16)
{
func.reset(new WF_stats<uint64_t>(id, name));
}
else
{
func.reset(new WF_stats<uint128_t>(id, name));
}
break;
}
case CalpontSystemCatalog::DOUBLE: case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE: case CalpontSystemCatalog::UDOUBLE:

View File

@ -52,35 +52,49 @@ using namespace joblist;
namespace windowfunction namespace windowfunction
{ {
template<typename T_IN, typename T_OUT>
void WF_sum_avg<T_IN, T_OUT>::checkSumLimit(long double val, long double sum)
{
}
template<typename T_IN, typename T_OUT> template<typename T_IN, typename T_OUT>
inline void WF_sum_avg<T_IN, T_OUT>::checkSumLimit(int128_t val, int128_t sum) inline void WF_sum_avg<T_IN,T_OUT>::checkSumLimit(T_IN& val, T_OUT& sum)
{ }
template<>
inline void WF_sum_avg<int128_t,int128_t>::checkSumLimit(int128_t& val, int128_t& sum)
{ {
if (((sum >= 0) && ((fMax128 - sum) < val)) || datatypes::AdditionOverflowCheck ofCheckOp;
((sum < 0) && ((fMin128 - sum) > val))) ofCheckOp(sum, val);
{
string errStr = "SUM(int128_t)";
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
cerr << errStr << endl;
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
}
} }
template<typename T_IN, typename T_OUT> template<>
inline void WF_sum_avg<T_IN, T_OUT>::checkSumLimit(uint128_t val, uint128_t sum) inline void WF_sum_avg<long double,long double>::checkSumLimit(long double& val, long double& sum)
{ { }
if ((fMaxu128 - sum) < val)
{ template<>
string errStr = "SUM(uint128_t)"; inline void WF_sum_avg<float, long double>::checkSumLimit(float&, long double&)
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr); { }
cerr << errStr << endl;
throw IDBExcept(errStr, ERR_WF_OVERFLOW); template<>
} inline void WF_sum_avg<long, long double>::checkSumLimit(long&, long double&)
} { }
template<>
inline void WF_sum_avg<unsigned long, long double>::checkSumLimit(unsigned long&, long double&)
{ }
template<>
inline void WF_sum_avg<double, long double>::checkSumLimit(double&, long double&)
{ }
template<>
void WF_sum_avg<int128_t,int128_t>::checkSumLimit(int128_t& val, int128_t& sum);
template<>
void WF_sum_avg<long double,long double>::checkSumLimit(long double& val, long double& sum);
template<>
void WF_sum_avg<float, long double>::checkSumLimit(float&, long double&);
template<>
void WF_sum_avg<long, long double>::checkSumLimit(long&, long double&);
template<>
void WF_sum_avg<unsigned long, long double>::checkSumLimit(unsigned long&, long double&);
template<>
void WF_sum_avg<double, long double>::checkSumLimit(double&, long double&);
template<typename T_IN, typename T_OUT> template<typename T_IN, typename T_OUT>
int128_t WF_sum_avg<T_IN, T_OUT>::calculateAvg(int128_t sum, uint64_t count, int scale) int128_t WF_sum_avg<T_IN, T_OUT>::calculateAvg(int128_t sum, uint64_t count, int scale)
@ -118,41 +132,6 @@ int128_t WF_sum_avg<T_IN, T_OUT>::calculateAvg(int128_t sum, uint64_t count, int
return avg; return avg;
} }
template<typename T_IN, typename T_OUT>
uint128_t WF_sum_avg<T_IN, T_OUT>::calculateAvg(uint128_t sum, uint64_t count, int scale)
{
uint128_t avg = 0;
uint128_t factor;
datatypes::getScaleDivisor(factor, scale);
if (scale > 0)
{
if ((sum * factor) / factor == sum)
{
avg = sum * factor;
avg /= count;
}
else
{
// scale won't fit before divide, we're gonna lose precision.
avg = sum / count;
if ((avg * factor) / factor != avg) // Still won't fit
{
string errStr = string("AVG(int)");
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
cerr << errStr << endl;
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
}
avg *= factor;
}
}
else
{
avg = sum / count;
}
avg += 0.5;
return avg;
}
template<typename T_IN, typename T_OUT> template<typename T_IN, typename T_OUT>
inline long double WF_sum_avg<T_IN, T_OUT>::calculateAvg(long double sum, uint64_t count, int scale) inline long double WF_sum_avg<T_IN, T_OUT>::calculateAvg(long double sum, uint64_t count, int scale)
{ {
@ -188,31 +167,19 @@ boost::shared_ptr<WindowFunctionType> WF_sum_avg<T_IN, T_OUT>::makeFunction(int
} }
case CalpontSystemCatalog::DECIMAL: case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL:
{ {
if (wc->functionParms()[0]->resultType().colWidth < 16) if (wc->functionParms()[0]->resultType().colWidth < datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_sum_avg<int64_t, int128_t>(id, name)); func.reset(new WF_sum_avg<int64_t, int128_t>(id, name));
} }
else else if (wc->functionParms()[0]->resultType().colWidth == datatypes::MAXDECIMALWIDTH)
{ {
func.reset(new WF_sum_avg<int128_t, int128_t>(id, name)); func.reset(new WF_sum_avg<int128_t, int128_t>(id, name));
} }
break; break;
} }
case CalpontSystemCatalog::UDECIMAL:
{
if (wc->functionParms()[0]->resultType().colWidth < 16)
{
func.reset(new WF_sum_avg<uint64_t, uint128_t>(id, name));
}
else
{
func.reset(new WF_sum_avg<uint128_t, uint128_t>(id, name));
}
break;
}
case CalpontSystemCatalog::DOUBLE: case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE: case CalpontSystemCatalog::UDOUBLE:
{ {

View File

@ -39,9 +39,6 @@ public:
WindowFunctionType(id, name), fDistinct(id != WF__SUM && id != WF__AVG) WindowFunctionType(id, name), fDistinct(id != WF__SUM && id != WF__AVG)
{ {
resetData(); resetData();
utils::int128Max(fMax128);
utils::int128Min(fMin128);
utils::uint128Max(fMaxu128);
} }
// pure virtual in base // pure virtual in base
@ -58,19 +55,17 @@ protected:
uint64_t fCount; uint64_t fCount;
bool fDistinct; bool fDistinct;
std::set<T_IN> fSet; std::set<T_IN> fSet;
int128_t fMax128;
int128_t fMin128;
uint128_t fMaxu128;
void checkSumLimit(long double val, long double sum); void checkSumLimit(T_IN& val, T_OUT& sum);
void checkSumLimit(int128_t val, int128_t sum);
void checkSumLimit(uint128_t val, uint128_t sum);
int128_t calculateAvg(int128_t sum, uint64_t count, int scale); int128_t calculateAvg(int128_t sum, uint64_t count, int scale);
uint128_t calculateAvg(uint128_t sum, uint64_t count, int scale);
long double calculateAvg(long double sum, uint64_t count, int scale); long double calculateAvg(long double sum, uint64_t count, int scale);
}; };
template<>
void WF_sum_avg<long double,long double>::checkSumLimit(long double& val, long double& sum);
} // namespace } // namespace
#endif // UTILS_WF_SUM_AVG_H #endif // UTILS_WF_SUM_AVG_H

View File

@ -423,7 +423,7 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std:
// call the write engine to write the rows // call the write engine to write the rows
int error = NO_ERROR; int error = NO_ERROR;
// WIP // MCOL-641 WIP
fWEWrapper.setDebugLevel(WriteEngine::DEBUG_3); fWEWrapper.setDebugLevel(WriteEngine::DEBUG_3);
cout << "inserting a row with transaction id " << txnid.id << endl; cout << "inserting a row with transaction id " << txnid.id << endl;
fWEWrapper.setIsInsert(true); fWEWrapper.setIsInsert(true);