From d4f2524481f57a52f468063499c0ef1f9c7fa553 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Wed, 6 Jul 2022 11:30:34 +0800 Subject: [PATCH] fix extractfiltervisitor --- src/graph/executor/algo/SubgraphExecutor.cpp | 26 +++++++------------ src/graph/executor/algo/SubgraphExecutor.h | 12 +++------ src/graph/validator/GetSubgraphValidator.cpp | 23 ++++++++++++---- .../visitor/ExtractFilterExprVisitor.cpp | 10 ++++++- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/graph/executor/algo/SubgraphExecutor.cpp b/src/graph/executor/algo/SubgraphExecutor.cpp index fd75762fdb3..15363d47aaa 100644 --- a/src/graph/executor/algo/SubgraphExecutor.cpp +++ b/src/graph/executor/algo/SubgraphExecutor.cpp @@ -13,20 +13,17 @@ namespace graph { folly::Future SubgraphExecutor::execute() { SCOPED_TIMER(&execTime_); totalSteps_ = subgraph_->steps(); - startVids_ = buildRequestDataSet(); - if (startVids_.rows.empty()) { + auto iter = ectx_->getResult(subgraph_->inputVar()).iter(); + auto res = buildRequestListByVidType(iter.get(), subgraph_->src(), true); + NG_RETURN_IF_ERROR(res); + vids_ = res.value(); + if (vids_.empty()) { DataSet emptyResult; return finish(ResultBuilder().value(Value(std::move(emptyResult))).build()); } return getNeighbors(); } -DataSet SubgraphExecutor::buildRequestDataSet() { - auto inputVar = subgraph_->inputVar(); - auto iter = ectx_->getResult(inputVar).iter(); - return buildRequestDataSetByVidType(iter.get(), subgraph_->src(), true); -} - folly::Future SubgraphExecutor::getNeighbors() { time::Duration getNbrTime; StorageClient* storageClient = qctx_->getStorageClient(); @@ -39,7 +36,7 @@ folly::Future SubgraphExecutor::getNeighbors() { return storageClient ->getNeighbors(param, {nebula::kVid}, - std::move(startVids_.rows), + std::move(vids_), {}, edgeDirection, nullptr, @@ -54,6 +51,7 @@ folly::Future SubgraphExecutor::getNeighbors() { .via(runner()) .thenValue([this, getNbrTime](RpcResponse&& resp) mutable { // addStats(resp, getNbrTime.elapsedInUSec()); + vids_.clear(); return handleResponse(std::move(resp)); }); } @@ -80,7 +78,6 @@ folly::Future SubgraphExecutor::handleResponse(RpcResponse&& resps) { if (!subgraph_->oneMoreStep()) { --steps; } - startVids_.rows.clear(); if (!process(std::move(iter)) || ++currentStep_ > steps) { return folly::makeFuture(Status::OK()); @@ -90,7 +87,6 @@ folly::Future SubgraphExecutor::handleResponse(RpcResponse&& resps) { } bool SubgraphExecutor::process(std::unique_ptr iter) { - auto& rows = startVids_.rows; auto gnSize = iter->size(); if (gnSize == 0) { return false; @@ -99,7 +95,7 @@ bool SubgraphExecutor::process(std::unique_ptr iter) { ResultBuilder builder; builder.value(iter->valuePtr()); - robin_hood::unordered_flat_map> currentVids; + HashMap currentVids; currentVids.reserve(gnSize); historyVids_.reserve(historyVids_.size() + gnSize); if (currentStep_ == 1) { @@ -140,9 +136,7 @@ bool SubgraphExecutor::process(std::unique_ptr iter) { } if (currentVids.emplace(dst, currentStep_).second) { // next vids for getNeighbor - Row row; - row.values.emplace_back(std::move(dst)); - rows.emplace_back(std::move(row)); + vids_.emplace_back(std::move(dst)); } iter->next(); } @@ -153,7 +147,7 @@ bool SubgraphExecutor::process(std::unique_ptr iter) { // update historyVids historyVids_.insert(std::make_move_iterator(currentVids.begin()), std::make_move_iterator(currentVids.end())); - if (rows.empty()) { + if (vids_.empty()) { return false; } return true; diff --git a/src/graph/executor/algo/SubgraphExecutor.h b/src/graph/executor/algo/SubgraphExecutor.h index af9f20d525f..62808e76849 100644 --- a/src/graph/executor/algo/SubgraphExecutor.h +++ b/src/graph/executor/algo/SubgraphExecutor.h @@ -44,6 +44,8 @@ using RpcResponse = storage::StorageRpcResponse>; + SubgraphExecutor(const PlanNode* node, QueryContext* qctx) : StorageAccessExecutor("SubgraphExecutor", node, qctx) { subgraph_ = asNode(node); @@ -51,8 +53,6 @@ class SubgraphExecutor : public StorageAccessExecutor { folly::Future execute() override; - DataSet buildRequestDataSet(); - folly::Future getNeighbors(); bool process(std::unique_ptr iter); @@ -60,15 +60,11 @@ class SubgraphExecutor : public StorageAccessExecutor { folly::Future handleResponse(RpcResponse&& resps); private: - robin_hood::unordered_flat_map> historyVids_; + HashMap historyVids_; const Subgraph* subgraph_{nullptr}; size_t currentStep_{1}; size_t totalSteps_{1}; - DataSet startVids_; -<<<<<<< HEAD -======= - std::unordered_map historyVids_; ->>>>>>> fix error + std::vector vids_; }; } // namespace graph diff --git a/src/graph/validator/GetSubgraphValidator.cpp b/src/graph/validator/GetSubgraphValidator.cpp index 845b276755a..e90eb3da411 100644 --- a/src/graph/validator/GetSubgraphValidator.cpp +++ b/src/graph/validator/GetSubgraphValidator.cpp @@ -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(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) { @@ -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(); } diff --git a/src/graph/visitor/ExtractFilterExprVisitor.cpp b/src/graph/visitor/ExtractFilterExprVisitor.cpp index 39bf6414854..58768f841f6 100644 --- a/src/graph/visitor/ExtractFilterExprVisitor.cpp +++ b/src/graph/visitor/ExtractFilterExprVisitor.cpp @@ -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 *) {