diff --git a/dbcon/execplan/predicateoperator.h b/dbcon/execplan/predicateoperator.h index 66120eb9c..f28b289f1 100644 --- a/dbcon/execplan/predicateoperator.h +++ b/dbcon/execplan/predicateoperator.h @@ -128,405 +128,6 @@ private: const CHARSET_INFO* cs; }; -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(); - - // 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) - { -#ifdef POSIX_REGEX - bool ret = regexec(regex.get(), v.c_str(), 0, NULL, 0) == 0; -#else - bool ret = boost::regex_match(v.c_str(), *regex); -#endif - return (((fOp == OP_LIKE) ? ret : !ret) && !isNull); - } - else - { -#ifdef POSIX_REGEX - regex_t regex; - std::string str = dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull)); - regcomp(®ex, str.c_str(), REG_NOSUB | REG_EXTENDED); - bool ret = regexec(®ex, v.c_str(), 0, NULL, 0) == 0; - regfree(®ex); -#else - boost::regex regex(dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull))); - bool ret = boost::regex_match(v.c_str(), 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; - - 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: - case execplan::CalpontSystemCatalog::UMEDINT: - case execplan::CalpontSystemCatalog::UTINYINT: - case execplan::CalpontSystemCatalog::USMALLINT: - { - if (fOp == OP_ISNULL) - { - lop->getUintVal(row, isNull); - bool ret = isNull; - isNull = false; - return ret; - } - - if (fOp == OP_ISNOTNULL) - { - lop->getUintVal(row, isNull); - bool ret = isNull; - isNull = false; - return !ret; - } - - if (isNull) - return false; - - uint64_t val1 = lop->getUintVal(row, isNull); - - if (isNull) - return false; - - return numericCompare(val1, rop->getUintVal(row, isNull)) && !isNull; - } - - case execplan::CalpontSystemCatalog::FLOAT: - case execplan::CalpontSystemCatalog::UFLOAT: - 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; - - double val1 = lop->getDoubleVal(row, isNull); - - if (isNull) - return false; - - return numericCompare(val1, rop->getDoubleVal(row, isNull)) && !isNull; - } - - case execplan::CalpontSystemCatalog::LONGDOUBLE: - { - if (fOp == OP_ISNULL) - { - lop->getLongDoubleVal(row, isNull); - bool ret = isNull; - isNull = false; - return ret; - } - - if (fOp == OP_ISNOTNULL) - { - lop->getLongDoubleVal(row, isNull); - bool ret = isNull; - isNull = false; - return !ret; - } - - if (isNull) - return false; - - long double val1 = lop->getLongDoubleVal(row, isNull); - if (isNull) - return false; - - long double val2 = rop->getLongDoubleVal(row, isNull); - if (isNull) - return false; - - // In many case, rounding error will prevent an eq compare to work - // In these cases, use the largest scale of the two items. - if (fOp == execplan::OP_EQ) - { - // In case a val is a representation of a very large integer, - // we won't want to just multiply by scale, as it may move - // significant digits out of scope. So we break them apart - // and compare each separately - int64_t scale = std::max(lop->resultType().scale, rop->resultType().scale); - if (scale) - { - long double intpart1; - long double fract1 = modfl(val1, &intpart1); - long double intpart2; - long double fract2 = modfl(val2, &intpart2); - if (numericCompare(intpart1, intpart2)) - { - double factor = pow(10.0, (double)scale); - fract1 = roundl(fract1 * factor); - fract2 = roundl(fract2 * factor); - return numericCompare(fract1, fract2); - } - else - { - return false; - } - } - } - return numericCompare(val1, val2); - } - - 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; - - IDB_Decimal val1 = lop->getDecimalVal(row, isNull); - - if (isNull) - return false; - - 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; - - 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::TIMESTAMP: - { - if (fOp == OP_ISNULL) - { - lop->getTimestampIntVal(row, isNull); - bool ret = isNull; - isNull = false; - return ret; - } - - if (fOp == OP_ISNOTNULL) - { - lop->getTimestampIntVal(row, isNull); - bool ret = isNull; - isNull = false; - return !ret; - } - - if (isNull) - return false; - - int64_t val1 = lop->getTimestampIntVal(row, isNull); - - if (isNull) - return false; - - return numericCompare(val1, rop->getTimestampIntVal(row, isNull)) && !isNull; - } - - case execplan::CalpontSystemCatalog::TIME: - { - if (fOp == OP_ISNULL) - { - lop->getTimeIntVal(row, isNull); - bool ret = isNull; - isNull = false; - return ret; - } - - if (fOp == OP_ISNOTNULL) - { - lop->getTimeIntVal(row, isNull); - bool ret = isNull; - isNull = false; - return !ret; - } - - if (isNull) - return false; - - int64_t val1 = lop->getTimeIntVal(row, isNull); - - if (isNull) - return false; - - return numericCompare(val1, rop->getTimeIntVal(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; - - const std::string& val1 = lop->getStrVal(row, isNull); - if (isNull) - return false; - - return strTrimCompare(val1, rop->getStrVal(row, isNull)) && !isNull; -// return strCompare(val1, rop->getStrVal(row, isNull)) && !isNull; - - } - - // MCOL-641 WIP This is an incorrect assumption. - case execplan::CalpontSystemCatalog::VARBINARY: - case execplan::CalpontSystemCatalog::BLOB: - return false; - break; - - default: - { - std::ostringstream oss; - oss << "invalid predicate operation type: " << fOperationType.colDataType; - throw logging::InvalidOperationExcept(oss.str()); - } - } - - return false; -} - inline bool PredicateOperator::numericCompare(IDB_Decimal& op1, IDB_Decimal& op2) { switch (fOp) diff --git a/utils/funcexp/func_char.cpp b/utils/funcexp/func_char.cpp index d9904ba63..d3bec2ae9 100644 --- a/utils/funcexp/func_char.cpp +++ b/utils/funcexp/func_char.cpp @@ -155,12 +155,12 @@ string Func_char::getStrVal(Row& row, if (tmpval > static_cast(INT64_MAX)) tmpval = INT64_MAX; - - if ( !getChar((int64_t)tmpval, buf) ) + // WIP MCOL-641 + /*if ( !getChar((int64_t)tmpval, buf) ) { isNull = true; return ""; - } + }*/ } else { @@ -172,11 +172,12 @@ string Func_char::getStrVal(Row& row, if ( lefto > 4 ) value++; - if ( !getChar((int64_t)value, buf) ) + // WIP MCOL-641 + /*if ( !getChar((int64_t)value, buf) ) { isNull = true; return ""; - } + }*/ } } break; diff --git a/utils/rowgroup/rowaggregation.cpp b/utils/rowgroup/rowaggregation.cpp index dd3c79caf..f39dea607 100755 --- a/utils/rowgroup/rowaggregation.cpp +++ b/utils/rowgroup/rowaggregation.cpp @@ -57,7 +57,6 @@ //..comment out NDEBUG to enable assertions, uncomment NDEBUG to disable //#define NDEBUG -#include "funcexp/utils_utf8.h" #include "mcs_decimal.h" using namespace std; diff --git a/utils/rowgroup/rowgroup.cpp b/utils/rowgroup/rowgroup.cpp index e8dc38f50..7a8ec8a28 100644 --- a/utils/rowgroup/rowgroup.cpp +++ b/utils/rowgroup/rowgroup.cpp @@ -1175,10 +1175,11 @@ bool Row::equals(const Row& r2, const std::vector& keyCols) const for (uint32_t i = 0; i < keyCols.size(); i++) { const uint32_t& col = keyCols[i]; + cscDataType columnType = getColType(col); - if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::VARCHAR || - (getColType(col) == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) || - getColType(col) == execplan::CalpontSystemCatalog::TEXT)) + if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::VARCHAR || + (columnType == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) || + columnType == execplan::CalpontSystemCatalog::TEXT)) { CHARSET_INFO* cs = getCharset(col); if (cs->strnncollsp(getStringPointer(col), getStringLength(col), @@ -1187,7 +1188,7 @@ bool Row::equals(const Row& r2, const std::vector& keyCols) const return false; } } - else if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::BLOB)) + else if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::BLOB)) { if (getStringLength(col) != r2.getStringLength(col)) return false; @@ -1197,19 +1198,25 @@ bool Row::equals(const Row& r2, const std::vector& keyCols) const } else { - if (getColType(col) == execplan::CalpontSystemCatalog::LONGDOUBLE) + if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::LONGDOUBLE)) { if (getLongDoubleField(col) != r2.getLongDoubleField(col)) return false; } + else if (UNLIKELY(execplan::isDecimal(columnType))) + { + if (getBinaryField(col) != r2.getBinaryField(col)) + return false; + } else if (getUintField(col) != r2.getUintField(col)) + { return false; + } } } return true; } - bool Row::equals(const Row& r2, uint32_t lastCol) const { // This check fires with empty r2 only. @@ -1227,9 +1234,10 @@ bool Row::equals(const Row& r2, uint32_t lastCol) const // because binary equality is not equality for many charsets/collations for (uint32_t col = 0; col <= lastCol; col++) { - if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::VARCHAR || - (getColType(col) == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) || - getColType(col) == execplan::CalpontSystemCatalog::TEXT)) + cscDataType columnType = getColType(col); + if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::VARCHAR || + (columnType == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) || + columnType == execplan::CalpontSystemCatalog::TEXT)) { CHARSET_INFO* cs = getCharset(col); if (cs->strnncollsp(getStringPointer(col), getStringLength(col), @@ -1238,7 +1246,7 @@ bool Row::equals(const Row& r2, uint32_t lastCol) const return false; } } - else if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::BLOB)) + else if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::BLOB)) { if (getStringLength(col) != r2.getStringLength(col)) return false; @@ -1248,13 +1256,20 @@ bool Row::equals(const Row& r2, uint32_t lastCol) const } else { - if (getColType(col) == execplan::CalpontSystemCatalog::LONGDOUBLE) + if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::LONGDOUBLE)) { if (getLongDoubleField(col) != r2.getLongDoubleField(col)) return false; } + else if (UNLIKELY(execplan::isDecimal(columnType))) + { + if (getBinaryField(col) != r2.getBinaryField(col)) + return false; + } else if (getUintField(col) != r2.getUintField(col)) + { return false; + } } } return true; diff --git a/utils/rowgroup/rowgroup.h b/utils/rowgroup/rowgroup.h index a8f84fbc8..22d47e16e 100644 --- a/utils/rowgroup/rowgroup.h +++ b/utils/rowgroup/rowgroup.h @@ -1301,85 +1301,6 @@ inline uint64_t Row::hash(uint32_t lastCol) const return ret; } -inline bool Row::equals(const Row& r2, const std::vector& keyCols) const -{ - for (uint32_t i = 0; i < keyCols.size(); i++) - { - const uint32_t& col = keyCols[i]; - - cscDataType columnType = getColType(i); - - if (!isLongString(col)) - { - if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::LONGDOUBLE)) - { - if (getLongDoubleField(i) != r2.getLongDoubleField(i)) - return false; - } - else if (UNLIKELY(execplan::isDecimal(columnType))) - { - if (getBinaryField(i) != r2.getBinaryField(i)) - return false; - } - else if (getUintField(col) != r2.getUintField(col)) - return false; - } - else - { - if (getStringLength(col) != r2.getStringLength(col)) - return false; - - if (memcmp(getStringPointer(col), r2.getStringPointer(col), getStringLength(col))) - return false; - } - } - - return true; -} - -inline bool Row::equals(const Row& r2, uint32_t lastCol) const -{ - // This check fires with empty r2 only. - if (lastCol >= columnCount) - return true; - - if (!useStringTable && !r2.useStringTable) - return !(memcmp(&data[offsets[0]], &r2.data[offsets[0]], offsets[lastCol + 1] - offsets[0])); - - for (uint32_t i = 0; i <= lastCol; i++) - { - cscDataType columnType = getColType(i); - if (!isLongString(i)) - { - if (UNLIKELY(getColType(i) == execplan::CalpontSystemCatalog::LONGDOUBLE)) - { - if (getLongDoubleField(i) != r2.getLongDoubleField(i)) - return false; - } - else if (UNLIKELY(execplan::isDecimal(columnType))) - { - if (*getBinaryField(i) != *r2.getBinaryField(i)) - return false; - } - - else if (getUintField(i) != r2.getUintField(i)) - return false; - } - else - { - uint32_t len = getStringLength(i); - - if (len != r2.getStringLength(i)) - return false; - - if (memcmp(getStringPointer(i), r2.getStringPointer(i), len)) - return false; - } - } - - return true; -} - inline bool Row::equals(const Row& r2) const { return equals(r2, columnCount - 1);