Skip to content
Snippets Groups Projects
Commit 9486db24 authored by yaphet's avatar yaphet Committed by GitHub
Browse files

Show and remove both tag and edge (#308)

* support show tags and edges

* support remove tag and edge

* address dangleptr's comments
parent 036283e9
No related branches found
No related tags found
No related merge requests found
Showing
with 391 additions and 23 deletions
......@@ -19,6 +19,8 @@ add_library(
CreateTagExecutor.cpp
AlterEdgeExecutor.cpp
AlterTagExecutor.cpp
RemoveTagExecutor.cpp
RemoveEdgeExecutor.cpp
DescribeTagExecutor.cpp
DescribeEdgeExecutor.cpp
InsertVertexExecutor.cpp
......
......@@ -27,11 +27,11 @@ Status CreateSpaceExecutor::prepare() {
break;
}
}
if (partNum_ == 0) {
return Status::Error("Partition_num value illegal");
if (partNum_ <= 0) {
return Status::Error("Partition_num value should be greater than zero");
}
if (replicaFactor_ == 0) {
return Status::Error("Replica_factor value illegal");
if (replicaFactor_ <= 0) {
return Status::Error("Replica_factor value should be greater than zero");
}
return Status::OK();
}
......
......@@ -17,6 +17,8 @@
#include "graph/CreateEdgeExecutor.h"
#include "graph/AlterTagExecutor.h"
#include "graph/AlterEdgeExecutor.h"
#include "graph/RemoveTagExecutor.h"
#include "graph/RemoveEdgeExecutor.h"
#include "graph/DescribeTagExecutor.h"
#include "graph/DescribeEdgeExecutor.h"
#include "graph/InsertVertexExecutor.h"
......@@ -63,6 +65,12 @@ std::unique_ptr<Executor> Executor::makeExecutor(Sentence *sentence) {
case Sentence::Kind::kDescribeEdge:
executor = std::make_unique<DescribeEdgeExecutor>(sentence, ectx());
break;
case Sentence::Kind::kRemoveTag:
executor = std::make_unique<RemoveTagExecutor>(sentence, ectx());
break;
case Sentence::Kind::kRemoveEdge:
executor = std::make_unique<RemoveEdgeExecutor>(sentence, ectx());
break;
case Sentence::Kind::kInsertVertex:
executor = std::make_unique<InsertVertexExecutor>(sentence, ectx());
break;
......
......@@ -86,7 +86,7 @@ protected:
}
protected:
ExecutionContext *ectx_;
ExecutionContext *ectx_;
std::function<void()> onFinish_;
std::function<void(Status)> onError_;
};
......
/* 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 "graph/RemoveEdgeExecutor.h"
namespace nebula {
namespace graph {
RemoveEdgeExecutor::RemoveEdgeExecutor(Sentence *sentence,
ExecutionContext *ectx) : Executor(ectx) {
sentence_ = static_cast<RemoveEdgeSentence*>(sentence);
}
Status RemoveEdgeExecutor::prepare() {
return checkIfGraphSpaceChosen();
}
void RemoveEdgeExecutor::execute() {
auto *mc = ectx()->getMetaClient();
auto *name = sentence_->name();
auto spaceId = ectx()->rctx()->session()->space();
auto future = mc->removeEdgeSchema(spaceId, *name);
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);
}
} // namespace graph
} // namespace nebula
/* 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_REMOVEEDGEEXECUTOR_H
#define GRAPH_REMOVEEDGEEXECUTOR_H
#include "base/Base.h"
#include "graph/Executor.h"
namespace nebula {
namespace graph {
class RemoveEdgeExecutor final : public Executor {
public:
RemoveEdgeExecutor(Sentence *sentence, ExecutionContext *context);
const char* name() const override {
return "RemoveEdgeExecutor";
}
Status MUST_USE_RESULT prepare() override;
void execute() override;
private:
RemoveEdgeSentence *sentence_{nullptr};
};
} // namespace graph
} // namespace nebula
#endif // GRAPH_REMOVEEDGEEXECUTOR_H
/* 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 "graph/RemoveTagExecutor.h"
namespace nebula {
namespace graph {
RemoveTagExecutor::RemoveTagExecutor(Sentence *sentence,
ExecutionContext *ectx) : Executor(ectx) {
sentence_ = static_cast<RemoveTagSentence*>(sentence);
}
Status RemoveTagExecutor::prepare() {
return checkIfGraphSpaceChosen();
}
void RemoveTagExecutor::execute() {
auto *mc = ectx()->getMetaClient();
auto *name = sentence_->name();
auto spaceId = ectx()->rctx()->session()->space();
auto future = mc->removeTagSchema(spaceId, *name);
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);
}
} // namespace graph
} // namespace nebula
/* 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_REMOVETAGEXECUTOR_H
#define GRAPH_REMOVETAGEXECUTOR_H
#include "base/Base.h"
#include "graph/Executor.h"
namespace nebula {
namespace graph {
class RemoveTagExecutor final : public Executor {
public:
RemoveTagExecutor(Sentence *sentence, ExecutionContext *context);
const char* name() const override {
return "RemoveTagExecutor";
}
Status MUST_USE_RESULT prepare() override;
void execute() override;
private:
RemoveTagSentence *sentence_{nullptr};
};
} // namespace graph
} // namespace nebula
#endif // GRAPH_REMOVETAGEXECUTOR_H
......@@ -19,7 +19,12 @@ ShowExecutor::ShowExecutor(Sentence *sentence,
Status ShowExecutor::prepare() {
return Status::OK();
if (sentence_->showType() == ShowSentence::ShowType::kShowTags ||
sentence_->showType() == ShowSentence::ShowType::kShowEdges) {
return checkIfGraphSpaceChosen();
} else {
return Status::OK();
}
}
......@@ -32,6 +37,12 @@ void ShowExecutor::execute() {
case ShowSentence::ShowType::kShowSpaces:
showSpaces();
break;
case ShowSentence::ShowType::kShowTags:
showTags();
break;
case ShowSentence::ShowType::kShowEdges:
showEdges();
break;
case ShowSentence::ShowType::kShowUsers:
case ShowSentence::ShowType::kShowUser:
case ShowSentence::ShowType::kShowRoles:
......@@ -82,10 +93,10 @@ void ShowExecutor::showHosts() {
auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error("Internal error"));
onError_(Status::Error(folly::stringPrintf("Internal error : %s",
e.what().c_str())));
return;
};
std::move(future).via(runner).thenValue(cb).thenError(error);
}
......@@ -125,10 +136,89 @@ void ShowExecutor::showSpaces() {
auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error("Internal error"));
onError_(Status::Error(folly::stringPrintf("Internal error : %s",
e.what().c_str())));
return;
};
std::move(future).via(runner).thenValue(cb).thenError(error);
}
void ShowExecutor::showTags() {
auto spaceId = ectx()->rctx()->session()->space();
auto future = ectx()->getMetaClient()->listTagSchemas(spaceId);
auto *runner = ectx()->rctx()->runner();
resp_ = std::make_unique<cpp2::ExecutionResponse>();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(std::move(resp).status());
return;
}
auto value = std::move(resp).value();
resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<cpp2::RowValue> rows;
std::vector<std::string> header{"Name"};
resp_->set_column_names(std::move(header));
for (auto &tag : value) {
std::vector<cpp2::ColumnValue> row;
row.resize(1);
row[0].set_str(tag.get_tag_name());
rows.emplace_back();
rows.back().set_columns(std::move(row));
}
DCHECK(onFinish_);
onFinish_();
};
auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error(folly::stringPrintf("Internal error : %s",
e.what().c_str())));
return;
};
std::move(future).via(runner).thenValue(cb).thenError(error);
}
void ShowExecutor::showEdges() {
auto spaceId = ectx()->rctx()->session()->space();
auto future = ectx()->getMetaClient()->listEdgeSchemas(spaceId);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(std::move(resp).status());
return;
}
auto value = std::move(resp).value();
resp_ = std::make_unique<cpp2::ExecutionResponse>();
std::vector<cpp2::RowValue> rows;
std::vector<std::string> header{"Name"};
resp_->set_column_names(std::move(header));
for (auto &edge : value) {
std::vector<cpp2::ColumnValue> row;
row.resize(1);
row[0].set_str(edge.get_edge_name());
rows.emplace_back();
rows.back().set_columns(std::move(row));
}
DCHECK(onFinish_);
onFinish_();
};
auto error = [this] (auto &&e) {
LOG(ERROR) << "Exception caught: " << e.what();
DCHECK(onError_);
onError_(Status::Error(folly::stringPrintf("Internal error : %s",
e.what().c_str())));
return;
};
std::move(future).via(runner).thenValue(cb).thenError(error);
}
......
......@@ -26,6 +26,8 @@ public:
void execute() override;
void showHosts();
void showSpaces();
void showTags();
void showEdges();
void setupResponse(cpp2::ExecutionResponse &resp) override;
......
......@@ -214,6 +214,20 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "SHOW TAGS";
auto code = client->execute(query, resp);
sleep(FLAGS_load_data_interval_second + 1);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "REMOVE TAG person ";
auto code = client->execute(query, resp);
sleep(FLAGS_load_data_interval_second + 1);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DROP SPACE my_space";
......
......@@ -14,6 +14,10 @@ std::string ShowSentence::toString() const {
return std::string("SHOW HOSTS");
case ShowType::kShowSpaces:
return std::string("SHOW SPACES");
case ShowType::kShowTags:
return std::string("SHOW TAGS");
case ShowType::kShowEdges:
return std::string("SHOW EDGES");
case ShowType::kShowUsers:
return std::string("SHOW USERS");
case ShowType::kShowUser:
......
......@@ -21,6 +21,8 @@ public:
kUnknown,
kShowHosts,
kShowSpaces,
kShowTags,
kShowEdges,
kShowUsers,
kShowUser,
kShowRoles
......
......@@ -33,7 +33,6 @@ std::string CreateTagSentence::toString() const {
return buf;
}
std::string CreateEdgeSentence::toString() const {
std::string buf;
buf.reserve(256);
......@@ -58,7 +57,6 @@ std::string CreateEdgeSentence::toString() const {
return buf;
}
std::string AlterTagOptItem::toString() const {
std::string buf;
buf.reserve(256);
......@@ -82,7 +80,6 @@ std::string AlterTagOptItem::toString() const {
return buf;
}
std::string AlterTagOptList::toString() const {
std::string buf;
buf.reserve(256);
......@@ -108,7 +105,6 @@ std::string AlterTagSentence::toString() const {
return buf;
}
std::string AlterEdgeSentence::toString() const {
std::string buf;
buf.reserve(256);
......@@ -133,20 +129,22 @@ std::string AlterEdgeSentence::toString() const {
return buf;
}
std::string DescribeTagSentence::toString() const {
std::string buf = "DESCRIBE TAG ";
buf += *name_;
return buf;
return folly::stringPrintf("DESCRIBE TAG %s", name_.get()->c_str());
}
std::string DescribeEdgeSentence::toString() const {
std::string buf = "DESCRIBE EDGE ";
buf += *name_;
return buf;
return folly::stringPrintf("DESCRIBE EDGE %s", name_.get()->c_str());
}
std::string RemoveTagSentence::toString() const {
return folly::stringPrintf("REMOVE TAG %s", name_.get()->c_str());
}
std::string RemoveEdgeSentence::toString() const {
return folly::stringPrintf("REMOVE TAG %s", name_.get()->c_str());
}
std::string YieldSentence::toString() const {
std::string buf;
......
......@@ -262,6 +262,41 @@ private:
std::unique_ptr<std::string> name_;
};
class RemoveTagSentence final : public Sentence {
public:
explicit RemoveTagSentence(std::string *name) {
name_.reset(name);
kind_ = Kind::kRemoveTag;
}
std::string toString() const override;
std::string* name() const {
return name_.get();
}
private:
std::unique_ptr<std::string> name_;
};
class RemoveEdgeSentence final : public Sentence {
public:
explicit RemoveEdgeSentence(std::string *name) {
name_.reset(name);
kind_ = Kind::kRemoveEdge;
}
std::string toString() const override;
std::string* name() const {
return name_.get();
}
private:
std::unique_ptr<std::string> name_;
};
class YieldSentence final : public Sentence {
public:
......
......@@ -30,6 +30,8 @@ public:
kAlterEdge,
kDescribeTag,
kDescribeEdge,
kRemoveTag,
kRemoveEdge,
kInsertVertex,
kInsertEdge,
kShow,
......
......@@ -80,8 +80,8 @@ class GraphScanner;
/* keywords */
%token KW_GO KW_AS KW_TO KW_OR KW_USE KW_SET KW_FROM KW_WHERE KW_ALTER
%token KW_MATCH KW_INSERT KW_VALUES KW_YIELD KW_RETURN KW_CREATE KW_VERTEX KW_TTL
%token KW_EDGE KW_UPDATE KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE KW_DELETE KW_FIND
%token KW_INT KW_BIGINT KW_DOUBLE KW_STRING KW_BOOL KW_TAG KW_UNION KW_INTERSECT KW_MINUS
%token KW_EDGE KW_EDGES KW_UPDATE KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE KW_DELETE KW_FIND
%token KW_INT KW_BIGINT KW_DOUBLE KW_STRING KW_BOOL KW_TAG KW_TAGS KW_UNION KW_INTERSECT KW_MINUS
%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_SHOW KW_HOSTS KW_TIMESTAMP KW_ADD
%token KW_PARTITION_NUM KW_REPLICA_FACTOR KW_DROP KW_REMOVE KW_SPACES
%token KW_IF KW_NOT KW_EXISTS KW_WITH KW_FIRSTNAME KW_LASTNAME KW_EMAIL KW_PHONE KW_USER KW_USERS
......@@ -151,6 +151,7 @@ class GraphScanner;
%type <sentence> create_tag_sentence create_edge_sentence
%type <sentence> alter_tag_sentence alter_edge_sentence
%type <sentence> describe_tag_sentence describe_edge_sentence
%type <sentence> remove_tag_sentence remove_edge_sentence
%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
......@@ -585,6 +586,18 @@ describe_edge_sentence
}
;
remove_tag_sentence
: KW_REMOVE KW_TAG LABEL {
$$ = new RemoveTagSentence($3);
}
;
remove_edge_sentence
: KW_REMOVE KW_EDGE LABEL {
$$ = new RemoveEdgeSentence($3);
}
;
traverse_sentence
: go_sentence { $$ = $1; }
| match_sentence { $$ = $1; }
......@@ -840,6 +853,12 @@ show_sentence
| KW_SHOW KW_SPACES {
$$ = new ShowSentence(ShowSentence::ShowType::kShowSpaces);
}
| KW_SHOW KW_TAGS {
$$ = new ShowSentence(ShowSentence::ShowType::kShowTags);
}
| KW_SHOW KW_EDGES {
$$ = new ShowSentence(ShowSentence::ShowType::kShowEdges);
}
| KW_SHOW KW_USERS {
$$ = new ShowSentence(ShowSentence::ShowType::kShowUsers);
}
......@@ -1062,6 +1081,8 @@ maintain_sentence
| alter_edge_sentence { $$ = $1; }
| describe_tag_sentence { $$ = $1; }
| describe_edge_sentence { $$ = $1; }
| remove_tag_sentence { $$ = $1; }
| remove_edge_sentence { $$ = $1; }
| show_sentence { $$ = $1; }
| add_hosts_sentence { $$ = $1; }
| remove_hosts_sentence { $$ = $1; }
......
......@@ -37,6 +37,7 @@ CREATE ([Cc][Rr][Ee][Aa][Tt][Ee])
DESCRIBE ([Dd][Ee][Ss][Cc][Rr][Ii][Bb][Ee])
VERTEX ([Vv][Ee][Rr][Tt][Ee][Xx])
EDGE ([Ee][Dd][Gg][Ee])
EDGES ([Ee][Dd][Gg][Ee][Ss])
UPDATE ([Uu][Pp][Dd][Aa][Tt][Ee])
DELETE ([Dd][Ee][Ll][Ee][Tt][Ee])
FIND ([Ff][Ii][Nn][Dd])
......@@ -54,6 +55,7 @@ DOUBLE ([Dd][Oo][Uu][Bb][Ll][Ee])
STRING ([Ss][Tt][Rr][Ii][Nn][Gg])
BOOL ([Bb][Oo][Oo][Ll])
TAG ([Tt][Aa][Gg])
TAGS ([Tt][Aa][Gg][Ss])
UNION ([Uu][Nn][Ii][Oo][Nn])
INTERSECT ([Ii][Nn][Tt][Ee][Rr][Ss][Ee][Cc][Tt])
MINUS ([Mm][Ii][Nn][Uu][Ss])
......@@ -120,6 +122,7 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
{DESCRIBE} { return TokenType::KW_DESCRIBE; }
{VERTEX} { return TokenType::KW_VERTEX; }
{EDGE} { return TokenType::KW_EDGE; }
{EDGES} { return TokenType::KW_EDGES; }
{UPDATE} { return TokenType::KW_UPDATE; }
{DELETE} { return TokenType::KW_DELETE; }
{FIND} { return TokenType::KW_FIND; }
......@@ -137,6 +140,7 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
{STRING} { return TokenType::KW_STRING; }
{BOOL} { return TokenType::KW_BOOL; }
{TAG} { return TokenType::KW_TAG; }
{TAGS} { return TokenType::KW_TAGS; }
{UNION} { return TokenType::KW_UNION; }
{INTERSECT} { return TokenType::KW_INTERSECT; }
{MINUS} { return TokenType::KW_MINUS; }
......
......@@ -396,6 +396,18 @@ TEST(Parser, AdminOperation) {
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
GQLParser parser;
std::string query = "show tags";
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
GQLParser parser;
std::string query = "show edges";
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
GQLParser parser;
std::string query = "drop space default_space";
......
......@@ -169,6 +169,8 @@ TEST(Scanner, Basic) {
CHECK_SEMANTIC_TYPE("VERTEX", TokenType::KW_VERTEX),
CHECK_SEMANTIC_TYPE("vertex", TokenType::KW_VERTEX),
CHECK_SEMANTIC_TYPE("EDGE", TokenType::KW_EDGE),
CHECK_SEMANTIC_TYPE("edges", TokenType::KW_EDGES),
CHECK_SEMANTIC_TYPE("EDGES", TokenType::KW_EDGES),
CHECK_SEMANTIC_TYPE("edge", TokenType::KW_EDGE),
CHECK_SEMANTIC_TYPE("UPDATE", TokenType::KW_UPDATE),
CHECK_SEMANTIC_TYPE("update", TokenType::KW_UPDATE),
......@@ -198,6 +200,8 @@ TEST(Scanner, Basic) {
CHECK_SEMANTIC_TYPE("bool", TokenType::KW_BOOL),
CHECK_SEMANTIC_TYPE("TAG", TokenType::KW_TAG),
CHECK_SEMANTIC_TYPE("tag", TokenType::KW_TAG),
CHECK_SEMANTIC_TYPE("TAGS", TokenType::KW_TAGS),
CHECK_SEMANTIC_TYPE("tags", TokenType::KW_TAGS),
CHECK_SEMANTIC_TYPE("UNION", TokenType::KW_UNION),
CHECK_SEMANTIC_TYPE("union", TokenType::KW_UNION),
CHECK_SEMANTIC_TYPE("INTERSECT", TokenType::KW_INTERSECT),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment