Skip to content

Commit

Permalink
Some fixes for filter pushdown (oap-project#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo authored and zhejiangxiaomai committed Mar 29, 2023
1 parent 051616e commit cb8182b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 0 additions & 7 deletions velox/dwio/common/MetadataFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,6 @@ std::unique_ptr<MetadataFilter::Node> MetadataFilter::Node::fromExpression(
}
return std::make_unique<OrNode>(std::move(lhs), std::move(rhs));
}
if (call->name() == "not") {
auto negated = fromExpression(scanSpec, *call->inputs()[0]);
if (!negated) {
return nullptr;
}
return std::make_unique<NotNode>(std::move(negated));
}
if (call->name() == "endswith" || call->name() == "contains" ||
call->name() == "like" || call->name() == "startswith" ||
call->name() == "in" || call->name() == "rlike" ||
Expand Down
6 changes: 4 additions & 2 deletions velox/substrait/SubstraitToVeloxPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class SubstraitVeloxPlanConverter {
/// existing conditions for this field.
bool setLeftBound(bool forOrRelation = false) {
if (forOrRelation) {
return true;
if (!rightBound_) leftBound_ = true;
return !rightBound_;
}
if (leftBound_ || inRange_ || multiRange_) {
return false;
Expand All @@ -202,7 +203,8 @@ class SubstraitVeloxPlanConverter {
/// existing conditions for this field.
bool setRightBound(bool forOrRelation = false) {
if (forOrRelation) {
return true;
if (!leftBound_) rightBound_ = true;
return !leftBound_;
}
if (rightBound_ || inRange_ || multiRange_) {
return false;
Expand Down
12 changes: 8 additions & 4 deletions velox/type/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,25 +661,29 @@ bool BytesRange::testBytesRange(

if (lowerUnbounded_) {
// min > upper_
int compare = compareRanges(min->data(), min->length(), upper_);
return min.has_value() &&
compareRanges(min->data(), min->length(), upper_) < 0;
(compare < 0 || (!upperExclusive_ && compare == 0));
}

if (upperUnbounded_) {
// max < lower_
int compare = compareRanges(max->data(), max->length(), lower_);
return max.has_value() &&
compareRanges(max->data(), max->length(), lower_) > 0;
(compare > 0 || (!lowerExclusive_ && compare == 0));
}

// min > upper_
int compare = compareRanges(min->data(), min->length(), upper_);
if (min.has_value() &&
compareRanges(min->data(), min->length(), upper_) > 0) {
(compare > 0 || (compare == 0 && upperExclusive_))) {
return false;
}

// max < lower_
compare = compareRanges(max->data(), max->length(), lower_);
if (max.has_value() &&
compareRanges(max->data(), max->length(), lower_) < 0) {
(compare < 0 || (compare == 0 && lowerExclusive_))) {
return false;
}
return true;
Expand Down

0 comments on commit cb8182b

Please sign in to comment.