From 09ed8b48110678a3870678aa6db0d63f524a0634 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Wed, 16 Feb 2022 14:14:34 +0800 Subject: [PATCH] remove project --- src/graph/context/ast/QueryAstContext.h | 1 + src/graph/executor/algo/SubgraphExecutor.h | 2 +- .../executor/query/DataCollectExecutor.cpp | 40 +++++++++++-------- src/graph/planner/ngql/SubgraphPlanner.cpp | 2 +- src/graph/planner/plan/Query.h | 11 +++-- src/graph/validator/GetSubgraphValidator.cpp | 5 ++- .../features/subgraph/subgraph.IntVid.feature | 1 - tests/tck/features/subgraph/subgraph.feature | 27 +------------ 8 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/graph/context/ast/QueryAstContext.h b/src/graph/context/ast/QueryAstContext.h index 6d534a203ee..8fc3c2d1015 100644 --- a/src/graph/context/ast/QueryAstContext.h +++ b/src/graph/context/ast/QueryAstContext.h @@ -127,6 +127,7 @@ struct SubgraphContext final : public AstContext { std::vector colNames; std::unordered_set edgeTypes; std::unordered_set biDirectEdgeTypes; + std::vector colType; bool withProp{false}; bool getVertexProp{false}; bool getEdgeProp{false}; diff --git a/src/graph/executor/algo/SubgraphExecutor.h b/src/graph/executor/algo/SubgraphExecutor.h index c76f9c9678a..0bd388c76f2 100644 --- a/src/graph/executor/algo/SubgraphExecutor.h +++ b/src/graph/executor/algo/SubgraphExecutor.h @@ -8,7 +8,7 @@ #include "graph/executor/Executor.h" -// Subgraph receive result from GetNeightbors +// Subgraph receive result from GetNeighbors // There are two Main functions // First : Extract the deduplicated destination VID from GetNeighbors // Second: Delete previously visited edges and save the result(iter) to the variable `resultVar` diff --git a/src/graph/executor/query/DataCollectExecutor.cpp b/src/graph/executor/query/DataCollectExecutor.cpp index 6115ccebb79..7fefd9012a4 100644 --- a/src/graph/executor/query/DataCollectExecutor.cpp +++ b/src/graph/executor/query/DataCollectExecutor.cpp @@ -61,18 +61,20 @@ folly::Future DataCollectExecutor::doCollect() { } Status DataCollectExecutor::collectSubgraph(const std::vector& vars) { - auto* dc = asNode(node()); - std::pair outCol = dc->subgraphCol(); + const auto* dc = asNode(node()); + const auto& colType = dc->colType(); DataSet ds; ds.colNames = std::move(colNames_); - for (auto i = vars.begin(); i != vars.end(); ++i) { - const auto& hist = ectx_->getHistory(*i); - for (auto j = hist.begin(); j != hist.end(); ++j) { - auto iter = (*j).iter(); - auto* gnIter = static_cast(iter.get()); - List vertices; - List edges; - if (outCol.first) { + const auto& hist = ectx_->getHistory(vars[0]); + for (const auto& result : hist) { + auto iter = result.iter(); + auto* gnIter = static_cast(iter.get()); + List vertices; + List edges; + Row row; + bool notEmpty = false; + for (const auto& type : colType) { + if (type == Value::Type::VERTEX) { auto originVertices = gnIter->getVertices(); vertices.reserve(originVertices.size()); for (auto& v : originVertices.values) { @@ -81,8 +83,11 @@ Status DataCollectExecutor::collectSubgraph(const std::vector& vars } vertices.emplace_back(std::move(v)); } - } - if (outCol.second) { + if (!vertices.empty()) { + notEmpty = true; + row.emplace_back(std::move(vertices)); + } + } else { auto originEdges = gnIter->getEdges(); edges.reserve(originEdges.size()); for (auto& edge : originEdges.values) { @@ -91,11 +96,14 @@ Status DataCollectExecutor::collectSubgraph(const std::vector& vars } edges.emplace_back(std::move(edge)); } + if (!edges.empty()) { + notEmpty = true; + } + row.emplace_back(std::move(edges)); } - if (vertices.empty() && edges.empty()) { - break; - } - ds.rows.emplace_back(Row({std::move(vertices), std::move(edges)})); + } + if (notEmpty) { + ds.rows.emplace_back(std::move(row)); } } result_.setDataSet(std::move(ds)); diff --git a/src/graph/planner/ngql/SubgraphPlanner.cpp b/src/graph/planner/ngql/SubgraphPlanner.cpp index 6c020f1613b..f071c58302d 100644 --- a/src/graph/planner/ngql/SubgraphPlanner.cpp +++ b/src/graph/planner/ngql/SubgraphPlanner.cpp @@ -82,7 +82,7 @@ StatusOr SubgraphPlanner::nSteps(SubPlan& startVidPlan, const std::stri auto* dc = DataCollect::make(qctx, DataCollect::DCKind::kSubgraph); dc->addDep(loop); dc->setInputVars({resultVar}); - dc->setSubgraphCol(subgraphCtx_->getVertexProp, subgraphCtx_->getEdgeProp); + dc->setColType(std::move(subgraphCtx_->colType)); dc->setColNames(subgraphCtx_->colNames); SubPlan subPlan; diff --git a/src/graph/planner/plan/Query.h b/src/graph/planner/plan/Query.h index 2d581234c36..8e1dc24cd07 100644 --- a/src/graph/planner/plan/Query.h +++ b/src/graph/planner/plan/Query.h @@ -1226,13 +1226,12 @@ class DataCollect final : public VariableDependencyNode { return distinct_; } - void setSubgraphCol(bool getVertices, bool getEdges) { - subgraphCol_.first = getVertices; - subgraphCol_.second = getEdges; + void setColType(std::vector&& colType) { + colType_ = std::move(colType); } - const std::pair& subgraphCol() { - return subgraphCol_; + const std::vector& colType() const { + return colType_; } PlanNode* clone() const override; @@ -1249,7 +1248,7 @@ class DataCollect final : public VariableDependencyNode { DCKind kind_; // using for m to n steps StepClause step_; - std::pair subgraphCol_; + std::vector colType_; bool distinct_{false}; }; diff --git a/src/graph/validator/GetSubgraphValidator.cpp b/src/graph/validator/GetSubgraphValidator.cpp index c681aa23c92..15fcd0b0eb7 100644 --- a/src/graph/validator/GetSubgraphValidator.cpp +++ b/src/graph/validator/GetSubgraphValidator.cpp @@ -102,22 +102,25 @@ Status GetSubgraphValidator::validateYield(YieldClause* yield) { } auto size = yield->columns().size(); outputs_.reserve(size); - + std::vector colType; for (const auto& col : yield->columns()) { const std::string& colStr = col->expr()->toString(); if (colStr == "VERTICES") { subgraphCtx_->getVertexProp = true; + colType.emplace_back(Value::Type::VERTEX); } else if (colStr == "EDGES") { if (subgraphCtx_->steps.steps() == 0) { return Status::SemanticError("Get Subgraph 0 STEPS only support YIELD vertices"); } subgraphCtx_->getEdgeProp = true; + colType.emplace_back(Value::Type::EDGE); } else { return Status::SemanticError("Get Subgraph only support YIELD vertices OR edges"); } outputs_.emplace_back(col->name(), Value::Type::LIST); } subgraphCtx_->colNames = getOutColNames(); + subgraphCtx_->colType = std::move(colType); return Status::OK(); } diff --git a/tests/tck/features/subgraph/subgraph.IntVid.feature b/tests/tck/features/subgraph/subgraph.IntVid.feature index fe051ef5dd8..e70c30ae9f1 100644 --- a/tests/tck/features/subgraph/subgraph.IntVid.feature +++ b/tests/tck/features/subgraph/subgraph.IntVid.feature @@ -955,7 +955,6 @@ Feature: Integer Vid subgraph | relationships | | <[edge1]> | | <[edge2]> | - | [] | When executing query: """ GET SUBGRAPH WITH PROP FROM hash('Tony Parker') BOTH like YIELD edges as relationships, vertices as nodes diff --git a/tests/tck/features/subgraph/subgraph.feature b/tests/tck/features/subgraph/subgraph.feature index 724e5b4b4be..15054b60f06 100644 --- a/tests/tck/features/subgraph/subgraph.feature +++ b/tests/tck/features/subgraph/subgraph.feature @@ -955,7 +955,6 @@ Feature: subgraph | b | | <[edge1]> | | <[edge2]> | - | [] | When executing query: """ GET SUBGRAPH WITH PROP FROM 'Tony Parker' BOTH like YIELD edges as a, vertices as b @@ -1011,31 +1010,7 @@ Feature: subgraph | <[vertex4]> | <[edge4]> | | <[vertex5]> | [] | - Scenario: Get subgraph in a space which doesn't have edge schema - Given an empty graph - And create a space with following options: - | partition_num | 9 | - | replica_factor | 1 | - | vid_type | FIXED_STRING(20) | - And having executed: - """ - CREATE TAG IF NOT EXISTS person(name string); - """ - When try to execute query: - """ - INSERT VERTEX person VALUES "Tom":("Tom") - """ - Then the execution should be successful - When executing query: - """ - GET SUBGRAPH 1 STEPS FROM "Tom" YIELD vertices as nodes, edges as relationships - """ - Then the result should be, in any order, with relax comparison: - | nodes | relationships | - | [("Tom")] | [] | - | [] | [] | - - Scenario: Get subgraph in a space which doesn't have edge schema + Scenario: Get subgraph in a space which doesn't have edge schema Given an empty graph And create a space with following options: | partition_num | 9 |