Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Do not dedup and remove the reversely edges directly. (#1234)
Browse files Browse the repository at this point in the history
* Do not dedup and rm the reversely edge directly.

* Support yield vertices only.
  • Loading branch information
CPWstatic committed Jul 9, 2021
1 parent 348ee1d commit 2bb65d0
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 34 deletions.
41 changes: 13 additions & 28 deletions src/executor/query/DataCollectExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ folly::Future<Status> DataCollectExecutor::doCollect() {
auto vars = dc->vars();
switch (dc->kind()) {
case DataCollect::DCKind::kSubgraph: {
NG_RETURN_IF_ERROR(collectSubgraph(vars));
NG_RETURN_IF_ERROR(collectSubgraph(vars, dc->onlyVertices()));
break;
}
case DataCollect::DCKind::kRowBasedMove: {
Expand Down Expand Up @@ -61,41 +61,26 @@ folly::Future<Status> DataCollectExecutor::doCollect() {
return finish(builder.finish());
}

Status DataCollectExecutor::collectSubgraph(const std::vector<std::string>& vars) {
Status DataCollectExecutor::collectSubgraph(const std::vector<std::string>& vars,
bool onlyVertices) {
DataSet ds;
ds.colNames = std::move(colNames_);
// the subgraph not need duplicate vertices or edges, so dedup here directly
std::unordered_set<Value> uniqueVids;
std::unordered_set<std::tuple<Value, EdgeType, EdgeRanking, Value>> uniqueEdges;
{
// getNeighbor
const auto& hist = ectx_->getHistory(vars[0]);
for (auto j = hist.begin(); j != hist.end(); ++j) {
// if (i == vars.begin() && j == hist.end() - 1) {
// continue;
// }
auto iter = (*j).iter();
List vertices;
List edges;
auto* gnIter = static_cast<GetNeighborsIter*>(iter.get());
auto originVertices = gnIter->getVertices();
for (auto& v : originVertices.values) {
if (!v.isVertex()) {
continue;
}
if (uniqueVids.emplace(v.getVertex().vid).second) {
vertices.emplace_back(std::move(v));
}
}
auto originEdges = gnIter->getEdges();
for (auto& edge : originEdges.values) {
if (!edge.isEdge()) {
continue;
}
const auto& e = edge.getEdge();
auto edgeKey = std::make_tuple(e.src, e.type, e.ranking, e.dst);
if (uniqueEdges.emplace(std::move(edgeKey)).second) {
edges.emplace_back(std::move(edge));
auto vertices = gnIter->getVertices();
List edges;
if (!onlyVertices) {
edges.reserve(vertices.size() * 2);
for (; gnIter->valid(); gnIter->next()) {
auto type = gnIter->getEdgeProp("*", kType);
if (type < 0) {
continue;
}
edges.values.emplace_back(gnIter->getEdge());
}
}
ds.rows.emplace_back(Row({std::move(vertices), std::move(edges)}));
Expand Down
2 changes: 1 addition & 1 deletion src/executor/query/DataCollectExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DataCollectExecutor final : public Executor {
private:
folly::Future<Status> doCollect();

Status collectSubgraph(const std::vector<std::string>& vars);
Status collectSubgraph(const std::vector<std::string>& vars, bool onlyVertices);

Status rowBasedMove(const std::vector<std::string>& vars);

Expand Down
11 changes: 9 additions & 2 deletions src/parser/TraverseSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ class GetSubgraphSentence final : public Sentence {
InBoundClause* in,
OutBoundClause* out,
BothInOutClause* both,
WhereClause* where) {
WhereClause* where,
bool onlyVertices) {
kind_ = Kind::kGetSubgraph;
withProp_ = withProp;
step_.reset(step);
Expand All @@ -600,6 +601,7 @@ class GetSubgraphSentence final : public Sentence {
out_.reset(out);
both_.reset(both);
where_.reset(where);
onlyVertices_ = onlyVertices;
}

StepClause* step() const {
Expand Down Expand Up @@ -630,16 +632,21 @@ class GetSubgraphSentence final : public Sentence {
return where_.get();
}

bool onlyVertices() const {
return onlyVertices_;
}

std::string toString() const override;

private:
bool withProp_;
bool withProp_{false};
std::unique_ptr<StepClause> step_;
std::unique_ptr<FromClause> from_;
std::unique_ptr<InBoundClause> in_;
std::unique_ptr<OutBoundClause> out_;
std::unique_ptr<BothInOutClause> both_;
std::unique_ptr<WhereClause> where_;
bool onlyVertices_{false};
};
} // namespace nebula
#endif // PARSER_TRAVERSESENTENCES_H_
15 changes: 13 additions & 2 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static constexpr size_t kCommentLengthLimit = 256;
nebula::meta::cpp2::FTClient *text_search_client_item;
nebula::TSClientList *text_search_client_list;
nebula::QueryUniqueIdentifier *query_unique_identifier;
std::string *subgraph_yield_clause;
}

/* destructors */
Expand Down Expand Up @@ -198,6 +199,7 @@ static constexpr size_t kCommentLengthLimit = 256;
%token KW_REDUCE
%token KW_SESSIONS KW_SESSION
%token KW_KILL KW_QUERY KW_QUERIES KW_TOP
%token KW_VERTICES

/* symbols */
%token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA
Expand Down Expand Up @@ -337,6 +339,8 @@ static constexpr size_t kCommentLengthLimit = 256;

%type <query_unique_identifier> query_unique_identifier

%type <subgraph_yield_clause> subgraph_yield_clause

%type <sentence> maintain_sentence
%type <sentence> create_space_sentence describe_space_sentence drop_space_sentence
%type <sentence> create_tag_sentence create_edge_sentence
Expand Down Expand Up @@ -522,6 +526,7 @@ unreserved_keyword
| KW_QUERY { $$ = new std::string("query"); }
| KW_KILL { $$ = new std::string("kill"); }
| KW_TOP { $$ = new std::string("top"); }
| KW_VERTICES { $$ = new std::string("vertices"); }
;

expression
Expand Down Expand Up @@ -2023,10 +2028,16 @@ both_in_out_clause
| KW_BOTH over_edges { $$ = new BothInOutClause($2, BoundClause::BOTH); }

get_subgraph_sentence
: KW_GET KW_SUBGRAPH opt_with_properites step_clause from_clause in_bound_clause out_bound_clause both_in_out_clause where_clause {
$$ = new GetSubgraphSentence($3, $4, $5, $6, $7, $8, $9);
: KW_GET KW_SUBGRAPH opt_with_properites step_clause from_clause in_bound_clause out_bound_clause both_in_out_clause where_clause subgraph_yield_clause {
$$ = new GetSubgraphSentence($3, $4, $5, $6, $7, $8, $9, $10 != nullptr);
delete $10;
}

subgraph_yield_clause
: %empty { $$ = nullptr; }
| KW_YIELD KW_VERTICES { $$ = new std::string("vertices"); }
;

use_sentence
: KW_USE name_label { $$ = new UseSentence($2); }
;
Expand Down
1 change: 1 addition & 0 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
"PROFILE" { return TokenType::KW_PROFILE; }
"FORMAT" { return TokenType::KW_FORMAT; }
"CASE" { return TokenType::KW_CASE; }
"VERTICES" { return TokenType::KW_VERTICES; }

/**
* TODO(dutor) Manage the dynamic allocated objects with an object pool,
Expand Down
9 changes: 9 additions & 0 deletions src/planner/plan/Query.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ class DataCollect final : public VariableDependencyNode {
}
}

void setOnlyVertices() {
onlyVertices_ = true;
}

DCKind kind() const {
return kind_;
}
Expand All @@ -989,6 +993,10 @@ class DataCollect final : public VariableDependencyNode {
return distinct_;
}

bool onlyVertices() const {
return onlyVertices_;
}

PlanNode* clone() const override;

std::unique_ptr<PlanNodeDescription> explain() const override;
Expand All @@ -1004,6 +1012,7 @@ class DataCollect final : public VariableDependencyNode {
// using for m to n steps
StepClause step_;
bool distinct_{false};
bool onlyVertices_{false};
};

class Join : public SingleDependencyNode {
Expand Down
8 changes: 7 additions & 1 deletion src/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace graph {
Status GetSubgraphValidator::validateImpl() {
auto* gsSentence = static_cast<GetSubgraphSentence*>(sentence_);
withProp_ = gsSentence->withProp();
onlyVertices_ = gsSentence->onlyVertices();

NG_RETURN_IF_ERROR(validateStep(gsSentence->step(), steps_));
NG_RETURN_IF_ERROR(validateStarts(gsSentence->from(), from_));
Expand Down Expand Up @@ -309,7 +310,12 @@ Status GetSubgraphValidator::toPlan() {
// edgefilter
dc->setInputVars({dep->outputVar(), subgraph->outputVar()});
}
dc->setColNames({"vertices", "edges"});
if (onlyVertices_) {
dc->setColNames({"vertices"});
} else {
dc->setColNames({"vertices", "edges"});
}
dc->setOnlyVertices();
root_ = dc;
tail_ = projectStartVid_ != nullptr ? projectStartVid_ : loop;
return Status::OK();
Expand Down
1 change: 1 addition & 0 deletions src/validator/GetSubgraphValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GetSubgraphValidator final : public TraversalValidator {
bool withProp_{false};
Expression* filter_{nullptr};
bool dstFilter_{false};
bool onlyVertices_{false};
};

} // namespace graph
Expand Down

0 comments on commit 2bb65d0

Please sign in to comment.