Skip to content

Commit

Permalink
Enable filter push-down on nested field
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Nov 14, 2024
1 parent 59d5248 commit 7ea5c2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
40 changes: 8 additions & 32 deletions cpp/velox/operators/functions/SparkExprToSubfieldFilterParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,6 @@ namespace gluten {

using namespace facebook::velox;

bool SparkExprToSubfieldFilterParser::toSparkSubfield(const core::ITypedExpr* field, common::Subfield& subfield) {
std::vector<std::unique_ptr<common::Subfield::PathElement>> path;
for (auto* current = field;;) {
if (auto* fieldAccess = dynamic_cast<const core::FieldAccessTypedExpr*>(current)) {
path.push_back(std::make_unique<common::Subfield::NestedField>(fieldAccess->name()));
} else if (dynamic_cast<const core::DereferenceTypedExpr*>(current)) {
return false;
} else if (dynamic_cast<const core::InputTypedExpr*>(current) == nullptr) {
return false;
} else {
break;
}

if (!current->inputs().empty()) {
return false;
} else {
break;
}
}
std::reverse(path.begin(), path.end());
subfield = common::Subfield(std::move(path));
return true;
}

std::unique_ptr<common::Filter> SparkExprToSubfieldFilterParser::leafCallToSubfieldFilter(
const core::CallTypedExpr& call,
common::Subfield& subfield,
Expand All @@ -56,42 +32,42 @@ std::unique_ptr<common::Filter> SparkExprToSubfieldFilterParser::leafCallToSubfi
const auto* leftSide = call.inputs()[0].get();

if (call.name() == "equalto") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
return negated ? makeNotEqualFilter(call.inputs()[1], evaluator) : makeEqualFilter(call.inputs()[1], evaluator);
}
} else if (call.name() == "lessthanorequal") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
return negated ? makeGreaterThanFilter(call.inputs()[1], evaluator)
: makeLessThanOrEqualFilter(call.inputs()[1], evaluator);
}
} else if (call.name() == "lessthan") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
return negated ? makeGreaterThanOrEqualFilter(call.inputs()[1], evaluator)
: makeLessThanFilter(call.inputs()[1], evaluator);
}
} else if (call.name() == "greaterthanorequal") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
return negated ? makeLessThanFilter(call.inputs()[1], evaluator)
: makeGreaterThanOrEqualFilter(call.inputs()[1], evaluator);
}
} else if (call.name() == "greaterthan") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
return negated ? makeLessThanOrEqualFilter(call.inputs()[1], evaluator)
: makeGreaterThanFilter(call.inputs()[1], evaluator);
}
} else if (call.name() == "in") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
return makeInFilter(call.inputs()[1], evaluator, negated);
}
} else if (call.name() == "isnull") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
if (negated) {
return exec::isNotNull();
}
return exec::isNull();
}
} else if (call.name() == "isnotnull") {
if (toSparkSubfield(leftSide, subfield)) {
if (toSubfield(leftSide, subfield)) {
if (negated) {
return exec::isNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ namespace gluten {
/// Parses Spark expression into subfield filter. Differences from Presto's parser include:
/// 1) Some Spark functions are registered under different names.
/// 2) The supported functions vary.
/// 3) Filter push-down on nested fields is disabled.
class SparkExprToSubfieldFilterParser : public facebook::velox::exec::ExprToSubfieldFilterParser {
public:
std::unique_ptr<facebook::velox::common::Filter> leafCallToSubfieldFilter(
const facebook::velox::core::CallTypedExpr& call,
facebook::velox::common::Subfield& subfield,
facebook::velox::core::ExpressionEvaluator* evaluator,
bool negated) override;

private:
// Compared to the upstream 'toSubfield', the push-down of filter on nested field is disabled.
bool toSparkSubfield(const facebook::velox::core::ITypedExpr* field, facebook::velox::common::Subfield& subfield);
};
} // namespace gluten

0 comments on commit 7ea5c2c

Please sign in to comment.