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

Merge pull request #1787 from mariadb-corporation/bar-develop-like

MCOL-4498 LIKE is not collation aware
This commit is contained in:
Roman Nozdrin
2021-04-02 11:57:06 +03:00
committed by GitHub
61 changed files with 1094 additions and 789 deletions

View File

@ -208,17 +208,6 @@ ConstantColumn::ConstantColumn( const ConstantColumn& rhs):
fAlias = rhs.alias();
fResult = rhs.fResult;
fResultType = rhs.fResultType;
if (fRegex.get() != NULL)
{
fRegex.reset(new CNX_Regex());
#ifdef POSIX_REGEX
string str = dataconvert::DataConvert::constructRegexp(fResult.strVal);
regcomp(fRegex.get(), str.c_str(), REG_NOSUB | REG_EXTENDED);
#else
*fRegex = dataconvert::DataConvert::constructRegexp(fResult.strVal);
#endif
}
}
ConstantColumn::ConstantColumn(const int64_t val, TYPE type) :
@ -268,12 +257,6 @@ ConstantColumn::ConstantColumn(const uint64_t val, TYPE type,
ConstantColumn::~ConstantColumn()
{
#ifdef POSIX_REGEX
if (fRegex.get() != NULL)
regfree(fRegex.get());
#endif
}
const string ConstantColumn::toString() const
@ -409,17 +392,5 @@ bool ConstantColumn::operator!=(const TreeNode* t) const
return (!(*this == t));
}
void ConstantColumn::constructRegex()
{
//fRegex = new regex_t();
fRegex.reset(new CNX_Regex());
#ifdef POSIX_REGEX
string str = dataconvert::DataConvert::constructRegexp(fResult.strVal);
regcomp(fRegex.get(), str.c_str(), REG_NOSUB | REG_EXTENDED);
#else
*fRegex = dataconvert::DataConvert::constructRegexp(fResult.strVal);
#endif
}
}
// vim:ts=4 sw=4:

View File

@ -242,10 +242,6 @@ public:
*/
using ReturnedColumn::evaluate;
virtual void evaluate(rowgroup::Row& row) {}
/**
* F&E
*/
virtual void constructRegex();
/**
* F&E
*/

View File

@ -386,40 +386,15 @@ bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, ReturnedCol
// 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(&regex, str.c_str(), REG_NOSUB | REG_EXTENDED);
bool ret = regexec(&regex, v.c_str(), 0, NULL, 0) == 0;
regfree(&regex);
#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);
}
const std::string & subject = lop->getStrVal(row, isNull);
if (isNull)
return false;
const std::string & pattern = rop->getStrVal(row, isNull);
if (isNull)
return false;
return datatypes::Charset(cs).like(fOp == OP_NOTLIKE,
utils::ConstString(subject),
utils::ConstString(pattern));
}
// fOpType should have already been set on the connector during parsing

View File

@ -416,19 +416,6 @@ void SimpleFilter::unserialize(messageqcpp::ByteStream& b)
fWindowFunctionColumnList.push_back(raf);
}
// construct regex constant for like operator
if (fOp->op() == OP_LIKE || fOp->op() == OP_NOTLIKE)
{
ConstantColumn* rcc = dynamic_cast<ConstantColumn*>(fRhs);
if (rcc)
rcc->constructRegex();
ConstantColumn* lcc = dynamic_cast<ConstantColumn*>(fLhs);
if (lcc)
lcc->constructRegex();
}
}
bool SimpleFilter::operator==(const SimpleFilter& t) const

View File

@ -50,7 +50,6 @@ TreeNode::TreeNode(const TreeNode& rhs):
fResult(rhs.fResult),
fResultType(rhs.resultType()),
fOperationType(rhs.operationType()),
fRegex (rhs.regex()),
fDerivedTable (rhs.derivedTable()),
fRefCount(rhs.refCount()),
fDerivedRefCol(rhs.derivedRefCol())

View File

@ -356,16 +356,6 @@ public:
return fResult;
}
// regex mutator and accessor
virtual void regex(SP_IDB_Regex regex)
{
fRegex = regex;
}
virtual SP_IDB_Regex regex() const
{
return fRegex;
}
uint32_t charsetNumber() const
{
return fResultType.charsetNumber;
@ -380,7 +370,6 @@ protected:
Result fResult;
execplan::CalpontSystemCatalog::ColType fResultType; // mapped from mysql data type
execplan::CalpontSystemCatalog::ColType fOperationType; // operator type, could be different from the result type
SP_IDB_Regex fRegex;
// double's range is +/-1.7E308 with at least 15 digits of precision
char tmp[312]; // for conversion use

View File

@ -62,6 +62,60 @@ const int8_t COMPARE_NGE = (COMPARE_GE | COMPARE_NOT); //0x0e
const int8_t COMPARE_LIKE = 0x10;
const int8_t COMPARE_NLIKE = (COMPARE_LIKE | COMPARE_NOT); //0x18
namespace primitives
{
using utils::ConstString;
class StringComparator: public datatypes::Charset
{
public:
StringComparator(const Charset &cs)
:Charset(cs)
{ }
bool op(int * error, uint8_t COP,
const ConstString &str1,
const ConstString &str2) const
{
if (COP & COMPARE_LIKE)
return like(COP & COMPARE_NOT, str1, str2);
int cmp = strnncollsp(str1, str2);
switch (COP)
{
case COMPARE_NIL:
return false;
case COMPARE_LT:
return cmp < 0;
case COMPARE_EQ:
return cmp == 0;
case COMPARE_LE:
return cmp <= 0;
case COMPARE_GT:
return cmp > 0;
case COMPARE_NE:
return cmp != 0;
case COMPARE_GE:
return cmp >= 0;
default:
*error |= 1;
return false;
}
}
};
} // namespace primities
// BOP (Binary Operation) values
// used to tell if the operations are all be true or
// any to be true.