2018-03-11 17:58:10 +00:00
|
|
|
#include "parquet_filter.h"
|
|
|
|
|
|
|
|
Constraint::Constraint(
|
2018-03-25 03:51:15 +00:00
|
|
|
RowGroupBitmap bitmap,
|
2018-03-11 17:58:10 +00:00
|
|
|
int column,
|
2018-03-25 03:51:15 +00:00
|
|
|
std::string columnName,
|
2018-03-11 17:58:10 +00:00
|
|
|
ConstraintOperator op,
|
|
|
|
ValueType type,
|
2018-03-13 00:42:50 +00:00
|
|
|
int64_t intValue,
|
2018-03-11 17:58:10 +00:00
|
|
|
double doubleValue,
|
|
|
|
std::vector<unsigned char> blobValue
|
2018-03-25 03:51:15 +00:00
|
|
|
): bitmap(bitmap),
|
|
|
|
column(column),
|
|
|
|
columnName(columnName),
|
|
|
|
op(op),
|
|
|
|
type(type),
|
|
|
|
intValue(intValue),
|
|
|
|
doubleValue(doubleValue),
|
|
|
|
blobValue(blobValue),
|
|
|
|
hadRows(false) {
|
|
|
|
RowGroupBitmap bm = bitmap;
|
|
|
|
this->bitmap = bm;
|
2018-03-16 00:40:21 +00:00
|
|
|
|
2018-03-17 19:28:51 +00:00
|
|
|
if(type == Text) {
|
2018-03-16 00:40:21 +00:00
|
|
|
stringValue = std::string((char*)&blobValue[0], blobValue.size());
|
2018-03-17 19:28:51 +00:00
|
|
|
|
|
|
|
if(op == Like) {
|
|
|
|
// This permits more rowgroups than is strictly needed
|
|
|
|
// since it assumes an implicit wildcard. But it's
|
|
|
|
// simple to implement, so we'll go with it.
|
|
|
|
likeStringValue = stringValue;
|
|
|
|
size_t idx = likeStringValue.find_first_of("%");
|
|
|
|
if(idx != std::string::npos) {
|
|
|
|
likeStringValue = likeStringValue.substr(0, idx);
|
|
|
|
}
|
|
|
|
idx = likeStringValue.find_first_of("_");
|
|
|
|
if(idx != std::string::npos) {
|
|
|
|
likeStringValue = likeStringValue.substr(0, idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 17:58:10 +00:00
|
|
|
}
|
2018-03-25 03:51:15 +00:00
|
|
|
|
|
|
|
std::string Constraint::describe() const {
|
|
|
|
std::string rv;
|
|
|
|
rv.append(columnName);
|
|
|
|
rv.append(" ");
|
|
|
|
switch(op) {
|
|
|
|
case Equal:
|
|
|
|
rv.append("=");
|
|
|
|
break;
|
|
|
|
case GreaterThan:
|
|
|
|
rv.append(">");
|
|
|
|
break;
|
|
|
|
case LessThanOrEqual:
|
|
|
|
rv.append("<=");
|
|
|
|
break;
|
|
|
|
case LessThan:
|
|
|
|
rv.append("<");
|
|
|
|
break;
|
|
|
|
case GreaterThanOrEqual:
|
|
|
|
rv.append(">=");
|
|
|
|
break;
|
|
|
|
case Match:
|
|
|
|
rv.append("MATCH");
|
|
|
|
break;
|
|
|
|
case Like:
|
|
|
|
rv.append("LIKE");
|
|
|
|
break;
|
|
|
|
case Glob:
|
|
|
|
rv.append("GLOB");
|
|
|
|
break;
|
|
|
|
case Regexp:
|
|
|
|
rv.append("REGEXP");
|
|
|
|
break;
|
|
|
|
case NotEqual:
|
|
|
|
rv.append("<>");
|
|
|
|
break;
|
|
|
|
case IsNot:
|
|
|
|
rv.append("IS NOT");
|
|
|
|
break;
|
|
|
|
case IsNotNull:
|
|
|
|
rv.append("IS NOT NULL");
|
|
|
|
break;
|
|
|
|
case IsNull:
|
|
|
|
rv.append("IS NULL");
|
|
|
|
break;
|
|
|
|
case Is:
|
|
|
|
rv.append("IS");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv.append(" ");
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case Null:
|
|
|
|
rv.append("NULL");
|
|
|
|
break;
|
|
|
|
case Integer:
|
|
|
|
rv.append(std::to_string(intValue));
|
|
|
|
break;
|
|
|
|
case Double:
|
|
|
|
rv.append(std::to_string(doubleValue));
|
|
|
|
break;
|
|
|
|
case Blob:
|
|
|
|
break;
|
|
|
|
case Text:
|
|
|
|
rv.append(stringValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|