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
MCOL-4171
This commit is contained in:
committed by
Roman Nozdrin
parent
5287e6860b
commit
638202417f
@ -285,7 +285,6 @@ void FrameBoundExpressionRange<T>::validate()
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
int64_t tmp = this->fRow.getIntField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
@ -299,6 +298,33 @@ void FrameBoundExpressionRange<T>::validate()
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (this->fRow.getColumnWidth(this->fIndex[1]) < 16)
|
||||
{
|
||||
int64_t tmp = this->fRow.getIntField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
|
||||
if (tmp < 0)
|
||||
{
|
||||
invalid = true;
|
||||
oss << "<negative>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int128_t tmp = this->fRow.getInt128Field(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
|
||||
if (tmp < 0)
|
||||
{
|
||||
invalid = true;
|
||||
oss << "<negative>";
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
@ -343,15 +369,30 @@ void FrameBoundExpressionRange<T>::validate()
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (this->fRow.getColumnWidth(this->fIndex[1]) < 16)
|
||||
{
|
||||
uint64_t tmp = this->fRow.getUintField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint128_t tmp = this->fRow.getUint128Field(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
default:
|
||||
{
|
||||
int64_t tmp = this->fRow.getIntField(this->fIndex[1]);
|
||||
uint64_t tmp = this->fRow.getUintField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
break;
|
||||
}
|
||||
|
@ -610,7 +610,7 @@ void CompareRule::compileRules(const std::vector<IdbSortSpec>& spec, const rowgr
|
||||
case datatypes::MAXDECIMALWIDTH:
|
||||
c = new WideDecimalCompare(*i, offsets[i->fIndex]); break;
|
||||
case datatypes::MAXLEGACYWIDTH:
|
||||
c = new BigIntCompare(*i);
|
||||
c = new BigIntCompare(*i); break;
|
||||
case 1 :
|
||||
c = new TinyIntCompare(*i); break;
|
||||
case 2 :
|
||||
@ -837,8 +837,6 @@ bool EqualCompData::operator()(Row::Pointer a, Row::Pointer b)
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
@ -854,6 +852,21 @@ bool EqualCompData::operator()(Row::Pointer a, Row::Pointer b)
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
// equal compare. ignore sign and null
|
||||
if (fRow1.getColumnWidth(*i) < 16)
|
||||
{
|
||||
eq = (fRow1.getUintField(*i) == fRow2.getUintField(*i));
|
||||
}
|
||||
else
|
||||
{
|
||||
eq = (fRow1.getUint128Field(*i) == fRow2.getUint128Field(*i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ namespace windowfunction
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_count<T>::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_count<T>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
@ -70,7 +70,25 @@ boost::shared_ptr<WindowFunctionType> WF_count<T>::makeFunction(int id, const st
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::BINARY:
|
||||
{
|
||||
std::cout << __FILE__<< ":" <<__LINE__ << " Fix for 16 Bytes ?" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_count<int64_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_count<int128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
func.reset(new WF_count<int64_t>(id, name));
|
||||
break;
|
||||
@ -176,7 +194,7 @@ void WF_count<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_count<int64_t>::makeFunction(int, const string&, int);
|
||||
boost::shared_ptr<WindowFunctionType> WF_count<int64_t>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
|
||||
} //namespace
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace windowfunction
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
@ -64,7 +64,6 @@ boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_lead_lag<int64_t>(id, name));
|
||||
break;
|
||||
@ -75,7 +74,6 @@ boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
case CalpontSystemCatalog::TIMESTAMP:
|
||||
@ -85,6 +83,32 @@ boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_lead_lag<int64_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_lead_lag<int128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_lead_lag<uint64_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_lead_lag<uint128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
@ -293,10 +317,12 @@ void WF_lead_lag<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_lead_lag<int64_t>::makeFunction(int, const string&, int);
|
||||
boost::shared_ptr<WindowFunctionType> WF_lead_lag<int64_t>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
template void WF_lead_lag<int64_t>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<uint64_t>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<int128_t>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<uint128_t>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<float>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<double>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<string>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
T fValue;
|
||||
|
@ -52,7 +52,7 @@ namespace windowfunction
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_min_max<T>::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_min_max<T>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
@ -63,7 +63,6 @@ boost::shared_ptr<WindowFunctionType> WF_min_max<T>::makeFunction(int id, const
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_min_max<int64_t>(id, name));
|
||||
break;
|
||||
@ -74,7 +73,6 @@ boost::shared_ptr<WindowFunctionType> WF_min_max<T>::makeFunction(int id, const
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
case CalpontSystemCatalog::TIMESTAMP:
|
||||
@ -84,6 +82,32 @@ boost::shared_ptr<WindowFunctionType> WF_min_max<T>::makeFunction(int id, const
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_min_max<int64_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_min_max<int128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_min_max<uint64_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_min_max<uint128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
@ -173,7 +197,7 @@ void WF_min_max<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_min_max<int64_t>::makeFunction(int, const string&, int);
|
||||
boost::shared_ptr<WindowFunctionType> WF_min_max<int64_t>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
|
||||
} //namespace
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
T fValue;
|
||||
|
@ -53,7 +53,7 @@ namespace windowfunction
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
@ -64,7 +64,6 @@ boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, cons
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_nth_value<int64_t>(id, name));
|
||||
break;
|
||||
@ -75,7 +74,6 @@ boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, cons
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
case CalpontSystemCatalog::TIMESTAMP:
|
||||
@ -85,6 +83,32 @@ boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, cons
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_nth_value<int64_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_nth_value<int128_t>(id, name));
|
||||
}
|
||||
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::UDOUBLE:
|
||||
{
|
||||
@ -273,7 +297,7 @@ void WF_nth_value<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_nth_value<int64_t>::makeFunction(int, const string&, int);
|
||||
boost::shared_ptr<WindowFunctionType> WF_nth_value<int64_t>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
|
||||
} //namespace
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
T fValue;
|
||||
|
@ -54,7 +54,7 @@ namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_ntile::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_ntile::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_ntile(id, name));
|
||||
return func;
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace windowfunction
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
@ -69,7 +69,6 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_percentile<int64_t>(id, name));
|
||||
break;
|
||||
@ -80,7 +79,6 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
case CalpontSystemCatalog::TIMESTAMP:
|
||||
@ -90,6 +88,32 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_percentile<int128_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_percentile<int128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_percentile<uint128_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_percentile<uint128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
@ -371,7 +395,7 @@ void WF_percentile<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_percentile<int64_t>::makeFunction(int, const string&, int);
|
||||
boost::shared_ptr<WindowFunctionType> WF_percentile<int64_t>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
|
||||
} //namespace
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_ranking::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_ranking::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_ranking(id, name));
|
||||
return func;
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_row_number::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_row_number::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_row_number(id, name));
|
||||
return func;
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace windowfunction
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const string& name, int ct)
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
@ -66,7 +66,6 @@ boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const st
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_stats<int64_t>(id, name));
|
||||
break;
|
||||
@ -77,12 +76,37 @@ boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const st
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
func.reset(new WF_stats<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_stats<int64_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_stats<int128_t>(id, name));
|
||||
}
|
||||
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::UDOUBLE:
|
||||
{
|
||||
@ -177,17 +201,19 @@ void WF_stats<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
int scale = fRow.getScale(colIn);
|
||||
long double factor = pow(10.0, scale);
|
||||
long double ldSum1 = fSum1;
|
||||
long double ldSum2 = fSum2;
|
||||
|
||||
// adjust the scale if necessary
|
||||
if (scale != 0 &&
|
||||
cdt != CalpontSystemCatalog::LONGDOUBLE)
|
||||
{
|
||||
fSum1 /= factor;
|
||||
fSum2 /= factor * factor;
|
||||
ldSum1 /= factor;
|
||||
ldSum2 /= factor * factor;
|
||||
}
|
||||
|
||||
long double stat = fSum1 * fSum1 / fCount;
|
||||
stat = fSum2 - stat;
|
||||
long double stat = ldSum1 * ldSum1 / fCount;
|
||||
stat = ldSum2 - stat;
|
||||
|
||||
if (fFunctionId == WF__STDDEV_POP)
|
||||
stat = sqrt(stat / fCount);
|
||||
@ -220,7 +246,7 @@ void WF_stats<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<int64_t>::makeFunction(int, const string&, int);
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<int64_t>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
|
||||
} //namespace
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
long double fSum1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
/* CopyrighT (C) 2014 InfiniDB, Inc.
|
||||
Copyright (c) 2019 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
@ -50,112 +50,116 @@ using namespace joblist;
|
||||
#include "wf_sum_avg.h"
|
||||
|
||||
|
||||
#if 0
|
||||
namespace
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
void checkSumLimit(T sum, T val)
|
||||
template<typename T_IN, typename T_OUT>
|
||||
void WF_sum_avg<T_IN, T_OUT>::checkSumLimit(long double val, long double sum)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void checkSumLimit<int64_t>(int64_t sum, int64_t val)
|
||||
template<typename T_IN, typename T_OUT>
|
||||
inline void WF_sum_avg<T_IN, T_OUT>::checkSumLimit(int128_t val, int128_t sum)
|
||||
{
|
||||
if (((sum >= 0) && ((numeric_limits<int64_t>::max() - sum) < val)) ||
|
||||
((sum < 0) && ((numeric_limits<int64_t>::min() - sum) > val)))
|
||||
if (((sum >= 0) && ((fMax128 - sum) < val)) ||
|
||||
((sum < 0) && ((fMin128 - sum) > val)))
|
||||
{
|
||||
string errStr = "SUM(int):";
|
||||
string errStr = "SUM(int128_t)";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
}
|
||||
}
|
||||
|
||||
ostringstream oss;
|
||||
oss << sum << "+" << val;
|
||||
template<typename T_IN, typename T_OUT>
|
||||
inline void WF_sum_avg<T_IN, T_OUT>::checkSumLimit(uint128_t val, uint128_t sum)
|
||||
{
|
||||
if ((fMaxu128 - sum) < val)
|
||||
{
|
||||
string errStr = "SUM(uint128_t)";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
}
|
||||
}
|
||||
|
||||
if (sum > 0)
|
||||
oss << " > " << numeric_limits<uint64_t>::max();
|
||||
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 factor = pow(10.0, scale);
|
||||
int128_t avg;
|
||||
if (scale > 0)
|
||||
{
|
||||
if ((sum * factor) / factor == sum)
|
||||
{
|
||||
avg = sum * factor;
|
||||
avg /= count;
|
||||
}
|
||||
else
|
||||
oss << " < " << numeric_limits<uint64_t>::min();
|
||||
|
||||
errStr += oss.str();
|
||||
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void checkSumLimit<uint64_t>(uint64_t sum, uint64_t val)
|
||||
{
|
||||
if ((sum >= 0) && ((numeric_limits<uint64_t>::max() - sum) < val))
|
||||
else
|
||||
{
|
||||
string errStr = "SUM(unsigned):";
|
||||
|
||||
ostringstream oss;
|
||||
oss << sum << "+" << val << " > " << numeric_limits<uint64_t>::max();
|
||||
errStr += oss.str();
|
||||
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
avg = sum / count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
long double calculateAvg(long double sum, uint64_t count, int s)
|
||||
{
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
long double avgWithLimit(long double sum, uint64_t count, int scale, long double u, long double l)
|
||||
{
|
||||
long double factor = pow(10.0, scale);
|
||||
long double avg = sum / count;
|
||||
avg *= factor;
|
||||
|
||||
avg += (avg < 0) ? (-0.5) : (0.5);
|
||||
|
||||
if (avg > u || avg < l)
|
||||
{
|
||||
string errStr = string("AVG") + (l < 0 ? "(int):" : "(unsign)");
|
||||
ostringstream oss;
|
||||
oss << avg;
|
||||
errStr += oss.str();
|
||||
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
}
|
||||
|
||||
return avg;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
int64_t calculateAvg<int64_t>(int64_t sum, uint64_t count, int scale)
|
||||
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)
|
||||
{
|
||||
int64_t t = (int64_t) avgWithLimit(sum, count, scale,
|
||||
numeric_limits<int64_t>::max(), numeric_limits<int64_t>::min());
|
||||
return t;
|
||||
uint128_t factor = pow(10.0, scale);
|
||||
uint128_t avg = sum;
|
||||
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<>
|
||||
uint64_t calculateAvg<uint64_t>(uint64_t sum, uint64_t count, int scale)
|
||||
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)
|
||||
{
|
||||
uint64_t t = (uint64_t) avgWithLimit(sum, count, scale, numeric_limits<uint64_t>::max(), 0);
|
||||
return t;
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_sum_avg<T>::makeFunction(int id, const string& name, int ct)
|
||||
// For the static function makeFunction, the template parameters are ignored
|
||||
template<typename T_IN, typename T_OUT>
|
||||
boost::shared_ptr<WindowFunctionType> WF_sum_avg<T_IN, T_OUT>::makeFunction(int id, const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
@ -165,9 +169,9 @@ boost::shared_ptr<WindowFunctionType> WF_sum_avg<T>::makeFunction(int id, const
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_sum_avg<int64_t>(id, name));
|
||||
// Look into using int128_t instead of long double
|
||||
func.reset(new WF_sum_avg<int64_t, long double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -176,29 +180,54 @@ boost::shared_ptr<WindowFunctionType> WF_sum_avg<T>::makeFunction(int id, const
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
{
|
||||
func.reset(new WF_sum_avg<uint64_t, long double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
if (wc->functionParms()[0]->resultType().colWidth < 16)
|
||||
{
|
||||
func.reset(new WF_sum_avg<int64_t, int128_t>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
func.reset(new WF_sum_avg<int128_t, int128_t>(id, name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
func.reset(new WF_sum_avg<uint64_t>(id, name));
|
||||
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::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_sum_avg<double>(id, name));
|
||||
func.reset(new WF_sum_avg<double, long double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_sum_avg<float>(id, name));
|
||||
func.reset(new WF_sum_avg<float, long double>(id, name));
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
{
|
||||
func.reset(new WF_sum_avg<long double>(id, name));
|
||||
func.reset(new WF_sum_avg<long double, long double>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -216,15 +245,15 @@ boost::shared_ptr<WindowFunctionType> WF_sum_avg<T>::makeFunction(int id, const
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_sum_avg<T>::clone() const
|
||||
template<typename T_IN, typename T_OUT>
|
||||
WindowFunctionType* WF_sum_avg<T_IN, T_OUT>::clone() const
|
||||
{
|
||||
return new WF_sum_avg<T>(*this);
|
||||
return new WF_sum_avg<T_IN, T_OUT>(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_sum_avg<T>::resetData()
|
||||
template<typename T_IN, typename T_OUT>
|
||||
void WF_sum_avg<T_IN, T_OUT>::resetData()
|
||||
{
|
||||
fAvg = 0;
|
||||
fSum = 0;
|
||||
@ -235,8 +264,8 @@ void WF_sum_avg<T>::resetData()
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
template<typename T_IN, typename T_OUT>
|
||||
void WF_sum_avg<T_IN, T_OUT>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
uint64_t colOut = fFieldIndex[0];
|
||||
|
||||
@ -251,8 +280,7 @@ void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
e = c;
|
||||
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
double scale = fRow.getScale(colIn);
|
||||
|
||||
int scale = fRow.getScale(colOut) - fRow.getScale(colIn);
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
@ -263,34 +291,27 @@ void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
continue;
|
||||
|
||||
T valIn;
|
||||
CDT cdt;
|
||||
getValue(colIn, valIn, &cdt);
|
||||
// checkSumLimit(fSum, valIn);
|
||||
getValue(colIn, fVal, &cdt);
|
||||
|
||||
if ((!fDistinct) || (fSet.find(valIn) == fSet.end()))
|
||||
if ((!fDistinct) || (fSet.find(fVal) == fSet.end()))
|
||||
{
|
||||
long double val = valIn;
|
||||
if (scale &&
|
||||
cdt != CalpontSystemCatalog::LONGDOUBLE)
|
||||
{
|
||||
val /= pow(10.0, scale);
|
||||
}
|
||||
fSum += val;
|
||||
checkSumLimit(fVal, fSum);
|
||||
fSum += (T_OUT)fVal;
|
||||
fCount++;
|
||||
|
||||
if (fDistinct)
|
||||
fSet.insert(valIn);
|
||||
fSet.insert(fVal);
|
||||
}
|
||||
}
|
||||
|
||||
if ((fCount > 0) && (fFunctionId == WF__AVG || fFunctionId == WF__AVG_DISTINCT))
|
||||
{
|
||||
fAvg = fSum / fCount;
|
||||
fAvg = calculateAvg(fSum, fCount, scale);
|
||||
}
|
||||
}
|
||||
|
||||
long double* v = NULL;
|
||||
T_OUT* v = NULL;
|
||||
|
||||
if (fCount > 0)
|
||||
{
|
||||
@ -307,7 +328,7 @@ void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_sum_avg<int64_t>::makeFunction(int, const string&, int);
|
||||
boost::shared_ptr<WindowFunctionType> WF_sum_avg<int64_t, long double>::makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
|
||||
} //namespace
|
||||
|
@ -29,8 +29,9 @@
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
// T_IN is the data type of the input values.
|
||||
// T_OUT is the data type we are using for output and internal values
|
||||
template<typename T_IN, typename T_OUT>
|
||||
class WF_sum_avg : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
@ -38,6 +39,9 @@ public:
|
||||
WindowFunctionType(id, name), fDistinct(id != WF__SUM && id != WF__AVG)
|
||||
{
|
||||
resetData();
|
||||
utils::int128Max(fMax128);
|
||||
utils::int128Min(fMin128);
|
||||
utils::uint128Max(fMaxu128);
|
||||
}
|
||||
|
||||
// pure virtual in base
|
||||
@ -45,16 +49,27 @@ public:
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int, WindowFunctionColumn*);
|
||||
|
||||
protected:
|
||||
long double fAvg;
|
||||
long double fSum;
|
||||
T_IN fVal;
|
||||
T_OUT fAvg;
|
||||
T_OUT fSum;
|
||||
uint64_t fCount;
|
||||
bool fDistinct;
|
||||
std::set<T> 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(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);
|
||||
uint128_t calculateAvg(uint128_t sum, uint64_t count, int scale);
|
||||
long double calculateAvg(long double sum, uint64_t count, int scale);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -56,7 +56,7 @@ using namespace joblist;
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_udaf::makeFunction(int id, const string& name, int ct, mcsv1sdk::mcsv1Context& context)
|
||||
boost::shared_ptr<WindowFunctionType> WF_udaf::makeFunction(int id, const string& name, int ct, mcsv1sdk::mcsv1Context& context, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
|
||||
@ -544,11 +544,13 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
|
||||
static const static_any::any& intTypeId = (int)1;
|
||||
static const static_any::any& longTypeId = (long)1;
|
||||
static const static_any::any& llTypeId = (long long)1;
|
||||
static const static_any::any& int128TypeId = (int128_t)1;
|
||||
static const static_any::any& ucharTypeId = (unsigned char)1;
|
||||
static const static_any::any& ushortTypeId = (unsigned short)1;
|
||||
static const static_any::any& uintTypeId = (unsigned int)1;
|
||||
static const static_any::any& ulongTypeId = (unsigned long)1;
|
||||
static const static_any::any& ullTypeId = (unsigned long long)1;
|
||||
static const static_any::any& uint128TypeId = (int128_t)1;
|
||||
static const static_any::any& floatTypeId = (float)1;
|
||||
static const static_any::any& doubleTypeId = (double)1;
|
||||
static const std::string typeStr("");
|
||||
@ -562,6 +564,8 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
|
||||
// it to whatever they said to return.
|
||||
int64_t intOut = 0;
|
||||
uint64_t uintOut = 0;
|
||||
int128_t int128Out = 0;
|
||||
uint128_t uint128Out = 0;
|
||||
float floatOut = 0.0;
|
||||
double doubleOut = 0.0;
|
||||
long double longdoubleOut = 0.0;
|
||||
@ -651,6 +655,24 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
|
||||
intOut = (int64_t)doubleOut;
|
||||
oss << doubleOut;
|
||||
}
|
||||
else if (valOut.compatible(int128TypeId))
|
||||
{
|
||||
int128Out = valOut.cast<int128_t>();
|
||||
uintOut = intOut = int128Out; // may truncate
|
||||
floatOut = int128Out;
|
||||
doubleOut = int128Out;
|
||||
longdoubleOut = int128Out;
|
||||
oss << longdoubleOut;
|
||||
}
|
||||
else if (valOut.compatible(uint128TypeId))
|
||||
{
|
||||
uint128Out = valOut.cast<uint128_t>();
|
||||
uintOut = intOut = uint128Out; // may truncate
|
||||
floatOut = uint128Out;
|
||||
doubleOut = uint128Out;
|
||||
longdoubleOut = uint128Out;
|
||||
oss << longdoubleOut;
|
||||
}
|
||||
|
||||
if (valOut.compatible(strTypeId))
|
||||
{
|
||||
@ -901,33 +923,66 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
int64_t valIn;
|
||||
|
||||
if (cc)
|
||||
if (fRow.getColumnWidth(colIn) < 16)
|
||||
{
|
||||
valIn = cc->getDecimalVal(fRow, isNull).value;
|
||||
int64_t valIn;
|
||||
|
||||
if (cc)
|
||||
{
|
||||
valIn = cc->getDecimalVal(fRow, isNull).value;
|
||||
}
|
||||
else
|
||||
{
|
||||
getValue(colIn, valIn);
|
||||
}
|
||||
|
||||
// Check for distinct, if turned on.
|
||||
// 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<DistinctMap::iterator, bool> distinct;
|
||||
distinct = fDistinctMap.insert(val);
|
||||
if (distinct.second == false)
|
||||
{
|
||||
++(*distinct.first).second;
|
||||
bSkipIt = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
datum.columnData = valIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
getValue(colIn, valIn);
|
||||
}
|
||||
int128_t valIn;
|
||||
|
||||
// Check for distinct, if turned on.
|
||||
// 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<DistinctMap::iterator, bool> distinct;
|
||||
distinct = fDistinctMap.insert(val);
|
||||
if (distinct.second == false)
|
||||
if (cc)
|
||||
{
|
||||
++(*distinct.first).second;
|
||||
bSkipIt = true;
|
||||
continue;
|
||||
valIn = cc->getDecimalVal(fRow, isNull).s128Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
getValue(colIn, valIn);
|
||||
}
|
||||
}
|
||||
|
||||
datum.columnData = valIn;
|
||||
// Check for distinct, if turned on.
|
||||
// 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<DistinctMap::iterator, bool> distinct;
|
||||
distinct = fDistinctMap.insert(val);
|
||||
if (distinct.second == false)
|
||||
{
|
||||
++(*distinct.first).second;
|
||||
bSkipIt = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
datum.columnData = valIn;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1154,7 +1209,7 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
||||
fPrev = c;
|
||||
}
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_udaf::makeFunction(int id, const string& name, int ct, mcsv1sdk::mcsv1Context& context);
|
||||
boost::shared_ptr<WindowFunctionType> WF_udaf::makeFunction(int id, const string& name, int ct, mcsv1sdk::mcsv1Context& context, WindowFunctionColumn*);
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
@ -104,7 +104,7 @@ protected:
|
||||
|
||||
public:
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int id, const string& name,
|
||||
int ct, mcsv1sdk::mcsv1Context& context);
|
||||
int ct, mcsv1sdk::mcsv1Context& context, WindowFunctionColumn* wc);
|
||||
};
|
||||
|
||||
|
||||
|
@ -150,67 +150,67 @@ WindowFunctionType::makeWindowFunction(const string& name, int ct, WindowFunctio
|
||||
int functionId = windowFunctionId[algorithm::to_upper_copy(name)];
|
||||
|
||||
// The template parameters here are dummies to execute the static makeFunction
|
||||
// which sets the real type based on ct.
|
||||
// which sets the real types based on ct.
|
||||
switch (functionId)
|
||||
{
|
||||
case WF__COUNT_ASTERISK:
|
||||
case WF__COUNT:
|
||||
case WF__COUNT_DISTINCT:
|
||||
af = WF_count<int64_t>::makeFunction(functionId, name, ct);
|
||||
af = WF_count<int64_t>::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__MIN:
|
||||
case WF__MAX:
|
||||
af = WF_min_max<int64_t>::makeFunction(functionId, name, ct);
|
||||
af = WF_min_max<int64_t>::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__SUM:
|
||||
case WF__AVG:
|
||||
case WF__SUM_DISTINCT:
|
||||
case WF__AVG_DISTINCT:
|
||||
af = WF_sum_avg<int64_t>::makeFunction(functionId, name, ct);
|
||||
af = WF_sum_avg<int64_t, long double>::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__STDDEV_POP:
|
||||
case WF__STDDEV_SAMP:
|
||||
case WF__VAR_POP:
|
||||
case WF__VAR_SAMP:
|
||||
af = WF_stats<int64_t>::makeFunction(functionId, name, ct);
|
||||
af = WF_stats<int64_t>::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__ROW_NUMBER:
|
||||
af = WF_row_number::makeFunction(functionId, name, ct);
|
||||
af = WF_row_number::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__RANK:
|
||||
case WF__DENSE_RANK:
|
||||
case WF__PERCENT_RANK:
|
||||
case WF__CUME_DIST:
|
||||
af = WF_ranking::makeFunction(functionId, name, ct);
|
||||
af = WF_ranking::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__FIRST_VALUE:
|
||||
case WF__LAST_VALUE:
|
||||
case WF__NTH_VALUE:
|
||||
af = WF_nth_value<int64_t>::makeFunction(functionId, name, ct);
|
||||
af = WF_nth_value<int64_t>::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__LEAD:
|
||||
case WF__LAG:
|
||||
af = WF_lead_lag<int64_t>::makeFunction(functionId, name, ct);
|
||||
af = WF_lead_lag<int64_t>::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__NTILE:
|
||||
af = WF_ntile::makeFunction(functionId, name, ct);
|
||||
af = WF_ntile::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__PERCENTILE_CONT:
|
||||
case WF__PERCENTILE_DISC:
|
||||
af = WF_percentile<int64_t>::makeFunction(functionId, name, ct);
|
||||
af = WF_percentile<int64_t>::makeFunction(functionId, name, ct, wc);
|
||||
break;
|
||||
|
||||
case WF__UDAF:
|
||||
af = WF_udaf::makeFunction(functionId, name, ct, wc->getUDAFContext());
|
||||
af = WF_udaf::makeFunction(functionId, name, ct, wc->getUDAFContext(), wc);
|
||||
break;
|
||||
|
||||
case WF__REGR_SLOPE:
|
||||
@ -229,7 +229,7 @@ WindowFunctionType::makeWindowFunction(const string& name, int ct, WindowFunctio
|
||||
break;
|
||||
}
|
||||
|
||||
// Copy the only the constant parameter pointers
|
||||
// Copy only the constant parameter pointers
|
||||
af->constParms(wc->functionParms());
|
||||
|
||||
return af;
|
||||
@ -308,6 +308,26 @@ template<> void WindowFunctionType::getValue<string>(uint64_t i, string& t, CDT*
|
||||
// By not setting cdt, we let it default to the column's type
|
||||
}
|
||||
|
||||
template<> void WindowFunctionType::getValue<int128_t>(uint64_t i, int128_t& t, CDT* cdt)
|
||||
{
|
||||
t = fRow.getInt128Field(i);
|
||||
|
||||
if (cdt)
|
||||
{
|
||||
*cdt = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
}
|
||||
}
|
||||
|
||||
template<> void WindowFunctionType::getValue<uint128_t>(uint64_t i, uint128_t& t, CDT* cdt)
|
||||
{
|
||||
t = fRow.getUint128Field(i);
|
||||
|
||||
if (cdt)
|
||||
{
|
||||
*cdt = execplan::CalpontSystemCatalog::DECIMAL;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void WindowFunctionType::setValue(uint64_t i, T& t)
|
||||
{
|
||||
}
|
||||
@ -337,6 +357,11 @@ template<> void WindowFunctionType::setValue<long double>(uint64_t i, long doubl
|
||||
fRow.setLongDoubleField(t, i);
|
||||
}
|
||||
|
||||
template<> void WindowFunctionType::setValue<int128_t>(uint64_t i, int128_t& t)
|
||||
{
|
||||
fRow.setInt128Field(t, i);
|
||||
}
|
||||
|
||||
template<> void WindowFunctionType::setValue<string>(uint64_t i, string& t)
|
||||
{
|
||||
fRow.setStringField(t, i);
|
||||
@ -389,7 +414,6 @@ void WindowFunctionType::setValue(int ct, int64_t b, int64_t e, int64_t c, T* v)
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
int64_t iv = *v;
|
||||
setValue(i, iv);
|
||||
@ -401,13 +425,26 @@ void WindowFunctionType::setValue(int ct, int64_t b, int64_t e, int64_t c, T* v)
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
uint64_t uv = *v;
|
||||
setValue(i, uv);
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
int128_t iv = *v;
|
||||
setValue(i, iv);
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
uint128_t uv = *v;
|
||||
setValue(i, uv);
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
@ -452,7 +489,6 @@ void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
t = (T) fRow.getIntField(i);
|
||||
pw = s - fRow.getScale(i); // pw is difference of scales, will be in [-18, 18]
|
||||
@ -470,7 +506,6 @@ void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
t = (T) fRow.getUintField(i);
|
||||
pw = s - fRow.getScale(i); // pw is difference of scales, will be in [-18, 18]
|
||||
@ -483,6 +518,40 @@ void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
uint32_t w = fRow.getColumnWidth(i);
|
||||
if (w < 16)
|
||||
t = (T) fRow.getIntField(i);
|
||||
else
|
||||
t = (T) fRow.getInt128Field(i);
|
||||
pw = s - fRow.getScale(i); // pw is difference of scales, will be in [-18, 18]
|
||||
|
||||
if (pw > 0)
|
||||
t *= IDB_pow[pw];
|
||||
else if (pw < 0)
|
||||
t /= IDB_pow[-pw];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
uint32_t w = fRow.getColumnWidth(i);
|
||||
if (w < 16)
|
||||
t = (T) fRow.getUintField(i);
|
||||
else
|
||||
t = (T) fRow.getUint128Field(i);
|
||||
pw = s - fRow.getScale(i); // pw is difference of scales, will be in [-18, 18]
|
||||
|
||||
if (pw > 0)
|
||||
t *= IDB_pow[pw];
|
||||
else if (pw < 0)
|
||||
t /= IDB_pow[-pw];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
@ -552,6 +621,18 @@ void WindowFunctionType::getConstValue<uint64_t>(ConstantColumn* cc, uint64_t& t
|
||||
t = cc->getUintVal(fRow, b);
|
||||
}
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<int128_t>(ConstantColumn* cc, int128_t& t, bool& b)
|
||||
{
|
||||
t = cc->getDecimalVal(fRow, b).s128Value;
|
||||
}
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<uint128_t>(ConstantColumn* cc, uint128_t& t, bool& b)
|
||||
{
|
||||
t = cc->getDecimalVal(fRow, b).s128Value;
|
||||
}
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<double>(ConstantColumn* cc, double& t, bool& b)
|
||||
{
|
||||
@ -581,12 +662,16 @@ template void WindowFunctionType::implicit2T<uint64_t>(uint64_t, uint64_t&, int)
|
||||
template void WindowFunctionType::implicit2T<float>(uint64_t, float&, int);
|
||||
template void WindowFunctionType::implicit2T<double>(uint64_t, double&, int);
|
||||
template void WindowFunctionType::implicit2T<long double>(uint64_t, long double&, int);
|
||||
template void WindowFunctionType::implicit2T<int128_t>(uint64_t, int128_t&, int);
|
||||
template void WindowFunctionType::implicit2T<uint128_t>(uint64_t, uint128_t&, int);
|
||||
|
||||
template void WindowFunctionType::setValue<int64_t>(int, int64_t, int64_t, int64_t, int64_t*);
|
||||
template void WindowFunctionType::setValue<uint64_t>(int, int64_t, int64_t, int64_t, uint64_t*);
|
||||
template void WindowFunctionType::setValue<float>(int, int64_t, int64_t, int64_t, float*);
|
||||
template void WindowFunctionType::setValue<double>(int, int64_t, int64_t, int64_t, double*);
|
||||
template void WindowFunctionType::setValue<long double>(int, int64_t, int64_t, int64_t, long double*);
|
||||
template void WindowFunctionType::setValue<int128_t>(int, int64_t, int64_t, int64_t, int128_t*);
|
||||
template void WindowFunctionType::setValue<uint128_t>(int, int64_t, int64_t, int64_t, uint128_t*);
|
||||
|
||||
void* WindowFunctionType::getNullValueByType(int ct, int pos)
|
||||
{
|
||||
@ -610,7 +695,8 @@ void* WindowFunctionType::getNullValueByType(int ct, int pos)
|
||||
// static uint64_t char4Null = joblist::CHAR4NULL;
|
||||
// static uint64_t char8Null = joblist::CHAR8NULL;
|
||||
static string stringNull("");
|
||||
|
||||
static int128_t int128Null; // Set at runtime;
|
||||
|
||||
void* v = NULL;
|
||||
|
||||
switch (ct)
|
||||
@ -714,9 +800,18 @@ void* WindowFunctionType::getNullValueByType(int ct, int pos)
|
||||
v = &intNull;
|
||||
break;
|
||||
|
||||
default:
|
||||
case 8:
|
||||
v = &bigIntNull;
|
||||
break;
|
||||
|
||||
case 16:
|
||||
utils::setWideDecimalNullValue(int128Null);
|
||||
v = &int128Null;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -226,6 +226,10 @@ protected:
|
||||
{
|
||||
return fRow.getIntField(i);
|
||||
}
|
||||
int128_t getInt128Value(uint64_t i)
|
||||
{
|
||||
return fRow.getInt128Field(i);
|
||||
}
|
||||
double getDoubleValue(uint64_t i)
|
||||
{
|
||||
return fRow.getDoubleField(i);
|
||||
@ -238,6 +242,10 @@ protected:
|
||||
{
|
||||
fRow.setIntField(v, i);
|
||||
}
|
||||
void setInt128Value(int64_t i, int128_t v)
|
||||
{
|
||||
fRow.setInt128Field(v, i);
|
||||
}
|
||||
void setDoubleValue(int64_t i, double v)
|
||||
{
|
||||
fRow.setDoubleField(v, i);
|
||||
|
Reference in New Issue
Block a user