1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -41,151 +41,155 @@
#include "dataconvert.h"
#include "utils_utf8.h"
namespace messageqcpp {
namespace messageqcpp
{
class ByteStream;
}
namespace execplan {
namespace execplan
{
class PredicateOperator : public Operator {
class PredicateOperator : public Operator
{
public:
PredicateOperator();
PredicateOperator(const std::string& operatorName);
PredicateOperator(const PredicateOperator& rhs);
virtual ~PredicateOperator();
PredicateOperator();
PredicateOperator(const std::string& operatorName);
PredicateOperator(const PredicateOperator& rhs);
virtual ~PredicateOperator();
/** return a copy of this pointer
*
* deep copy of this pointer and return the copy
*/
inline virtual PredicateOperator* clone() const
{
return new PredicateOperator (*this);
}
/**
* The serialization interface
*/
virtual void serialize(messageqcpp::ByteStream&) const;
virtual void unserialize(messageqcpp::ByteStream&);
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return true iff every member of t is a duplicate copy of every member of this; false otherwise
*/
virtual bool operator==(const TreeNode* t) const;
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return true iff every member of t is a duplicate copy of every member of this; false otherwise
*/
bool operator==(const PredicateOperator& t) const;
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return false iff every member of t is a duplicate copy of every member of this; true otherwise
*/
virtual bool operator!=(const TreeNode* t) const;
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return false iff every member of t is a duplicate copy of every member of this; true otherwise
*/
bool operator!=(const PredicateOperator& t) const;
/***********************************************************
* F&E framework *
***********************************************************/
inline virtual bool getBoolVal(rowgroup::Row& row, bool& isNull, ReturnedColumn* lop, ReturnedColumn* rop);
void setOpType(Type& l, Type& r);
/** return a copy of this pointer
*
* deep copy of this pointer and return the copy
*/
inline virtual PredicateOperator* clone() const
{
return new PredicateOperator (*this);
}
/**
* The serialization interface
*/
virtual void serialize(messageqcpp::ByteStream&) const;
virtual void unserialize(messageqcpp::ByteStream&);
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return true iff every member of t is a duplicate copy of every member of this; false otherwise
*/
virtual bool operator==(const TreeNode* t) const;
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return true iff every member of t is a duplicate copy of every member of this; false otherwise
*/
bool operator==(const PredicateOperator& t) const;
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return false iff every member of t is a duplicate copy of every member of this; true otherwise
*/
virtual bool operator!=(const TreeNode* t) const;
/** @brief Do a deep, strict (as opposed to semantic) equivalence test
*
* Do a deep, strict (as opposed to semantic) equivalence test.
* @return false iff every member of t is a duplicate copy of every member of this; true otherwise
*/
bool operator!=(const PredicateOperator& t) const;
/***********************************************************
* F&E framework *
***********************************************************/
inline virtual bool getBoolVal(rowgroup::Row& row, bool& isNull, ReturnedColumn* lop, ReturnedColumn* rop);
void setOpType(Type& l, Type& r);
private:
template <typename result_t>
inline bool numericCompare(result_t op1, result_t op2);
inline bool strCompare(const std::string& op1, const std::string& op2);
template <typename result_t>
inline bool numericCompare(result_t op1, result_t op2);
inline bool strCompare(const std::string& op1, const std::string& op2);
};
inline bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, ReturnedColumn* lop, ReturnedColumn* rop)
{
// like operator. both sides are string.
if (fOp == OP_LIKE || fOp == OP_NOTLIKE)
{
SP_CNX_Regex regex = rop->regex();
// like operator. both sides are string.
if (fOp == OP_LIKE || fOp == OP_NOTLIKE)
{
SP_CNX_Regex regex = rop->regex();
// Ugh. The strings returned by getStrVal have null padding out to the col width. boost::regex
// considers these nulls significant, but they're not in the pattern, so we need to strip
// them off...
const std::string& v = lop->getStrVal(row, isNull);
char* c = (char*)alloca(v.length() + 1);
memcpy(c, v.c_str(), v.length());
c[v.length()] = 0;
std::string vv(c);
// Ugh. The strings returned by getStrVal have null padding out to the col width. boost::regex
// considers these nulls significant, but they're not in the pattern, so we need to strip
// them off...
const std::string& v = lop->getStrVal(row, isNull);
char* c = (char*)alloca(v.length() + 1);
memcpy(c, v.c_str(), v.length());
c[v.length()] = 0;
std::string vv(c);
if (regex)
{
if (regex)
{
#ifdef _MSC_VER
bool ret = boost::regex_match(vv, *regex);
bool ret = boost::regex_match(vv, *regex);
#else
bool ret = regexec(regex.get(), vv.c_str(), 0, NULL, 0) == 0;
bool ret = regexec(regex.get(), vv.c_str(), 0, NULL, 0) == 0;
#endif
return (((fOp == OP_LIKE) ? ret : !ret) && !isNull);
}
else
{
return (((fOp == OP_LIKE) ? ret : !ret) && !isNull);
}
else
{
#ifdef _MSC_VER
boost::regex regex(dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull)));
bool ret = boost::regex_match(vv, regex);
boost::regex regex(dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull)));
bool ret = boost::regex_match(vv, regex);
#else
regex_t regex;
std::string str=dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull));
regcomp(&regex, str.c_str(), REG_NOSUB | REG_EXTENDED);
bool ret = regexec(&regex, vv.c_str(), 0, NULL, 0) == 0;
regfree(&regex);
regex_t regex;
std::string str = dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull));
regcomp(&regex, str.c_str(), REG_NOSUB | REG_EXTENDED);
bool ret = regexec(&regex, vv.c_str(), 0, NULL, 0) == 0;
regfree(&regex);
#endif
return (((fOp == OP_LIKE) ? ret : !ret) && !isNull);
}
}
// fOpType should have already been set on the connector during parsing
switch (fOperationType.colDataType)
{
case execplan::CalpontSystemCatalog::BIGINT:
case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::TINYINT:
case execplan::CalpontSystemCatalog::SMALLINT:
{
if (fOp == OP_ISNULL)
{
lop->getIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
return (((fOp == OP_LIKE) ? ret : !ret) && !isNull);
}
}
int64_t val1 = lop->getIntVal(row, isNull);
if (isNull)
return false;
// fOpType should have already been set on the connector during parsing
switch (fOperationType.colDataType)
{
case execplan::CalpontSystemCatalog::BIGINT:
case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::TINYINT:
case execplan::CalpontSystemCatalog::SMALLINT:
{
if (fOp == OP_ISNULL)
{
lop->getIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
return numericCompare(val1, rop->getIntVal(row, isNull)) && !isNull;
}
if (fOp == OP_ISNOTNULL)
{
lop->getIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::UBIGINT:
case execplan::CalpontSystemCatalog::UINT:
@ -213,6 +217,7 @@ inline bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, Retu
return false;
uint64_t val1 = lop->getUintVal(row, isNull);
if (isNull)
return false;
@ -221,221 +226,238 @@ inline bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, Retu
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT:
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::UDOUBLE:
{
if (fOp == OP_ISNULL)
{
lop->getDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
{
if (fOp == OP_ISNULL)
{
lop->getDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
double val1 = lop->getDoubleVal(row, isNull);
if (isNull)
return false;
if (fOp == OP_ISNOTNULL)
{
lop->getDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
return numericCompare(val1, rop->getDoubleVal(row, isNull)) && !isNull;
}
if (isNull)
return false;
case execplan::CalpontSystemCatalog::DECIMAL:
double val1 = lop->getDoubleVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getDoubleVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{
if (fOp == OP_ISNULL)
{
lop->getDecimalVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDecimalVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
{
if (fOp == OP_ISNULL)
{
lop->getDecimalVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
IDB_Decimal val1 = lop->getDecimalVal(row, isNull);
if (isNull)
return false;
if (fOp == OP_ISNOTNULL)
{
lop->getDecimalVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
return numericCompare(val1, rop->getDecimalVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::DATE:
{
if (fOp == OP_ISNULL)
{
lop->getDateIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDateIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
if (isNull)
return false;
int64_t val1 = lop->getDateIntVal(row, isNull);
if (isNull)
return false;
IDB_Decimal val1 = lop->getDecimalVal(row, isNull);
return numericCompare(val1, (int64_t)rop->getDateIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::DATETIME:
{
if (fOp == OP_ISNULL)
{
lop->getDatetimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDatetimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
if (isNull)
return false;
int64_t val1 = lop->getDatetimeIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getDecimalVal(row, isNull)) && !isNull;
}
return numericCompare(val1, rop->getDatetimeIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::DATE:
{
if (fOp == OP_ISNULL)
{
lop->getDateIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
if (fOp == OP_ISNOTNULL)
{
lop->getDateIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getDateIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, (int64_t)rop->getDateIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::DATETIME:
{
if (fOp == OP_ISNULL)
{
lop->getDatetimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDatetimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getDatetimeIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getDatetimeIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::TEXT:
{
if (fOp == OP_ISNULL)
{
lop->getStrVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getStrVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
{
if (fOp == OP_ISNULL)
{
lop->getStrVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
const std::string& val1 = lop->getStrVal(row, isNull);
if (isNull)
return false;
if (fOp == OP_ISNOTNULL)
{
lop->getStrVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
return strCompare(val1, rop->getStrVal(row, isNull)) && !isNull;
}
if (isNull)
return false;
//FIXME: ???
case execplan::CalpontSystemCatalog::VARBINARY:
const std::string& val1 = lop->getStrVal(row, isNull);
if (isNull)
return false;
return strCompare(val1, rop->getStrVal(row, isNull)) && !isNull;
}
//FIXME: ???
case execplan::CalpontSystemCatalog::VARBINARY:
case execplan::CalpontSystemCatalog::BLOB:
return false;
break;
return false;
break;
default:
{
std::ostringstream oss;
oss << "invalid predicate operation type: " << fOperationType.colDataType;
throw logging::InvalidOperationExcept(oss.str());
}
}
default:
{
std::ostringstream oss;
oss << "invalid predicate operation type: " << fOperationType.colDataType;
throw logging::InvalidOperationExcept(oss.str());
}
}
return false;
return false;
}
template <typename result_t>
inline bool PredicateOperator::numericCompare(result_t op1, result_t op2)
{
switch (fOp)
{
case OP_EQ:
return op1 == op2;
case OP_NE:
return op1 != op2;
case OP_GT:
return op1 > op2;
case OP_GE:
return op1 >= op2;
case OP_LT:
return op1 < op2;
case OP_LE:
return op1 <= op2;
default:
{
std::ostringstream oss;
oss << "invalid predicate operation: " << fOp;
throw logging::InvalidOperationExcept(oss.str());
}
}
switch (fOp)
{
case OP_EQ:
return op1 == op2;
case OP_NE:
return op1 != op2;
case OP_GT:
return op1 > op2;
case OP_GE:
return op1 >= op2;
case OP_LT:
return op1 < op2;
case OP_LE:
return op1 <= op2;
default:
{
std::ostringstream oss;
oss << "invalid predicate operation: " << fOp;
throw logging::InvalidOperationExcept(oss.str());
}
}
}
inline bool PredicateOperator::strCompare(const std::string& op1, const std::string& op2)
{
switch (fOp)
{
case OP_EQ:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) == 0;
case OP_NE:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) != 0;
case OP_GT:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) > 0;
case OP_GE:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) >= 0;
case OP_LT:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) < 0;
case OP_LE:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) <= 0;
default:
{
std::ostringstream oss;
oss << "Non support predicate operation: " << fOp;
throw logging::InvalidOperationExcept(oss.str());
}
}
switch (fOp)
{
case OP_EQ:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) == 0;
case OP_NE:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) != 0;
case OP_GT:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) > 0;
case OP_GE:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) >= 0;
case OP_LT:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) < 0;
case OP_LE:
return funcexp::utf8::idb_strcoll(op1.c_str(), op2.c_str()) <= 0;
default:
{
std::ostringstream oss;
oss << "Non support predicate operation: " << fOp;
throw logging::InvalidOperationExcept(oss.str());
}
}
}
std::ostream& operator<<(std::ostream& os, const PredicateOperator& rhs);
}
}
#endif //PREDICATEOPERATOR_H