diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 07fdb25f5..4dd14cd4d 100755 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -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(const_cast(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()); diff --git a/utils/funcexp/func_bitwise.cpp b/utils/funcexp/func_bitwise.cpp index 8b065e15f..028aedc1c 100644 --- a/utils/funcexp/func_bitwise.cpp +++ b/utils/funcexp/func_bitwise.cpp @@ -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: diff --git a/utils/funcexp/funcexp.cpp b/utils/funcexp/funcexp.cpp index be50ca2cf..1c01458d7 100644 --- a/utils/funcexp/funcexp.cpp +++ b/utils/funcexp/funcexp.cpp @@ -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 diff --git a/utils/funcexp/functor_int.h b/utils/funcexp/functor_int.h index 78655a892..3e2f465cb 100644 --- a/utils/funcexp/functor_int.h +++ b/utils/funcexp/functor_int.h @@ -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