Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format fetchedges #2779

Merged
merged 5 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/graph/context/ast/QueryAstContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ struct FetchVerticesContext final : public AstContext {
std::string inputVarName;
};

struct FetchEdgesContext final : public AstContext {
Expression* src{nullptr};
Expression* dst{nullptr};
Expression* rank{nullptr};
Expression* type{nullptr};

ExpressionProps exprProps;
YieldColumns* yieldExpr{nullptr};
std::string edgeName;
bool distinct{false};
// store the result of the previous sentence
std::string inputVarName;
};

} // namespace graph
} // namespace nebula
#endif // GRAPH_CONTEXT_AST_QUERYASTCONTEXT_H_
1 change: 1 addition & 0 deletions src/graph/planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ nebula_add_library(
ngql/SubgraphPlanner.cpp
ngql/LookupPlanner.cpp
ngql/FetchVerticesPlanner.cpp
ngql/FetchEdgesPlanner.cpp
)
5 changes: 5 additions & 0 deletions src/graph/planner/PlannersRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "graph/planner/match/PropIndexSeek.h"
#include "graph/planner/match/StartVidFinder.h"
#include "graph/planner/match/VertexIdSeek.h"
#include "graph/planner/ngql/FetchEdgesPlanner.h"
#include "graph/planner/ngql/FetchVerticesPlanner.h"
#include "graph/planner/ngql/GoPlanner.h"
#include "graph/planner/ngql/LookupPlanner.h"
Expand Down Expand Up @@ -52,6 +53,10 @@ void PlannersRegister::registSequential() {
auto& planners = Planner::plannersMap()[Sentence::Kind::kFetchVertices];
planners.emplace_back(&FetchVerticesPlanner::match, &FetchVerticesPlanner::make);
}
{
auto& planners = Planner::plannersMap()[Sentence::Kind::kFetchEdges];
planners.emplace_back(&FetchEdgesPlanner::match, &FetchEdgesPlanner::make);
}
}

void PlannersRegister::registMatch() {
Expand Down
68 changes: 68 additions & 0 deletions src/graph/planner/ngql/FetchEdgesPlanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#include "graph/planner/ngql/FetchEdgesPlanner.h"
namespace nebula {
namespace graph {

std::unique_ptr<FetchEdgesPlanner::EdgeProps> FetchEdgesPlanner::buildEdgeProps() {
auto eProps = std::make_unique<EdgeProps>();
const auto &edgePropsMap = fetchCtx_->exprProps.edgeProps();
for (const auto &edgeProp : edgePropsMap) {
EdgeProp ep;
ep.set_type(edgeProp.first);
ep.set_props(std::vector<std::string>(edgeProp.second.begin(), edgeProp.second.end()));
eProps->emplace_back(std::move(ep));
}
return eProps;
}

Expression *FetchEdgesPlanner::emptyEdgeFilter() {
auto *pool = fetchCtx_->qctx->objPool();
const auto &edgeName = fetchCtx_->edgeName;
auto notEmpty = [&pool](Expression *expr) {
return RelationalExpression::makeNE(pool, ConstantExpression::make(pool, Value::kEmpty), expr);
};
auto exprAnd = [&pool](Expression *left, Expression *right) {
return LogicalExpression::makeAnd(pool, left, right);
};

auto *srcNotEmpty = notEmpty(EdgeSrcIdExpression::make(pool, edgeName));
auto *dstNotEmpty = notEmpty(EdgeDstIdExpression::make(pool, edgeName));
auto *rankNotEmpty = notEmpty(EdgeRankExpression::make(pool, edgeName));
return exprAnd(srcNotEmpty, exprAnd(dstNotEmpty, rankNotEmpty));
}

StatusOr<SubPlan> FetchEdgesPlanner::transform(AstContext *astCtx) {
fetchCtx_ = static_cast<FetchEdgesContext *>(astCtx);
auto qctx = fetchCtx_->qctx;
auto spaceID = fetchCtx_->space.id;

SubPlan subPlan;
auto *getEdges = GetEdges::make(qctx,
nullptr,
spaceID,
fetchCtx_->src,
fetchCtx_->type,
fetchCtx_->rank,
fetchCtx_->dst,
buildEdgeProps(),
{},
fetchCtx_->distinct);
getEdges->setInputVar(fetchCtx_->inputVarName);

subPlan.root = Filter::make(qctx, getEdges, emptyEdgeFilter());
nevermore3 marked this conversation as resolved.
Show resolved Hide resolved

subPlan.root = Project::make(qctx, subPlan.root, fetchCtx_->yieldExpr);
if (fetchCtx_->distinct) {
subPlan.root = Dedup::make(qctx, subPlan.root);
}
subPlan.tail = getEdges;
return subPlan;
}

} // namespace graph
} // namespace nebula
45 changes: 45 additions & 0 deletions src/graph/planner/ngql/FetchEdgesPlanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#ifndef GRAPH_PLANNER_NGQL_FETCH_EDGES_H_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pragma once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, the effect is the same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the new code style according to the doc.

#define GRAPH_PLANNER_NGQL_FETCH_EDGES_H_

#include "common/base/Base.h"
#include "graph/context/ast/QueryAstContext.h"
#include "graph/planner/Planner.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"

namespace nebula {
namespace graph {
class FetchEdgesPlanner final : public Planner {
public:
using EdgeProp = nebula::storage::cpp2::EdgeProp;
using EdgeProps = std::vector<EdgeProp>;

static std::unique_ptr<FetchEdgesPlanner> make() {
return std::unique_ptr<FetchEdgesPlanner>(new FetchEdgesPlanner());
}

static bool match(AstContext* astCtx) {
return astCtx->sentence->kind() == Sentence::Kind::kFetchEdges;
}

StatusOr<SubPlan> transform(AstContext* astCtx) override;

std::unique_ptr<EdgeProps> buildEdgeProps();

Expression* emptyEdgeFilter();

private:
FetchEdgesPlanner() = default;

FetchEdgesContext* fetchCtx_{nullptr};
};
} // namespace graph
} // namespace nebula

#endif // GRAPH_PLANNER_NGQL_FETCH_EDGES_H
Loading