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

[Query] Support Description about Graph Space #388

Merged
merged 25 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f9f77ab
support describe space
darionyaphet May 10, 2019
e095f3a
Merge branch 'master' into desc-space
darionyaphet May 10, 2019
d690703
support describe space
darionyaphet May 10, 2019
5616f00
Merge branch 'master' into desc-space
darionyaphet May 13, 2019
0cdf9fe
Merge branch 'master' into desc-space
darionyaphet May 13, 2019
99c20da
Merge branch 'master' into desc-space
darionyaphet May 13, 2019
5ebffcb
support desc space
darionyaphet May 13, 2019
524f599
Merge branch 'master' into desc-space
darionyaphet May 16, 2019
00241b7
address dangleptr's comment
darionyaphet May 16, 2019
1fa7ea4
Merge branch 'master' into desc-space
darionyaphet May 16, 2019
f05753e
address dutor's comment
darionyaphet May 16, 2019
6b084ae
using async
darionyaphet May 17, 2019
f6d86df
Merge branch 'master' into desc-space
darionyaphet May 17, 2019
5c81428
address dangleptr's comment
darionyaphet May 17, 2019
c90d2df
Merge branch 'master' into desc-space
darionyaphet May 17, 2019
637cf12
Merge branch 'master' into desc-space
darionyaphet May 17, 2019
95f5b42
fix
darionyaphet May 17, 2019
a0f1618
Merge branch 'master' into desc-space
darionyaphet May 17, 2019
97899e7
fix copyright
darionyaphet May 17, 2019
257dda1
address dangleptr's comment
darionyaphet May 21, 2019
7266efd
Merge branch 'master' into desc-space
darionyaphet May 21, 2019
ea6fa97
fix
darionyaphet May 21, 2019
1ff461c
Merge branch 'master' into desc-space
darionyaphet May 23, 2019
eff84b3
Merge branch 'master' into desc-space
darionyaphet May 23, 2019
22a0ae1
fix
darionyaphet May 23, 2019
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
Next Next commit
support describe space
  • Loading branch information
darionyaphet committed May 10, 2019
commit f9f77ab1a9e62ce7331f660f3a79af0ed7359f41
1 change: 1 addition & 0 deletions src/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_library(
RemoveHostsExecutor.cpp
CreateSpaceExecutor.cpp
DropSpaceExecutor.cpp
DescribeSpaceExecutor.cpp
ShowExecutor.cpp
YieldExecutor.cpp
mock/PropertiesSchema.cpp
Expand Down
53 changes: 53 additions & 0 deletions src/graph/DescribeSpaceExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved
*
* This source code is licensed under Apache 2.0 License
* (found in the LICENSE.Apache file in the root directory)
*/

#include "base/Base.h"
#include "graph/DescribeSpaceExecutor.h"
#include "meta/SchemaManager.h"

namespace nebula {
namespace graph {

DescribeSpaceExecutor::DescribeSpaceExecutor(Sentence *sentence,
ExecutionContext *ectx) : Executor(ectx) {
sentence_ = static_cast<DescribeSpaceSentence*>(sentence);
}

Status DescribeSpaceExecutor::prepare() {
return checkIfGraphSpaceChosen();
}

void DescribeSpaceExecutor::execute() {
auto spaceId = ectx()->rctx()->session()->space();
auto future = ectx()->getMetaClient()->getSpace(spaceId);
auto *runner = ectx()->rctx()->runner();

auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(std::move(resp).status());
return;
}
DCHECK(onFinish_);
onFinish_();
};

auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error("Internal error"));
return;
};

std::move(future).via(runner).thenValue(cb).thenError(error);
}

void DescribeSpaceExecutor::setupResponse(cpp2::ExecutionResponse &resp) {
resp = std::move(*resp_);
}

} // namespace graph
} // namespace nebula
39 changes: 39 additions & 0 deletions src/graph/DescribeSpaceExecutor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved
*
* This source code is licensed under Apache 2.0 License
* (found in the LICENSE.Apache file in the root directory)
*/

#ifndef GRAPH_DESCRIBESPACEEXECUTOR_H_
#define GRAPH_DESCRIBESPACEEXECUTOR_H_

#include "base/Base.h"
#include "graph/Executor.h"

namespace nebula {
namespace graph {

class DescribeSpaceExecutor final : public Executor {
public:
DescribeSpaceExecutor(Sentence *sentence, ExecutionContext *ectx);

const char* name() const override {
return "DescribeSpaceExecutor";
}

Status MUST_USE_RESULT prepare() override;

void execute() override;

void setupResponse(cpp2::ExecutionResponse &resp) override;

private:
DescribeSpaceExecutor *sentence_{nullptr};
std::string *tag_{nullptr};
std::unique_ptr<cpp2::ExecutionResponse> resp_;
};

} // namespace graph
} // namespace nebula

#endif // GRAPH_DESCRIBESPACEEXECUTOR_H_
4 changes: 4 additions & 0 deletions src/graph/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "graph/AddHostsExecutor.h"
#include "graph/RemoveHostsExecutor.h"
#include "graph/CreateSpaceExecutor.h"
#include "graph/DescribeSpaceExecutor.h"
#include "graph/DropSpaceExecutor.h"
#include "graph/YieldExecutor.h"

