Skip to content

Commit

Permalink
Merge branch 'master' into format_lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 authored Sep 24, 2021
2 parents 81e18fd + fd2e949 commit cf54a77
Show file tree
Hide file tree
Showing 56 changed files with 981 additions and 600 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
-DCMAKE_C_COMPILER=$TOOLSET_CLANG_DIR/bin/gcc \
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_TESTING=on \
-DENABLE_COVERAGE=on \
-B build
echo "::set-output name=j::10"
echo "::set-output name=t::10"
Expand Down Expand Up @@ -144,6 +145,11 @@ jobs:
make RM_DIR=false down
working-directory: tests/
timeout-minutes: 2
- name: coverage
if: ${{ matrix.compiler == 'gcc-9.2' && matrix.os == 'ubuntu2004' }}
run: |
~/.local/bin/fastcov -d build -l -o fastcov.info -p --exclude /usr/include --exclude=/opt/vesoft --exclude scanner.lex
bash <(curl -s https://codecov.io/bash) -Z -f fastcov.info
- name: Sanitizer
if: ${{ always() }}
run: |
Expand Down
2 changes: 2 additions & 0 deletions cmake/nebula/GeneralCompilerConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ if(ENABLE_TESTING AND ENABLE_COVERAGE)
add_compile_options(--coverage)
add_compile_options(-g)
add_compile_options(-O0)
nebula_add_exe_linker_flag(-coverage)
nebula_add_exe_linker_flag(-lgcov)
endif()

# TODO(doodle) Add option suggest-override for gnu
Expand Down
10 changes: 10 additions & 0 deletions src/graph/context/ast/QueryAstContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ struct SubgraphContext final : public AstContext {
bool getEdgeProp{false};
};

struct FetchVerticesContext final : public AstContext {
Starts from;
bool distinct{false};
YieldColumns* yieldExpr{nullptr};
ExpressionProps exprProps;

// store the result of the previous sentence
std::string inputVarName;
};

} // namespace graph
} // namespace nebula
#endif // GRAPH_CONTEXT_AST_QUERYASTCONTEXT_H_
15 changes: 11 additions & 4 deletions src/graph/executor/admin/ListRolesExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ folly::Future<Status> ListRolesExecutor::listRoles() {
auto foundItem = std::find_if(items.begin(), items.end(), [&account](const auto &item) {
return item.get_user_id() == account;
});
if (foundItem != items.end() && foundItem->get_role_type() != meta::cpp2::RoleType::ADMIN) {
v.emplace_back(Row({foundItem->get_user_id(),
apache::thrift::util::enumNameSafe(foundItem->get_role_type())}));
} else {
if (foundItem != items.end()) {
if (foundItem->get_role_type() != meta::cpp2::RoleType::ADMIN) {
v.emplace_back(Row({foundItem->get_user_id(),
apache::thrift::util::enumNameSafe(foundItem->get_role_type())}));
} else {
for (const auto &item : items) {
v.emplace_back(nebula::Row(
{item.get_user_id(), apache::thrift::util::enumNameSafe(item.get_role_type())}));
}
}
} else if (qctx_->rctx()->session()->isGod()) {
for (const auto &item : items) {
v.emplace_back(nebula::Row(
{item.get_user_id(), apache::thrift::util::enumNameSafe(item.get_role_type())}));
Expand Down
1 change: 1 addition & 0 deletions src/graph/planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ nebula_add_library(
ngql/GoPlanner.cpp
ngql/SubgraphPlanner.cpp
ngql/LookupPlanner.cpp
ngql/FetchVerticesPlanner.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/FetchVerticesPlanner.h"
#include "graph/planner/ngql/GoPlanner.h"
#include "graph/planner/ngql/LookupPlanner.h"
#include "graph/planner/ngql/PathPlanner.h"
Expand Down Expand Up @@ -47,6 +48,10 @@ void PlannersRegister::registSequential() {
auto& planners = Planner::plannersMap()[Sentence::Kind::kGetSubgraph];
planners.emplace_back(&SubgraphPlanner::match, &SubgraphPlanner::make);
}
{
auto& planners = Planner::plannersMap()[Sentence::Kind::kFetchVertices];
planners.emplace_back(&FetchVerticesPlanner::match, &FetchVerticesPlanner::make);
}
}

void PlannersRegister::registMatch() {
Expand Down
69 changes: 69 additions & 0 deletions src/graph/planner/ngql/FetchVerticesPlanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* 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/FetchVerticesPlanner.h"

#include "graph/planner/plan/Query.h"
#include "graph/util/PlannerUtil.h"

namespace nebula {
namespace graph {

std::unique_ptr<FetchVerticesPlanner::VertexProps> FetchVerticesPlanner::buildVertexProps(
const ExpressionProps::TagIDPropsMap& propsMap) {
if (propsMap.empty()) {
return nullptr;
}
auto vertexProps = std::make_unique<VertexProps>(propsMap.size());
auto fun = [](auto& tag) {
VertexProp vp;
vp.set_tag(tag.first);
std::vector<std::string> props(tag.second.begin(), tag.second.end());
vp.set_props(std::move(props));
return vp;
};
std::transform(propsMap.begin(), propsMap.end(), vertexProps->begin(), fun);
return vertexProps;
}

StatusOr<SubPlan> FetchVerticesPlanner::transform(AstContext* astCtx) {
fetchCtx_ = static_cast<FetchVerticesContext*>(astCtx);
auto qctx = fetchCtx_->qctx;
auto space = fetchCtx_->space;
auto& starts = fetchCtx_->from;

std::string vidsVar;
if (!starts.vids.empty() && starts.originalSrc == nullptr) {
PlannerUtil::buildConstantInput(qctx, starts, vidsVar);
} else {
starts.src = starts.originalSrc;
if (starts.fromType == kVariable) {
vidsVar = starts.userDefinedVarName;
} else {
vidsVar = fetchCtx_->inputVarName;
}
}

SubPlan subPlan;
auto* getVertices = GetVertices::make(qctx,
nullptr,
space.id,
starts.src,
buildVertexProps(fetchCtx_->exprProps.tagProps()),
{},
fetchCtx_->distinct);
getVertices->setInputVar(vidsVar);

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

} // namespace graph
} // namespace nebula
43 changes: 43 additions & 0 deletions src/graph/planner/ngql/FetchVerticesPlanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* 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_VERTICES_PLANNER_H_
#define GRAPH_PLANNER_NGQL_FETCH_VERTICES_PLANNER_H_

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

namespace nebula {
namespace graph {
class FetchVerticesPlanner final : public Planner {
public:
using VertexProp = nebula::storage::cpp2::VertexProp;
using VertexProps = std::vector<VertexProp>;

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

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

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

private:
std::unique_ptr<VertexProps> buildVertexProps(const ExpressionProps::TagIDPropsMap& propsMap);

private:
FetchVerticesPlanner() = default;

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

#endif // GRAPH_PLANNER_NGQL_FETCH_VERTICES_PLANNER_H
11 changes: 4 additions & 7 deletions src/graph/planner/ngql/GoPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

#include "graph/planner/ngql/GoPlanner.h"

#include "graph/planner/plan/Algo.h"
#include "graph/planner/plan/Logic.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/QueryUtil.h"
#include "graph/util/SchemaUtil.h"
#include "graph/validator/Validator.h"
#include "graph/util/PlannerUtil.h"

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -395,7 +392,7 @@ SubPlan GoPlanner::nStepsPlan(SubPlan& startVidPlan) {
gn->setEdgeProps(buildEdgeProps(true));
gn->setInputVar(goCtx_->vidsVar);

auto* getDst = QueryUtil::extractDstFromGN(qctx, gn, goCtx_->vidsVar);
auto* getDst = PlannerUtil::extractDstFromGN(qctx, gn, goCtx_->vidsVar);

PlanNode* loopBody = getDst;
PlanNode* loopDep = nullptr;
Expand Down Expand Up @@ -429,7 +426,7 @@ SubPlan GoPlanner::mToNStepsPlan(SubPlan& startVidPlan) {
gn->setEdgeProps(buildEdgeProps(false));
gn->setInputVar(goCtx_->vidsVar);

auto* getDst = QueryUtil::extractDstFromGN(qctx, gn, goCtx_->vidsVar);
auto* getDst = PlannerUtil::extractDstFromGN(qctx, gn, goCtx_->vidsVar);

auto* loopBody = getDst;
auto* loopDep = startVidPlan.root;
Expand Down Expand Up @@ -487,7 +484,7 @@ StatusOr<SubPlan> GoPlanner::transform(AstContext* astCtx) {
goCtx_->joinInput = goCtx_->from.fromType != FromType::kInstantExpr;
goCtx_->joinDst = !goCtx_->exprProps.dstTagProps().empty();

SubPlan startPlan = QueryUtil::buildStart(qctx, goCtx_->from, goCtx_->vidsVar);
SubPlan startPlan = PlannerUtil::buildStart(qctx, goCtx_->from, goCtx_->vidsVar);

auto& steps = goCtx_->steps;
if (steps.isMToN()) {
Expand Down
1 change: 0 additions & 1 deletion src/graph/planner/ngql/GoPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "graph/planner/Planner.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"
#include "graph/util/ExpressionUtils.h"

namespace nebula {
namespace graph {
Expand Down
8 changes: 4 additions & 4 deletions src/graph/planner/ngql/PathPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "graph/planner/plan/Algo.h"
#include "graph/planner/plan/Logic.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/QueryUtil.h"
#include "graph/util/PlannerUtil.h"
#include "graph/util/SchemaUtil.h"
#include "graph/validator/Validator.h"

Expand Down Expand Up @@ -62,15 +62,15 @@ void PathPlanner::doBuildEdgeProps(std::unique_ptr<std::vector<EdgeProp>>& edgeP
void PathPlanner::buildStart(Starts& starts, std::string& vidsVar, bool reverse) {
auto qctx = pathCtx_->qctx;
if (!starts.vids.empty() && starts.originalSrc == nullptr) {
QueryUtil::buildConstantInput(qctx, starts, vidsVar);
PlannerUtil::buildConstantInput(qctx, starts, vidsVar);
} else {
if (reverse) {
auto subPlan = QueryUtil::buildRuntimeInput(qctx, starts);
auto subPlan = PlannerUtil::buildRuntimeInput(qctx, starts);
pathCtx_->runtimeToProject = subPlan.tail;
pathCtx_->runtimeToDedup = subPlan.root;
vidsVar = pathCtx_->runtimeToDedup->outputVar();
} else {
auto subPlan = QueryUtil::buildRuntimeInput(qctx, starts);
auto subPlan = PlannerUtil::buildRuntimeInput(qctx, starts);
pathCtx_->runtimeFromProject = subPlan.tail;
pathCtx_->runtimeFromDedup = subPlan.root;
vidsVar = pathCtx_->runtimeFromDedup->outputVar();
Expand Down
4 changes: 2 additions & 2 deletions src/graph/planner/ngql/SubgraphPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "graph/planner/plan/Algo.h"
#include "graph/planner/plan/Logic.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/util/QueryUtil.h"
#include "graph/util/PlannerUtil.h"
#include "graph/util/SchemaUtil.h"
#include "graph/validator/Validator.h"

Expand Down Expand Up @@ -122,7 +122,7 @@ StatusOr<SubPlan> SubgraphPlanner::transform(AstContext* astCtx) {
auto qctx = subgraphCtx_->qctx;
std::string vidsVar;

SubPlan startPlan = QueryUtil::buildStart(qctx, subgraphCtx_->from, vidsVar);
SubPlan startPlan = PlannerUtil::buildStart(qctx, subgraphCtx_->from, vidsVar);
if (subgraphCtx_->steps.steps() == 0) {
return zeroStep(startPlan, vidsVar);
}
Expand Down
2 changes: 1 addition & 1 deletion src/graph/session/ClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void ClientSession::deleteQuery(QueryContext* qctx) {
session_.queries_ref()->erase(epId);
}

bool ClientSession::findQuery(nebula::ExecutionPlanID epId) {
bool ClientSession::findQuery(nebula::ExecutionPlanID epId) const {
folly::RWSpinLock::ReadHolder rHolder(rwSpinLock_);
auto context = contexts_.find(epId);
if (context != contexts_.end()) {
Expand Down
Loading

0 comments on commit cf54a77

Please sign in to comment.