1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

MCOL-1822 finishing up use long double for SUM/AVG

This commit is contained in:
David Hall
2019-03-01 17:34:57 -06:00
parent cf056e42ac
commit 9e1cec56b1
5 changed files with 67 additions and 42 deletions

View File

@@ -278,11 +278,42 @@ inline bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, Retu
return false;
long double val1 = lop->getLongDoubleVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getLongDoubleVal(row, isNull)) && !isNull;
long double val2 = rop->getLongDoubleVal(row, isNull);
if (isNull)
return false;
// In many case, rounding error will prevent an eq compare to work
// In these cases, use the largest scale of the two items.
if (fOp == execplan::OP_EQ)
{
// In case a val is a representation of a very large integer,
// we won't want to just multiply by scale, as it may move
// significant digits out of scope. So we break them apart
// and compare each separately
int64_t scale = max(lop->resultType().scale, rop->resultType().scale);
if (scale)
{
long double intpart1;
long double fract1 = modfl(val1, &intpart1);
long double intpart2;
long double fract2 = modfl(val2, &intpart2);
if (numericCompare(intpart1, intpart2))
{
double factor = pow(10.0, (double)scale);
fract1 = roundl(fract1 * factor);
fract2 = roundl(fract2 * factor);
return numericCompare(fract1, fract2);
}
else
{
return false;
}
}
}
return numericCompare(val1, val2);
}
case execplan::CalpontSystemCatalog::DECIMAL:

View File

@@ -378,6 +378,14 @@ void WindowFunctionColumn::adjustResultType()
boost::iequals(fFunctionName, "NTH_VALUE")) &&
!fFunctionParms.empty())
fResultType = fFunctionParms[0]->resultType();
if (boost::iequals(fFunctionName, "SUM") ||
boost::iequals(fFunctionName, "AVG"))
{
fResultType.colDataType = CalpontSystemCatalog::LONGDOUBLE;
fResultType.colWidth = sizeof(long double);
fResultType.precision = -1;
}
}
void WindowFunctionColumn::evaluate(Row& row, bool& isNull)

View File

@@ -897,7 +897,13 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
setError(gwi.thd, ER_CHECK_NOT_IMPLEMENTED, gwi.parseErrorText);
return NULL;
}
#if 0
if (item_sum->sum_func() != Item_sum::UDF_SUM_FUNC &&
item_sum->sum_func() != Item_sum::SUM_FUNC &&
item_sum->sum_func() != Item_sum::SUM_DISTINCT_FUNC &&
item_sum->sum_func() != Item_sum::AVG_FUNC &&
item_sum->sum_func() != Item_sum::AVG_DISTINCT_FUNC)
#endif
if (item_sum->sum_func() != Item_sum::UDF_SUM_FUNC)
{
ac->resultType(colType_MysqlToIDB(item_sum));