Skip to content

Commit

Permalink
add tag filter for subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Sep 28, 2022
1 parent d77b5a8 commit 5c84849
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/graph/context/ast/QueryAstContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct SubgraphContext final : public AstContext {
StepClause steps;
std::string loopSteps;
Expression* filter{nullptr};
Expression* tagFilter{nullptr};
Expression* edgeFilter{nullptr};
std::vector<std::string> colNames;
std::unordered_set<EdgeType> edgeTypes;
Expand Down
3 changes: 2 additions & 1 deletion src/graph/executor/algo/SubgraphExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ folly::Future<Status> SubgraphExecutor::getNeighbors() {
false,
{},
-1,
currentStep_ == 1 ? subgraph_->edgeFilter() : subgraph_->filter())
currentStep_ == 1 ? subgraph_->edgeFilter() : subgraph_->filter(),
currentStep_ == 1 ? nullptr : subgraph_->tagFilter())
.via(runner())
.thenValue([this, getNbrTime](RpcResponse&& resp) mutable {
// addStats(resp, getNbrTime.elapsedInUSec());
Expand Down
1 change: 1 addition & 0 deletions src/graph/planner/ngql/SubgraphPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ StatusOr<SubPlan> SubgraphPlanner::nSteps(SubPlan& startVidPlan, const std::stri
startVidPlan.root,
space.id,
subgraphCtx_->from.src,
subgraphCtx_->tagFilter,
subgraphCtx_->edgeFilter,
subgraphCtx_->filter,
steps.steps() + 1);
Expand Down
7 changes: 4 additions & 3 deletions src/graph/planner/plan/Algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ BiCartesianProduct::BiCartesianProduct(QueryContext* qctx)

std::unique_ptr<PlanNodeDescription> Subgraph::explain() const {
auto desc = SingleDependencyNode::explain();
addDescription("src", src_ != nullptr ? src_->toString() : "", desc.get());
addDescription("edge_filter", edgeFilter_ != nullptr ? edgeFilter_->toString() : "", desc.get());
addDescription("filter", filter_ != nullptr ? filter_->toString() : "", desc.get());
addDescription("src", src_ ? src_->toString() : "", desc.get());
addDescription("tag_filter", tagFilter_ ? tagFilter_->toString() : "", desc.get());
addDescription("edge_filter", edgeFilter_ ? edgeFilter_->toString() : "", desc.get());
addDescription("filter", filter_ ? filter_->toString() : "", desc.get());
addDescription(
"vertexProps", vertexProps_ ? folly::toJson(util::toJson(*vertexProps_)) : "", desc.get());
addDescription(
Expand Down
10 changes: 9 additions & 1 deletion src/graph/planner/plan/Algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ class Subgraph final : public SingleInputNode {
PlanNode* input,
GraphSpaceID space,
Expression* src,
const Expression* tagFilter,
const Expression* edgeFilter,
const Expression* filter,
size_t steps) {
return qctx->objPool()->makeAndAdd<Subgraph>(
qctx, input, space, DCHECK_NOTNULL(src), edgeFilter, filter, steps);
qctx, input, space, DCHECK_NOTNULL(src), tagFilter, edgeFilter, filter, steps);
}

GraphSpaceID space() const {
Expand All @@ -285,6 +286,10 @@ class Subgraph final : public SingleInputNode {
return src_;
}

const Expression* tagFilter() const {
return tagFilter_;
}

const Expression* edgeFilter() const {
return edgeFilter_;
}
Expand Down Expand Up @@ -337,19 +342,22 @@ class Subgraph final : public SingleInputNode {
PlanNode* input,
GraphSpaceID space,
Expression* src,
const Expression* tagFilter,
const Expression* edgeFilter,
const Expression* filter,
size_t steps)
: SingleInputNode(qctx, Kind::kSubgraph, input),
space_(space),
src_(src),
tagFilter_(tagFilter),
edgeFilter_(edgeFilter),
filter_(filter),
steps_(steps) {}

GraphSpaceID space_;
// vertices may be parsing from runtime.
Expression* src_{nullptr};
const Expression* tagFilter_{nullptr};
const Expression* edgeFilter_{nullptr};
const Expression* filter_{nullptr};
size_t steps_{1};
Expand Down
7 changes: 5 additions & 2 deletions src/graph/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ Status GetSubgraphValidator::validateWhere(WhereClause* where) {
{Expression::Kind::kAggregate,
Expression::Kind::kSrcProperty,
Expression::Kind::kVarProperty,
Expression::Kind::kInputProperty})) {
Expression::Kind::kInputProperty,
Expression::Kind::kLogicalOr})) {
return Status::SemanticError("Not support `%s' in where sentence.", expr->toString().c_str());
}

Expand All @@ -152,7 +153,9 @@ Status GetSubgraphValidator::validateWhere(WhereClause* where) {
if (!visitor.ok()) {
return Status::SemanticError("filter error");
}
subgraphCtx_->edgeFilter = std::move(visitor).remainedExpr();
subgraphCtx_->edgeFilter = visitor.remainedExpr();
auto tagFilter = visitor.extractedExpr() ? visitor.extractedExpr() : filter;
subgraphCtx_->tagFilter = rewriteDstProp2SrcProp(tagFilter);
} else {
subgraphCtx_->edgeFilter = condition;
}
Expand Down
8 changes: 8 additions & 0 deletions src/graph/visitor/ExtractFilterExprVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ void ExtractFilterExprVisitor::ExtractRemainExpr(LogicalExpression *expr,
}

operands.resize(lastUsedExprInd);
if (lastUsedExprInd > 1) {
auto extractedExpr = LogicalExpression::makeAnd(pool_);
extractedExpr->setOperands(std::move(operands));
extractedExpr_ = std::move(extractedExpr);
} else {
extractedExpr_ = std::move(operands[0]);
}

if (remainedOperands.size() > 1) {
auto remainedExpr = LogicalExpression::makeAnd(pool_);
remainedExpr->setOperands(std::move(remainedOperands));
Expand Down
5 changes: 5 additions & 0 deletions src/graph/visitor/ExtractFilterExprVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ExtractFilterExprVisitor final : public ExprVisitorImpl {
return canBePushed_;
}

Expression *extractedExpr() {
return extractedExpr_;
}

Expression *remainedExpr() {
return remainedExpr_;
}
Expand Down Expand Up @@ -88,6 +92,7 @@ class ExtractFilterExprVisitor final : public ExprVisitorImpl {
bool hasSplit{false};
bool splitForbidden{false};
Expression *remainedExpr_{nullptr};
Expression *extractedExpr_{nullptr};
PushType pushType_{PushType::kGetNeighbors};
};

Expand Down

0 comments on commit 5c84849

Please sign in to comment.