1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

1. Implement bit_count() distributed function.

2. Handle hexadecimal string literals in buildReturnedColumn().
This commit is contained in:
Gagan Goel
2019-11-21 15:32:29 +00:00
parent 6b916675d5
commit 2e16fe674c
4 changed files with 71 additions and 0 deletions

View File

@ -3173,6 +3173,15 @@ ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupp
}
case STRING_RESULT:
{
// Special handling for 0xHHHH literals
const Type_handler *tph = item->type_handler();
if (typeid(*tph) == typeid(Type_handler_hex_hybrid))
{
Item_hex_hybrid *hip = reinterpret_cast<Item_hex_hybrid*>(const_cast<Item*>(item));
rc = new ConstantColumn((int64_t)hip->val_int(), ConstantColumn::NUM);
break;
}
String val, *str = item->val_str(&val);
string valStr;
valStr.assign(str->ptr(), str->length());

View File

@ -359,5 +359,49 @@ int64_t Func_bitxor::getIntVal(Row& row,
}
//
// BIT COUNT
//
CalpontSystemCatalog::ColType Func_bit_count::operationType( FunctionParm& fp, CalpontSystemCatalog::ColType& resultType )
{
return resultType;
}
int64_t Func_bit_count::getIntVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& operationColType)
{
if ( parm.size() != 1 )
{
isNull = true;
return 0;
}
uint64_t val = 0;
if (!getUIntValFromParm(row, parm[0], val, isNull, fTimeZone))
{
std::ostringstream oss;
oss << "bit_count: datatype of " << execplan::colDataTypeToString(operationColType.colDataType);
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
}
// Refer to Hacker's Delight Chapter 5
// for the bit counting algo used here
val = val - ((val >> 1) & 0x5555555555555555);
val = (val & 0x3333333333333333) + ((val >> 2) & 0x3333333333333333);
val = (val + (val >> 4)) & 0x0F0F0F0F0F0F0F0F;
val = val + (val >> 8);
val = val + (val >> 16);
val = val + (val >> 32);
return (int64_t)(val & 0x000000000000007F);
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@ -86,6 +86,7 @@ FuncExp::FuncExp()
fFuncMap["atan"] = new Func_atan();
fFuncMap["atan2"] = new Func_atan();
fFuncMap["between"] = new Func_between();
fFuncMap["bit_count"] = new Func_bit_count();
fFuncMap["case_searched"] = new Func_searched_case();
fFuncMap["case_simple"] = new Func_simple_case();
fFuncMap["cast_as_signed"] = new Func_cast_signed(); //dlh

View File

@ -365,6 +365,23 @@ public:
};
/** @brief Func_bit_count class
*/
class Func_bit_count : public Func_Int
{
public:
Func_bit_count() : Func_Int("bit_count") {}
virtual ~Func_bit_count() {}
execplan::CalpontSystemCatalog::ColType operationType(FunctionParm& fp, execplan::CalpontSystemCatalog::ColType& resultType);
int64_t getIntVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
};
/** @brief Func_hour class
*/
class Func_hour : public Func_Int