You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
MCOL-1698 get DISTINCT working for UDAnF
This commit is contained in:
@ -58,7 +58,7 @@ UDAF_MAP& UDAFMap::getMap()
|
|||||||
// the function names passed to the interface is always in lower case.
|
// the function names passed to the interface is always in lower case.
|
||||||
fm["allnull"] = new allnull();
|
fm["allnull"] = new allnull();
|
||||||
fm["ssq"] = new ssq();
|
fm["ssq"] = new ssq();
|
||||||
fm["median"] = new median();
|
// fm["median"] = new median();
|
||||||
fm["avg_mode"] = new avg_mode();
|
fm["avg_mode"] = new avg_mode();
|
||||||
fm["avgx"] = new avgx();
|
fm["avgx"] = new avgx();
|
||||||
|
|
||||||
|
@ -189,6 +189,7 @@ static uint64_t UDAF_WINDOWFRAME_REQUIRED __attribute__ ((unused)) = 1 << 4; //
|
|||||||
static uint64_t UDAF_WINDOWFRAME_ALLOWED __attribute__ ((unused)) = 1 << 5; // If used as UDAnF, a WINDOW FRAME is optional
|
static uint64_t UDAF_WINDOWFRAME_ALLOWED __attribute__ ((unused)) = 1 << 5; // If used as UDAnF, a WINDOW FRAME is optional
|
||||||
static uint64_t UDAF_MAYBE_NULL __attribute__ ((unused)) = 1 << 6; // If UDA(n)F might return NULL.
|
static uint64_t UDAF_MAYBE_NULL __attribute__ ((unused)) = 1 << 6; // If UDA(n)F might return NULL.
|
||||||
static uint64_t UDAF_IGNORE_NULLS __attribute__ ((unused)) = 1 << 7; // If UDA(n)F wants NULL rows suppressed.
|
static uint64_t UDAF_IGNORE_NULLS __attribute__ ((unused)) = 1 << 7; // If UDA(n)F wants NULL rows suppressed.
|
||||||
|
static uint64_t UDAF_DISTINCT __attribute__ ((unused)) = 1 << 8; // Force UDA(n)F to be distinct on first param.
|
||||||
|
|
||||||
// Flags set by the framework to define the context of the call.
|
// Flags set by the framework to define the context of the call.
|
||||||
// User code shouldn't use these directly
|
// User code shouldn't use these directly
|
||||||
|
@ -82,7 +82,7 @@ WindowFunctionType* WF_udaf::clone() const
|
|||||||
void WF_udaf::resetData()
|
void WF_udaf::resetData()
|
||||||
{
|
{
|
||||||
getContext().getFunction()->reset(&getContext());
|
getContext().getFunction()->reset(&getContext());
|
||||||
fDistinctSet.clear();
|
fDistinctMap.clear();
|
||||||
WindowFunctionType::resetData();
|
WindowFunctionType::resetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +179,6 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
|
|||||||
case CalpontSystemCatalog::MEDINT:
|
case CalpontSystemCatalog::MEDINT:
|
||||||
case CalpontSystemCatalog::INT:
|
case CalpontSystemCatalog::INT:
|
||||||
case CalpontSystemCatalog::BIGINT:
|
case CalpontSystemCatalog::BIGINT:
|
||||||
case CalpontSystemCatalog::DATE:
|
|
||||||
case CalpontSystemCatalog::DATETIME:
|
|
||||||
{
|
{
|
||||||
int64_t valIn;
|
int64_t valIn;
|
||||||
|
|
||||||
@ -270,6 +268,9 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
|
|||||||
case CalpontSystemCatalog::UMEDINT:
|
case CalpontSystemCatalog::UMEDINT:
|
||||||
case CalpontSystemCatalog::UINT:
|
case CalpontSystemCatalog::UINT:
|
||||||
case CalpontSystemCatalog::UBIGINT:
|
case CalpontSystemCatalog::UBIGINT:
|
||||||
|
case CalpontSystemCatalog::TIME:
|
||||||
|
case CalpontSystemCatalog::DATE:
|
||||||
|
case CalpontSystemCatalog::DATETIME:
|
||||||
{
|
{
|
||||||
uint64_t valIn;
|
uint64_t valIn;
|
||||||
|
|
||||||
@ -622,8 +623,6 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
|
|||||||
case execplan::CalpontSystemCatalog::BIGINT:
|
case execplan::CalpontSystemCatalog::BIGINT:
|
||||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||||
case execplan::CalpontSystemCatalog::DATE:
|
|
||||||
case execplan::CalpontSystemCatalog::DATETIME:
|
|
||||||
if (valOut.empty())
|
if (valOut.empty())
|
||||||
{
|
{
|
||||||
setValue(colDataType, b, e, c, (int64_t*)NULL);
|
setValue(colDataType, b, e, c, (int64_t*)NULL);
|
||||||
@ -795,8 +794,6 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
case CalpontSystemCatalog::MEDINT:
|
case CalpontSystemCatalog::MEDINT:
|
||||||
case CalpontSystemCatalog::INT:
|
case CalpontSystemCatalog::INT:
|
||||||
case CalpontSystemCatalog::BIGINT:
|
case CalpontSystemCatalog::BIGINT:
|
||||||
case CalpontSystemCatalog::DATE:
|
|
||||||
case CalpontSystemCatalog::DATETIME:
|
|
||||||
{
|
{
|
||||||
int64_t valIn;
|
int64_t valIn;
|
||||||
|
|
||||||
@ -811,29 +808,23 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
|
|
||||||
// Check for distinct, if turned on.
|
// Check for distinct, if turned on.
|
||||||
// Currently, distinct only works on the first parameter.
|
// Currently, distinct only works on the first parameter.
|
||||||
if (k == 0)
|
if (k == 0 && fDistinct)
|
||||||
{
|
{
|
||||||
if ((fDistinct) || (fDistinctSet.find(valIn) != fDistinctSet.end()))
|
// MCOL-1698
|
||||||
|
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
||||||
|
// Unordered_map will not insert a duplicate key (valIn).
|
||||||
|
// If it doesn't insert, the original pair will be returned
|
||||||
|
// in distinct.first and distinct.second will be a bool --
|
||||||
|
// true if newly inserted, false if a duplicate.
|
||||||
|
std::pair<typename DistinctMap::iterator, bool> distinct;
|
||||||
|
distinct = fDistinctMap.insert(val);
|
||||||
|
if (distinct.second == false)
|
||||||
{
|
{
|
||||||
// MCOL-1698
|
// This is a duplicate: increment the count
|
||||||
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
++(*distinct.first).second;
|
||||||
// Unordered_map will not insert a duplicate key (valIn).
|
bSkipIt = true;
|
||||||
// If it doesn't insert, the original pair will be returned
|
continue;
|
||||||
// in distinct.first and distinct.second will be a bool --
|
|
||||||
// true if newly inserted, false if a duplicate.
|
|
||||||
std::pair<typename DistinctMap::iterator, bool> distinct;
|
|
||||||
distinct = fDistinctMap.insert(val);
|
|
||||||
if (distinct.second == false)
|
|
||||||
{
|
|
||||||
// This is a duplicate: increment the count
|
|
||||||
++(*distinct.first).second;
|
|
||||||
bSkipIt = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDistinct)
|
|
||||||
fDistinctSet.insert(valIn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.columnData = valIn;
|
datum.columnData = valIn;
|
||||||
@ -856,23 +847,17 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
|
|
||||||
// Check for distinct, if turned on.
|
// Check for distinct, if turned on.
|
||||||
// Currently, distinct only works on the first parameter.
|
// Currently, distinct only works on the first parameter.
|
||||||
if (k == 0)
|
if (k == 0 && fDistinct)
|
||||||
{
|
{
|
||||||
if ((fDistinct) || (fDistinctSet.find(valIn) != fDistinctSet.end()))
|
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
||||||
|
std::pair<typename DistinctMap::iterator, bool> distinct;
|
||||||
|
distinct = fDistinctMap.insert(val);
|
||||||
|
if (distinct.second == false)
|
||||||
{
|
{
|
||||||
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
++(*distinct.first).second;
|
||||||
std::pair<typename DistinctMap::iterator, bool> distinct;
|
bSkipIt = true;
|
||||||
distinct = fDistinctMap.insert(val);
|
continue;
|
||||||
if (distinct.second == false)
|
|
||||||
{
|
|
||||||
++(*distinct.first).second;
|
|
||||||
bSkipIt = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDistinct)
|
|
||||||
fDistinctSet.insert(valIn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.columnData = valIn;
|
datum.columnData = valIn;
|
||||||
@ -884,6 +869,9 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
case CalpontSystemCatalog::UMEDINT:
|
case CalpontSystemCatalog::UMEDINT:
|
||||||
case CalpontSystemCatalog::UINT:
|
case CalpontSystemCatalog::UINT:
|
||||||
case CalpontSystemCatalog::UBIGINT:
|
case CalpontSystemCatalog::UBIGINT:
|
||||||
|
case CalpontSystemCatalog::TIME:
|
||||||
|
case CalpontSystemCatalog::DATE:
|
||||||
|
case CalpontSystemCatalog::DATETIME:
|
||||||
{
|
{
|
||||||
uint64_t valIn;
|
uint64_t valIn;
|
||||||
|
|
||||||
@ -898,23 +886,17 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
|
|
||||||
// Check for distinct, if turned on.
|
// Check for distinct, if turned on.
|
||||||
// Currently, distinct only works on the first parameter.
|
// Currently, distinct only works on the first parameter.
|
||||||
if (k == 0)
|
if (k == 0 && fDistinct)
|
||||||
{
|
{
|
||||||
if ((fDistinct) || (fDistinctSet.find(valIn) != fDistinctSet.end()))
|
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
||||||
|
std::pair<typename DistinctMap::iterator, bool> distinct;
|
||||||
|
distinct = fDistinctMap.insert(val);
|
||||||
|
if (distinct.second == false)
|
||||||
{
|
{
|
||||||
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
++(*distinct.first).second;
|
||||||
std::pair<typename DistinctMap::iterator, bool> distinct;
|
bSkipIt = true;
|
||||||
distinct = fDistinctMap.insert(val);
|
continue;
|
||||||
if (distinct.second == false)
|
|
||||||
{
|
|
||||||
++(*distinct.first).second;
|
|
||||||
bSkipIt = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDistinct)
|
|
||||||
fDistinctSet.insert(valIn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.columnData = valIn;
|
datum.columnData = valIn;
|
||||||
@ -937,23 +919,17 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
|
|
||||||
// Check for distinct, if turned on.
|
// Check for distinct, if turned on.
|
||||||
// Currently, distinct only works on the first parameter.
|
// Currently, distinct only works on the first parameter.
|
||||||
if (k == 0)
|
if (k == 0 && fDistinct)
|
||||||
{
|
{
|
||||||
if ((fDistinct) || (fDistinctSet.find(valIn) != fDistinctSet.end()))
|
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
||||||
|
std::pair<typename DistinctMap::iterator, bool> distinct;
|
||||||
|
distinct = fDistinctMap.insert(val);
|
||||||
|
if (distinct.second == false)
|
||||||
{
|
{
|
||||||
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
++(*distinct.first).second;
|
||||||
std::pair<typename DistinctMap::iterator, bool> distinct;
|
bSkipIt = true;
|
||||||
distinct = fDistinctMap.insert(val);
|
continue;
|
||||||
if (distinct.second == false)
|
|
||||||
{
|
|
||||||
++(*distinct.first).second;
|
|
||||||
bSkipIt = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDistinct)
|
|
||||||
fDistinctSet.insert(valIn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.columnData = valIn;
|
datum.columnData = valIn;
|
||||||
@ -976,23 +952,17 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
|
|
||||||
// Check for distinct, if turned on.
|
// Check for distinct, if turned on.
|
||||||
// Currently, distinct only works on the first parameter.
|
// Currently, distinct only works on the first parameter.
|
||||||
if (k == 0)
|
if (k == 0 && fDistinct)
|
||||||
{
|
{
|
||||||
if ((fDistinct) || (fDistinctSet.find(valIn) != fDistinctSet.end()))
|
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
||||||
|
std::pair<typename DistinctMap::iterator, bool> distinct;
|
||||||
|
distinct = fDistinctMap.insert(val);
|
||||||
|
if (distinct.second == false)
|
||||||
{
|
{
|
||||||
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
++(*distinct.first).second;
|
||||||
std::pair<typename DistinctMap::iterator, bool> distinct;
|
bSkipIt = true;
|
||||||
distinct = fDistinctMap.insert(val);
|
continue;
|
||||||
if (distinct.second == false)
|
|
||||||
{
|
|
||||||
++(*distinct.first).second;
|
|
||||||
bSkipIt = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDistinct)
|
|
||||||
fDistinctSet.insert(valIn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.columnData = valIn;
|
datum.columnData = valIn;
|
||||||
@ -1018,23 +988,17 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
|||||||
|
|
||||||
// Check for distinct, if turned on.
|
// Check for distinct, if turned on.
|
||||||
// Currently, distinct only works on the first parameter.
|
// Currently, distinct only works on the first parameter.
|
||||||
if (k == 0)
|
if (k == 0 && fDistinct)
|
||||||
{
|
{
|
||||||
if ((fDistinct) || (fDistinctSet.find(valIn) != fDistinctSet.end()))
|
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
||||||
|
std::pair<typename DistinctMap::iterator, bool> distinct;
|
||||||
|
distinct = fDistinctMap.insert(val);
|
||||||
|
if (distinct.second == false)
|
||||||
{
|
{
|
||||||
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
|
++(*distinct.first).second;
|
||||||
std::pair<typename DistinctMap::iterator, bool> distinct;
|
bSkipIt = true;
|
||||||
distinct = fDistinctMap.insert(val);
|
continue;
|
||||||
if (distinct.second == false)
|
|
||||||
{
|
|
||||||
++(*distinct.first).second;
|
|
||||||
bSkipIt = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDistinct)
|
|
||||||
fDistinctSet.insert(valIn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.columnData = valIn;
|
datum.columnData = valIn;
|
||||||
|
@ -22,9 +22,9 @@
|
|||||||
#define UTILS_WF_UDAF_H
|
#define UTILS_WF_UDAF_H
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <tr1/unordered_set>
|
#include <tr1/unordered_map>
|
||||||
#else
|
#else
|
||||||
#include <unordered_set>
|
#include <unordered_map>
|
||||||
#endif
|
#endif
|
||||||
#include "windowfunctiontype.h"
|
#include "windowfunctiontype.h"
|
||||||
#include "mcsv1_udaf.h"
|
#include "mcsv1_udaf.h"
|
||||||
@ -83,6 +83,11 @@ public:
|
|||||||
return fDistinct;
|
return fDistinct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDistinct(bool d = true)
|
||||||
|
{
|
||||||
|
fDistinct = d;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetUDAFValue(static_any::any& valOut, int64_t colOut, int64_t b, int64_t e, int64_t c);
|
void SetUDAFValue(static_any::any& valOut, int64_t colOut, int64_t b, int64_t e, int64_t c);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user