Skip to content

Commit

Permalink
fix extractfiltervisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Aug 1, 2022
1 parent 61f2a94 commit 3e838d2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/graph/executor/algo/SubgraphExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ namespace graph {
folly::Future<Status> SubgraphExecutor::execute() {
SCOPED_TIMER(&execTime_);
totalSteps_ = subgraph_->steps();
startVids_ = buildRequestDataSet();
auto res = buildRequestDataSet();
NG_RETURN_IF_ERROR(res);
startVids_ = res.value();
if (startVids_.rows.empty()) {
DataSet emptyResult;
return finish(ResultBuilder().value(Value(std::move(emptyResult))).build());
}
return getNeighbors();
}

DataSet SubgraphExecutor::buildRequestDataSet() {
StatusOr<DataSet> SubgraphExecutor::buildRequestDataSet() {
auto inputVar = subgraph_->inputVar();
auto iter = ectx_->getResult(inputVar).iter();
return buildRequestDataSetByVidType(iter.get(), subgraph_->src(), true);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/executor/algo/SubgraphExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SubgraphExecutor : public StorageAccessExecutor {

folly::Future<Status> execute() override;

DataSet buildRequestDataSet();
StatusOr<DataSet> buildRequestDataSet();

folly::Future<Status> getNeighbors();

Expand Down
23 changes: 18 additions & 5 deletions src/graph/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ Status GetSubgraphValidator::validateBothInOutBound(BothInOutClause* out) {
return Status::OK();
}

static Expression* rewriteDstProp2SrcProp(const Expression* expr) {
ObjectPool* pool = expr->getObjPool();
auto matcher = [](const Expression* e) -> bool {
return e->kind() == Expression::Kind::kDstProperty;
};
auto rewriter = [pool](const Expression* e) -> Expression* {
auto dstExpr = static_cast<const DestPropertyExpression*>(e);
return SourcePropertyExpression::make(pool, dstExpr->sym(), dstExpr->prop());
};

return RewriteVisitor::transform(expr, std::move(matcher), std::move(rewriter));
}

// Check validity of filter expression, rewrites expression to fit its sementic,
// disable some invalid expression types, collect properties used in filter.
Status GetSubgraphValidator::validateWhere(WhereClause* where) {
Expand Down Expand Up @@ -132,18 +145,18 @@ Status GetSubgraphValidator::validateWhere(WhereClause* where) {

NG_RETURN_IF_ERROR(deduceProps(filter, subgraphCtx_->exprProps));

auto condition = filter->clone();
if (ExpressionUtils::findAny(expr, {Expression::Kind::kDstProperty})) {
auto visitor = ExtractFilterExprVisitor::makePushGetNeighbors(qctx_->objPool());
auto visitor = ExtractFilterExprVisitor::makePushGetVertices(qctx_->objPool());
filter->accept(&visitor);
if (!visitor.ok()) {
return Status::SemanticError("filter error");
}
auto remainedExpr = std::move(visitor).remainedExpr();
subgraphCtx_->filter = filter;
subgraphCtx_->edgeFilter = remainedExpr;
subgraphCtx_->edgeFilter = std::move(visitor).remainedExpr();
} else {
subgraphCtx_->filter = subgraphCtx_->edgeFilter = filter;
subgraphCtx_->edgeFilter = condition;
}
subgraphCtx_->filter = rewriteDstProp2SrcProp(condition);
return Status::OK();
}

Expand Down
10 changes: 9 additions & 1 deletion src/graph/visitor/ExtractFilterExprVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ void ExtractFilterExprVisitor::visit(VariablePropertyExpression *) {
}

void ExtractFilterExprVisitor::visit(DestPropertyExpression *) {
canBePushed_ = false;
switch (pushType_) {
case PushType::kGetNeighbors:
case PushType::kGetEdges:
canBePushed_ = false;
break;
case PushType::kGetVertices:
canBePushed_ = true;
break;
}
}

void ExtractFilterExprVisitor::visit(SourcePropertyExpression *) {
Expand Down

0 comments on commit 3e838d2

Please sign in to comment.