Expand Down Expand Up @@ -87,6 +88,9 @@ std::unique_ptr<Executor> Executor::makeExecutor(Sentence *sentence) {
case Sentence::Kind::kDropSpace:
executor = std::make_unique<DropSpaceExecutor>(sentence, ectx());
break;
case Sentence::Kind::kDescribeSpace:
executor = std::make_unique<DescribeSpaceExecutor>(sentence, ectx());
break;
case Sentence::Kind::kYield:
executor = std::make_unique<YieldExecutor>(sentence, ectx());
break;
Expand Down
6 changes: 6 additions & 0 deletions src/graph/test/SchemaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE SPACE default_space";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_load_data_interval_second + 1);
{
cpp2::ExecutionResponse resp;
Expand Down
12 changes: 9 additions & 3 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ struct IdName {
2: string name,
}

struct SpaceItem {
1: common.GraphSpaceID space_id,
2: string space_name,
3: i32 partition_num,
4: i32 replica_factor,
}

struct Pair {
1: string key,
2: string value,
Expand Down Expand Up @@ -111,9 +118,8 @@ struct GetSpaceReq {
}

struct GetSpaceResp {
1: IdName space,
2: i32 parts_num,
3: i32 replica_factor,
1: ErrorCode code,
2: SpaceItem item,
}

// Tags related operations
Expand Down
10 changes: 10 additions & 0 deletions src/meta/client/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ folly::Future<StatusOr<std::vector<SpaceIdName>>> MetaClient::listSpaces() {
});
}

folly::Future<StatusOr<cpp2::SpaceItem>>
MetaClient::getSpace(GraphSpaceID spaceId) {
cpp2::GetSpaceReq req;
req.set_space_id(spaceId);
return getResponse(std::move(req), [] (auto client, auto request) {
return client->future_getSpace(request);
}, [] (cpp2::GetSpaceResp&& resp) -> decltype(auto) {
return std::move(resp).get_item();
});
}

folly::Future<StatusOr<bool>> MetaClient::dropSpace(std::string name) {
cpp2::DropSpaceReq req;
Expand Down
3 changes: 3 additions & 0 deletions src/meta/client/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class MetaClient {
folly::Future<StatusOr<std::vector<SpaceIdName>>>
listSpaces();

folly::Future<StatusOr<cpp2::SpaceItem>>
getSpace(GraphSpaceID spaceId);

folly::Future<StatusOr<bool>>
dropSpace(std::string name);

Expand Down
8 changes: 8 additions & 0 deletions src/parser/AdminSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ std::string DropSpaceSentence::toString() const {
return buf;
}

std::string DescribeSpaceSentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "DESCRIBE SPACE ";
buf += *spaceName_;
return buf;
}

} // namespace nebula
19 changes: 18 additions & 1 deletion src/parser/AdminSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#ifndef PARSER_ADMINSENTENCES_H_
#define PARSER_ADMINSENTENCES_H_

#include "base/Base.h"
#include "parser/Clauses.h"
#include "parser/Sentence.h"
#include "network/NetworkUtils.h"
Expand Down Expand Up @@ -234,6 +233,24 @@ class DropSpaceSentence final : public Sentence {
std::unique_ptr<std::string> spaceName_;
};


class DescribeSpaceSentence final : public Sentence {
public:
explicit DescribeSpaceSentence(std::string *spaceName) {
spaceName_.reset(spaceName);
kind_ = Kind::kDescribeSpace;
}

std::string* spaceName() {
return spaceName_.get();
}

std::string toString() const override;

private:
std::unique_ptr<std::string> spaceName_;
};

} // namespace nebula

#endif // PARSER_ADMINSENTENCES_H_
1 change: 1 addition & 0 deletions src/parser/Sentence.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Sentence {
kRemoveHosts,
kCreateSpace,
kDropSpace,
kDescribeSpace,
kYield,
};

Expand Down
9 changes: 8 additions & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class GraphScanner;
%type <sentence> traverse_sentence set_sentence piped_sentence assignment_sentence
%type <sentence> maintain_sentence insert_vertex_sentence insert_edge_sentence
%type <sentence> mutate_sentence update_vertex_sentence update_edge_sentence delete_vertex_sentence delete_edge_sentence
%type <sentence> show_sentence add_hosts_sentence remove_hosts_sentence create_space_sentence
%type <sentence> show_sentence add_hosts_sentence remove_hosts_sentence create_space_sentence describe_space_sentence
%type <sentence> drop_space_sentence
%type <sentence> yield_sentence
%type <sentence> sentence
Expand Down Expand Up @@ -837,6 +837,12 @@ create_space_sentence
}
;

describe_space_sentence
: KW_DESCRIBE KW_SPACE LABEL {
$$ = new DescribeSpaceSentence($3);
}
;

space_opt_list
: space_opt_item {
$$ = new SpaceOptList();
Expand Down Expand Up @@ -888,6 +894,7 @@ maintain_sentence
| add_hosts_sentence { $$ = $1; }
| remove_hosts_sentence { $$ = $1; }
| create_space_sentence { $$ = $1; }
| describe_space_sentence { $$ = $1; }
| drop_space_sentence { $$ = $1; }
| yield_sentence {
// Now we take YIELD as a normal maintenance sentence.
Expand Down