From f4b83b855abaef42af13831fd359c2979590ed09 Mon Sep 17 00:00:00 2001 From: yuetong Date: Thu, 10 Jan 2019 03:20:59 -0600 Subject: [PATCH 1/5] implement show all host --- src/graph/CMakeLists.txt | 1 + src/graph/Executor.cpp | 5 ++ src/graph/ShowAllHostExecutor.cpp | 60 +++++++++++++++ src/graph/ShowAllHostExecutor.h | 39 ++++++++++ src/parser/CMakeLists.txt | 1 + src/parser/Sentence.h | 1 + src/parser/SequentialSentences.h | 1 + src/parser/ShowSentences.cpp | 18 +++++ src/parser/ShowSentences.h | 26 +++++++ src/parser/parser.yy | 11 ++- src/parser/scanner.lex | 124 ++++++++++++++++-------------- src/parser/test/ScannerTest.cpp | 20 ++++- 12 files changed, 246 insertions(+), 61 deletions(-) create mode 100644 src/graph/ShowAllHostExecutor.cpp create mode 100644 src/graph/ShowAllHostExecutor.h create mode 100644 src/parser/ShowSentences.cpp create mode 100644 src/parser/ShowSentences.h diff --git a/src/graph/CMakeLists.txt b/src/graph/CMakeLists.txt index bb72a83e656..18bf2150021 100644 --- a/src/graph/CMakeLists.txt +++ b/src/graph/CMakeLists.txt @@ -22,6 +22,7 @@ add_library( DescribeEdgeExecutor.cpp InsertVertexExecutor.cpp InsertEdgeExecutor.cpp + ShowAllHostExecutor.cpp mock/PropertiesSchema.cpp mock/EdgeSchema.cpp mock/TagSchema.cpp diff --git a/src/graph/Executor.cpp b/src/graph/Executor.cpp index e4184e45f07..e3533634d84 100644 --- a/src/graph/Executor.cpp +++ b/src/graph/Executor.cpp @@ -9,6 +9,7 @@ #include "parser/TraverseSentences.h" #include "parser/MutateSentences.h" #include "parser/MaintainSentences.h" +#include "parser/ShowSentences.h" #include "graph/GoExecutor.h" #include "graph/UseExecutor.h" #include "graph/PipeExecutor.h" @@ -20,6 +21,7 @@ #include "graph/DescribeEdgeExecutor.h" #include "graph/InsertVertexExecutor.h" #include "graph/InsertEdgeExecutor.h" +#include "graph/ShowAllHostExecutor.h" namespace nebula { namespace graph { @@ -61,6 +63,9 @@ std::unique_ptr Executor::makeExecutor(Sentence *sentence) { case Sentence::Kind::kInsertEdge: executor = std::make_unique(sentence, ectx()); break; + case Sentence::Kind::kShowAllHost: + executor = std::make_unique(sentence, ectx()); + break; case Sentence::Kind::kUnknown: LOG(FATAL) << "Sentence kind unknown"; break; diff --git a/src/graph/ShowAllHostExecutor.cpp b/src/graph/ShowAllHostExecutor.cpp new file mode 100644 index 00000000000..17bf08b5254 --- /dev/null +++ b/src/graph/ShowAllHostExecutor.cpp @@ -0,0 +1,60 @@ +/* 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/ShowAllHostExecutor.h" +#include "storage/StorageServiceHandler.h" + + +namespace nebula { +namespace graph { + +//using namespace meta; + +ShowAllHostExecutor::ShowAllHostExecutor(Sentence *sentence, + ExecutionContext *ectx) : Executor(ectx) { + sentence_ = static_cast(sentence); +} + + +Status ShowAllHostExecutor::prepare() { + return Status::OK(); +} + + +void ShowAllHostExecutor::execute() { + //TODO(YT) when StorageClient fininshed, then implement this interface + #if 0 + resp_ = std::make_unique(); + GraphSpaceID space = 0; + do { + std::vector header{"Host"}; + resp_->set_column_names(std::move(header)); + auto &items = meta::HostManager::get(space)->allHosts(); + std::vector rows; + for (auto &item : items) { + std::vector row; + row.resize(1); + row[0].set_str(NetworkUtils::intToIPv4(item.first)); + + rows.emplace_back(); + rows.back().set_columns(std::move(row)); + } + resp_->set_rows(std::move(rows)); + } while (false); + + DCHECK(onFinish_); + onFinish_(); + #endif +} + + +void ShowAllHostExecutor::setupResponse(cpp2::ExecutionResponse &resp) { + resp = std::move(*resp_); +} + +} // namespace graph +} // namespace nebula diff --git a/src/graph/ShowAllHostExecutor.h b/src/graph/ShowAllHostExecutor.h new file mode 100644 index 00000000000..712d4036e4c --- /dev/null +++ b/src/graph/ShowAllHostExecutor.h @@ -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_SHOWALLHOSTEXECUTOR_H_ +#define GRAPH_SHOWALLHOSTEXECUTOR_H_ + +#include "base/Base.h" +#include "graph/Executor.h" + +namespace nebula { +namespace graph { + +class ShowAllHostExecutor final : public Executor { +public: + ShowAllHostExecutor(Sentence *sentence, ExecutionContext *ectx); + + const char* name() const override { + return "ShowAllHostExecutor"; + } + + Status MUST_USE_RESULT prepare() override; + + void execute() override; + + void setupResponse(cpp2::ExecutionResponse &resp) override; + +private: + ShowAllHostSentence *sentence_{nullptr}; + std::unique_ptr resp_; +}; + + +} // namespace graph +} // namespace nebula + +#endif // GRAPH_SHOWALLHOSTEXECUTOR_H_ diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt index 906af6dcd9f..478f2f82144 100644 --- a/src/parser/CMakeLists.txt +++ b/src/parser/CMakeLists.txt @@ -19,6 +19,7 @@ add_library( MaintainSentences.cpp MutateSentences.cpp TraverseSentences.cpp + ShowSentences.cpp ) add_dependencies(parser_obj base_obj) diff --git a/src/parser/Sentence.h b/src/parser/Sentence.h index 50a38ab2c95..8aaef460058 100644 --- a/src/parser/Sentence.h +++ b/src/parser/Sentence.h @@ -32,6 +32,7 @@ class Sentence { kDescribeEdge, kInsertVertex, kInsertEdge, + kShowAllHost, }; Kind kind() const { diff --git a/src/parser/SequentialSentences.h b/src/parser/SequentialSentences.h index 497a2af0bfa..0e817532323 100644 --- a/src/parser/SequentialSentences.h +++ b/src/parser/SequentialSentences.h @@ -10,6 +10,7 @@ #include "parser/MaintainSentences.h" #include "parser/TraverseSentences.h" #include "parser/MutateSentences.h" +#include "parser/ShowSentences.h" namespace nebula { diff --git a/src/parser/ShowSentences.cpp b/src/parser/ShowSentences.cpp new file mode 100644 index 00000000000..34a7a548c2e --- /dev/null +++ b/src/parser/ShowSentences.cpp @@ -0,0 +1,18 @@ +/* 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 "parser/ShowSentences.h" + +namespace nebula { + + +std::string ShowAllHostSentence::toString() const { + std::string buf = "SHOW ALL HOST"; + return buf; +} + +} // namespace nebula diff --git a/src/parser/ShowSentences.h b/src/parser/ShowSentences.h new file mode 100644 index 00000000000..a341af49782 --- /dev/null +++ b/src/parser/ShowSentences.h @@ -0,0 +1,26 @@ +/* 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 PARSER_SHOWSENTENCES_H_ +#define PARSER_SHOWSENTENCES_H_ + +#include "base/Base.h" +#include "parser/Clauses.h" +#include "parser/Sentence.h" + +namespace nebula { + +class ShowAllHostSentence final : public Sentence { + public: + ShowAllHostSentence() { + kind_ = Kind::kShowAllHost; + } + + std::string toString() const override; +}; + +} // namespace nebula + +#endif // PARSER_SHOWSENTENCES_H_ diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 7b27c639365..92d3c3b3bf2 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -58,7 +58,7 @@ class GraphScanner; %token KW_MATCH KW_INSERT KW_VALUES KW_YIELD KW_RETURN KW_DEFINE KW_VERTEX KW_TTL %token KW_EDGE KW_UPDATE KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE %token KW_INT KW_BIGINT KW_DOUBLE KW_STRING KW_BOOL KW_TAG KW_UNION KW_INTERSECT KW_MINUS -%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE +%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_SHOW KW_ALL KW_HOST /* symbols */ %token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA %token PIPE OR AND LT LE GT GE EQ NE ADD SUB MUL DIV MOD NOT NEG ASSIGN @@ -102,6 +102,7 @@ class GraphScanner; %type traverse_sentence set_sentence piped_sentence assignment_sentence %type maintainance_sentence insert_vertex_sentence insert_edge_sentence %type mutate_sentence update_vertex_sentence update_edge_sentence +%type show_sentence %type sentence %type sentences @@ -663,6 +664,13 @@ update_edge_sentence } ; +show_sentence + : KW_SHOW KW_ALL KW_HOST { + auto sentence = new ShowAllHostSentence(); + $$ = sentence; + } + ; + mutate_sentence : insert_vertex_sentence {} | insert_edge_sentence {} @@ -685,6 +693,7 @@ sentence | piped_sentence {} | assignment_sentence {} | mutate_sentence {} + | show_sentence {} ; sentences diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index 29a404e6b1f..2a93d937b42 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -19,95 +19,101 @@ static constexpr size_t MAX_STRING = 4096; %} %x STR - -GO ([Gg][Oo]) +/* These tokens are kept sorted for human lookup */ +ALL ([Aa][Ll][Ll]) +ALTER ([Aa][Ll][Tt][Ee][Rr]) AS ([Aa][Ss]) -TO ([Tt][Oo]) -OR ([Oo][Rr]) -USE ([Uu][Ss][Ee]) -SET ([Ss][Ee][Tt]) -FROM ([Ff][Rr][Oo][Mm]) -WHERE ([Ww][Hh][Ee][Rr][Ee]) -MATCH ([Mm][Aa][Tt][Cc][Hh]) -INSERT ([Ii][Nn][Ss][Ee][Rr][Tt]) -VALUES ([Vv][Aa][Ll][Uu][Ee][Ss]) -YIELD ([Yy][Ii][Ee][Ll][Dd]) -RETURN ([Rr][Ee][Tt][Uu][Rr][Nn]) +BIGINT ([Bb][Ii][Gg][Ii][Nn][Tt]) +BOOL ([Bb][Oo][Oo][Ll]) DEFINE ([Dd][Ee][Ff][Ii][Nn][Ee]) DESCRIBE ([Dd][Ee][Ss][Cc][Rr][Ii][Bb][Ee]) -VERTEX ([Vv][Ee][Rr][Tt][Ee][Xx]) +DOUBLE ([Dd][Oo][Uu][Bb][Ll][Ee]) EDGE ([Ee][Dd][Gg][Ee]) -UPDATE ([Uu][Pp][Dd][Aa][Tt][Ee]) -ALTER ([Aa][Ll][Tt][Ee][Rr]) -STEPS ([Ss][Tt][Ee][Pp][Ss]) -OVER ([Oo][Vv][Ee][Rr]) -UPTO ([Uu][Pp][Tt][Oo]) -REVERSELY ([Rr][Ee][Vv][Ee][Rr][Ss][Ee][Ll][Yy]) -SPACE ([Ss][Pp][Aa][Cc][Ee]) -TTL ([Tt][Tt][Ll]) +FALSE ([Ff][Aa][Ll][Ss][Ee]) +FROM ([Ff][Rr][Oo][Mm]) +GO ([Gg][Oo]) +HOST ([Hh][Oo][Ss][Tt]) +INSERT ([Ii][Nn][Ss][Ee][Rr][Tt]) INT ([Ii][Nn][Tt]) -BIGINT ([Bb][Ii][Gg][Ii][Nn][Tt]) -DOUBLE ([Dd][Oo][Uu][Bb][Ll][Ee]) -STRING ([Ss][Tt][Rr][Ii][Nn][Gg]) -BOOL ([Bb][Oo][Oo][Ll]) -TAG ([Tt][Aa][Gg]) -UNION ([Uu][Nn][Ii][Oo][Nn]) INTERSECT ([Ii][Nn][Tt][Ee][Rr][Ss][Ee][Cc][Tt]) +MATCH ([Mm][Aa][Tt][Cc][Hh]) MINUS ([Mm][Ii][Nn][Uu][Ss]) NO ([Nn][Oo]) +OR ([Oo][Rr]) +OVER ([Oo][Vv][Ee][Rr]) OVERWRITE ([Oo][Vv][Ee][Rr][Ww][Rr][Ii][Tt][Ee]) +RETURN ([Rr][Ee][Tt][Uu][Rr][Nn]) +REVERSELY ([Rr][Ee][Vv][Ee][Rr][Ss][Ee][Ll][Yy]) +SET ([Ss][Ee][Tt]) +SHOW ([Ss][Hh][Oo][Ww]) +SPACE ([Ss][Pp][Aa][Cc][Ee]) +STEPS ([Ss][Tt][Ee][Pp][Ss]) +STRING ([Ss][Tt][Rr][Ii][Nn][Gg]) +TAG ([Tt][Aa][Gg]) +TO ([Tt][Oo]) TRUE ([Tt][Rr][Uu][Ee]) -FALSE ([Ff][Aa][Ll][Ss][Ee]) +TTL ([Tt][Tt][Ll]) +UNION ([Uu][Nn][Ii][Oo][Nn]) +UPDATE ([Uu][Pp][Dd][Aa][Tt][Ee]) +UPTO ([Uu][Pp][Tt][Oo]) +USE ([Uu][Ss][Ee]) +VALUES ([Vv][Aa][Ll][Uu][Ee][Ss]) +VERTEX ([Vv][Ee][Rr][Tt][Ee][Xx]) +WHERE ([Ww][Hh][Ee][Rr][Ee]) +YIELD ([Yy][Ii][Ee][Ll][Dd]) -LABEL ([a-zA-Z][_a-zA-Z0-9]*) DEC ([0-9]) HEX ([0-9a-fA-F]) +LABEL ([a-zA-Z][_a-zA-Z0-9]*) OCT ([0-7]) - %% thread_local static char sbuf[MAX_STRING]; size_t pos = 0; -{GO} { return TokenType::KW_GO; } + /* keep same order as above */ +{ALL} { return TokenType::KW_ALL; } +{ALTER} { return TokenType::KW_ALTER; } {AS} { return TokenType::KW_AS; } -{TO} { return TokenType::KW_TO; } -{OR} { return TokenType::KW_OR; } -{USE} { return TokenType::KW_USE; } -{SET} { return TokenType::KW_SET; } -{FROM} { return TokenType::KW_FROM; } -{WHERE} { return TokenType::KW_WHERE; } -{MATCH} { return TokenType::KW_MATCH; } -{INSERT} { return TokenType::KW_INSERT; } -{VALUES} { return TokenType::KW_VALUES; } -{YIELD} { return TokenType::KW_YIELD; } -{RETURN} { return TokenType::KW_RETURN; } +{BIGINT} { return TokenType::KW_BIGINT; } +{BOOL} { return TokenType::KW_BOOL; } {DEFINE} { return TokenType::KW_DEFINE; } {DESCRIBE} { return TokenType::KW_DESCRIBE; } -{VERTEX} { return TokenType::KW_VERTEX; } +{DOUBLE} { return TokenType::KW_DOUBLE; } {EDGE} { return TokenType::KW_EDGE; } -{UPDATE} { return TokenType::KW_UPDATE; } -{ALTER} { return TokenType::KW_ALTER; } -{STEPS} { return TokenType::KW_STEPS; } -{OVER} { return TokenType::KW_OVER; } -{UPTO} { return TokenType::KW_UPTO; } -{REVERSELY} { return TokenType::KW_REVERSELY; } -{SPACE} { return TokenType::KW_SPACE; } -{TTL} { return TokenType::KW_TTL; } +{FALSE} { yylval->boolval = false; return TokenType::BOOL; } +{FROM} { return TokenType::KW_FROM; } +{GO} { return TokenType::KW_GO; } +{HOST} { return TokenType::KW_HOST; } +{INSERT} { return TokenType::KW_INSERT; } {INT} { return TokenType::KW_INT; } -{BIGINT} { return TokenType::KW_BIGINT; } -{DOUBLE} { return TokenType::KW_DOUBLE; } -{STRING} { return TokenType::KW_STRING; } -{BOOL} { return TokenType::KW_BOOL; } -{TAG} { return TokenType::KW_TAG; } -{UNION} { return TokenType::KW_UNION; } {INTERSECT} { return TokenType::KW_INTERSECT; } +{MATCH} { return TokenType::KW_MATCH; } {MINUS} { return TokenType::KW_MINUS; } {NO} { return TokenType::KW_NO; } +{OR} { return TokenType::KW_OR; } +{OVER} { return TokenType::KW_OVER; } {OVERWRITE} { return TokenType::KW_OVERWRITE; } +{RETURN} { return TokenType::KW_RETURN; } +{REVERSELY} { return TokenType::KW_REVERSELY; } +{SET} { return TokenType::KW_SET; } +{SHOW} { return TokenType::KW_SHOW; } +{SPACE} { return TokenType::KW_SPACE; } +{STEPS} { return TokenType::KW_STEPS; } +{STRING} { return TokenType::KW_STRING; } +{TAG} { return TokenType::KW_TAG; } +{TO} { return TokenType::KW_TO; } {TRUE} { yylval->boolval = true; return TokenType::BOOL; } -{FALSE} { yylval->boolval = false; return TokenType::BOOL; } +{TTL} { return TokenType::KW_TTL; } +{UNION} { return TokenType::KW_UNION; } +{UPDATE} { return TokenType::KW_UPDATE; } +{UPTO} { return TokenType::KW_UPTO; } +{USE} { return TokenType::KW_USE; } +{VALUES} { return TokenType::KW_VALUES; } +{VERTEX} { return TokenType::KW_VERTEX; } +{WHERE} { return TokenType::KW_WHERE; } +{YIELD} { return TokenType::KW_YIELD; } "." { return TokenType::DOT; } "," { return TokenType::COMMA; } diff --git a/src/parser/test/ScannerTest.cpp b/src/parser/test/ScannerTest.cpp index ec9e8e78660..3d60f0aa2eb 100644 --- a/src/parser/test/ScannerTest.cpp +++ b/src/parser/test/ScannerTest.cpp @@ -233,11 +233,29 @@ TEST(Scanner, Basic) { CHECK_SEMANTIC_VALUE("\"Hello\"", TokenType::STRING, "Hello"), CHECK_SEMANTIC_VALUE("\"Hello\\\\\"", TokenType::STRING, "Hello\\"), - CHECK_SEMANTIC_VALUE("\"Hell\\o\"", TokenType::STRING, "Hello"), CHECK_SEMANTIC_VALUE("\"He\\nllo\"", TokenType::STRING, "He\nllo"), CHECK_SEMANTIC_VALUE("\"He\\\nllo\"", TokenType::STRING, "He\nllo"), CHECK_SEMANTIC_VALUE("\"\\\"Hello\\\"\"", TokenType::STRING, "\"Hello\""), + + // escape Normal character + // CHECK_SEMANTIC_VALUE("\"Hell\o\"", TokenType::STRING, "Hello"), error + CHECK_SEMANTIC_VALUE("\"Hell\\o\"", TokenType::STRING, "Hello"), + //CHECK_SEMANTIC_VALUE("\"Hell\\\o\"", TokenType::STRING, "Hello"), error + CHECK_SEMANTIC_VALUE("\"Hell\\\\o\"", TokenType::STRING, "Hell\\o"), + //CHECK_SEMANTIC_VALUE("\"Hell\\\\\o\"", TokenType::STRING, "Hello"), error + CHECK_SEMANTIC_VALUE("\"Hell\\\\\\o\"", TokenType::STRING, "Hell\\o"), CHECK_SEMANTIC_VALUE("\"\\110ello\"", TokenType::STRING, "Hello"), + CHECK_SEMANTIC_VALUE("\"\110ello\"", TokenType::STRING, "Hello"), + + CHECK_SEMANTIC_VALUE("\"\110 \"", TokenType::STRING, "H "), + CHECK_SEMANTIC_VALUE("\"\\110 \"", TokenType::STRING, "H "), + CHECK_SEMANTIC_VALUE("\"\\\110 \"", TokenType::STRING, "H "), + CHECK_SEMANTIC_VALUE("\"\\\\110 \"", TokenType::STRING, "\\110 "), + CHECK_SEMANTIC_VALUE("\"\\\\\110 \"", TokenType::STRING, "\\H "), + CHECK_SEMANTIC_VALUE("\"\\\\\\110 \"", TokenType::STRING, "\\H "), + CHECK_SEMANTIC_VALUE("\"\\\\\\\110 \"", TokenType::STRING, "\\H "), + CHECK_SEMANTIC_VALUE("\"\\\\\\\\110 \"", TokenType::STRING, "\\\\110 "), + CHECK_SEMANTIC_VALUE("\"\\\\\\\\\110 \"", TokenType::STRING, "\\\\H "), }; #undef CHECK_SEMANTIC_TYPE #undef CHECK_SEMANTIC_VALUE From 185d733fc3bc20377fdea05508fb57d106725444 Mon Sep 17 00:00:00 2001 From: yuetong Date: Mon, 14 Jan 2019 03:13:19 -0600 Subject: [PATCH 2/5] endImprove the code of show hosts --- src/graph/CMakeLists.txt | 2 +- src/graph/Executor.cpp | 6 +- src/graph/ShowAllHostExecutor.cpp | 60 -------- src/graph/ShowExecutor.cpp | 47 +++++++ .../{ShowAllHostExecutor.h => ShowExecutor.h} | 14 +- src/parser/Sentence.h | 2 +- src/parser/ShowSentences.cpp | 12 +- src/parser/ShowSentences.h | 29 +++- src/parser/parser.yy | 8 +- src/parser/scanner.lex | 129 +++++++++--------- 10 files changed, 160 insertions(+), 149 deletions(-) delete mode 100644 src/graph/ShowAllHostExecutor.cpp create mode 100644 src/graph/ShowExecutor.cpp rename src/graph/{ShowAllHostExecutor.h => ShowExecutor.h} (65%) diff --git a/src/graph/CMakeLists.txt b/src/graph/CMakeLists.txt index 18bf2150021..dd3f3559808 100644 --- a/src/graph/CMakeLists.txt +++ b/src/graph/CMakeLists.txt @@ -22,7 +22,7 @@ add_library( DescribeEdgeExecutor.cpp InsertVertexExecutor.cpp InsertEdgeExecutor.cpp - ShowAllHostExecutor.cpp + ShowExecutor.cpp mock/PropertiesSchema.cpp mock/EdgeSchema.cpp mock/TagSchema.cpp diff --git a/src/graph/Executor.cpp b/src/graph/Executor.cpp index e3533634d84..922380e4be2 100644 --- a/src/graph/Executor.cpp +++ b/src/graph/Executor.cpp @@ -21,7 +21,7 @@ #include "graph/DescribeEdgeExecutor.h" #include "graph/InsertVertexExecutor.h" #include "graph/InsertEdgeExecutor.h" -#include "graph/ShowAllHostExecutor.h" +#include "graph/ShowExecutor.h" namespace nebula { namespace graph { @@ -63,8 +63,8 @@ std::unique_ptr Executor::makeExecutor(Sentence *sentence) { case Sentence::Kind::kInsertEdge: executor = std::make_unique(sentence, ectx()); break; - case Sentence::Kind::kShowAllHost: - executor = std::make_unique(sentence, ectx()); + case Sentence::Kind::kShow: + executor = std::make_unique(sentence, ectx()); break; case Sentence::Kind::kUnknown: LOG(FATAL) << "Sentence kind unknown"; diff --git a/src/graph/ShowAllHostExecutor.cpp b/src/graph/ShowAllHostExecutor.cpp deleted file mode 100644 index 17bf08b5254..00000000000 --- a/src/graph/ShowAllHostExecutor.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* 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/ShowAllHostExecutor.h" -#include "storage/StorageServiceHandler.h" - - -namespace nebula { -namespace graph { - -//using namespace meta; - -ShowAllHostExecutor::ShowAllHostExecutor(Sentence *sentence, - ExecutionContext *ectx) : Executor(ectx) { - sentence_ = static_cast(sentence); -} - - -Status ShowAllHostExecutor::prepare() { - return Status::OK(); -} - - -void ShowAllHostExecutor::execute() { - //TODO(YT) when StorageClient fininshed, then implement this interface - #if 0 - resp_ = std::make_unique(); - GraphSpaceID space = 0; - do { - std::vector header{"Host"}; - resp_->set_column_names(std::move(header)); - auto &items = meta::HostManager::get(space)->allHosts(); - std::vector rows; - for (auto &item : items) { - std::vector row; - row.resize(1); - row[0].set_str(NetworkUtils::intToIPv4(item.first)); - - rows.emplace_back(); - rows.back().set_columns(std::move(row)); - } - resp_->set_rows(std::move(rows)); - } while (false); - - DCHECK(onFinish_); - onFinish_(); - #endif -} - - -void ShowAllHostExecutor::setupResponse(cpp2::ExecutionResponse &resp) { - resp = std::move(*resp_); -} - -} // namespace graph -} // namespace nebula diff --git a/src/graph/ShowExecutor.cpp b/src/graph/ShowExecutor.cpp new file mode 100644 index 00000000000..f66a9d71201 --- /dev/null +++ b/src/graph/ShowExecutor.cpp @@ -0,0 +1,47 @@ +/* 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/ShowExecutor.h" +#include "storage/StorageServiceHandler.h" + + +namespace nebula { +namespace graph { + + +ShowExecutor::ShowExecutor(Sentence *sentence, + ExecutionContext *ectx) : Executor(ectx) { + sentence_ = static_cast(sentence); +} + + +Status ShowExecutor::prepare() { + return Status::OK(); +} + + +void ShowExecutor::execute() { + // TODO(YT) when StorageClient fininshed, then implement this interface + auto show_kind = sentence->showKind(); + switch (show_kind) { + case (ShowSentence::ShowKind::KShowHost): + DCHECK(onFinish_); + onFinish_(); + break; + default: + LOG(FATAL) << "Show Sentence kind illegal: " << show_kind; + break; + } +} + + +void ShowExecutor::setupResponse(cpp2::ExecutionResponse &resp) { + resp = std::move(*resp_); +} + +} // namespace graph +} // namespace nebula diff --git a/src/graph/ShowAllHostExecutor.h b/src/graph/ShowExecutor.h similarity index 65% rename from src/graph/ShowAllHostExecutor.h rename to src/graph/ShowExecutor.h index 712d4036e4c..4864c2ffe76 100644 --- a/src/graph/ShowAllHostExecutor.h +++ b/src/graph/ShowExecutor.h @@ -4,8 +4,8 @@ * (found in the LICENSE.Apache file in the root directory) */ -#ifndef GRAPH_SHOWALLHOSTEXECUTOR_H_ -#define GRAPH_SHOWALLHOSTEXECUTOR_H_ +#ifndef GRAPH_SHOWEXECUTOR_H_ +#define GRAPH_SHOWEXECUTOR_H_ #include "base/Base.h" #include "graph/Executor.h" @@ -13,12 +13,12 @@ namespace nebula { namespace graph { -class ShowAllHostExecutor final : public Executor { +class ShowExecutor final : public Executor { public: - ShowAllHostExecutor(Sentence *sentence, ExecutionContext *ectx); + ShowExecutor(Sentence *sentence, ExecutionContext *ectx); const char* name() const override { - return "ShowAllHostExecutor"; + return "ShowExecutor"; } Status MUST_USE_RESULT prepare() override; @@ -28,7 +28,7 @@ class ShowAllHostExecutor final : public Executor { void setupResponse(cpp2::ExecutionResponse &resp) override; private: - ShowAllHostSentence *sentence_{nullptr}; + ShowSentence *sentence_{nullptr}; std::unique_ptr resp_; }; @@ -36,4 +36,4 @@ class ShowAllHostExecutor final : public Executor { } // namespace graph } // namespace nebula -#endif // GRAPH_SHOWALLHOSTEXECUTOR_H_ +#endif // GRAPH_SHOWEXECUTOR_H_ diff --git a/src/parser/Sentence.h b/src/parser/Sentence.h index 8aaef460058..b7be586bcfd 100644 --- a/src/parser/Sentence.h +++ b/src/parser/Sentence.h @@ -32,7 +32,7 @@ class Sentence { kDescribeEdge, kInsertVertex, kInsertEdge, - kShowAllHost, + kShow, }; Kind kind() const { diff --git a/src/parser/ShowSentences.cpp b/src/parser/ShowSentences.cpp index 34a7a548c2e..308999d67ea 100644 --- a/src/parser/ShowSentences.cpp +++ b/src/parser/ShowSentences.cpp @@ -9,9 +9,15 @@ namespace nebula { - -std::string ShowAllHostSentence::toString() const { - std::string buf = "SHOW ALL HOST"; +std::string ShowSentence::toString() const { + switch (showKind_) { + case ShowKind::kShowHosts: + std::string buf = "SHOW HOSTS"; + break; + default: + LOG(FATAL) << "Show Sentence kind illegal: " << kind_; + break; + } return buf; } diff --git a/src/parser/ShowSentences.h b/src/parser/ShowSentences.h index a341af49782..f8fa209811f 100644 --- a/src/parser/ShowSentences.h +++ b/src/parser/ShowSentences.h @@ -12,13 +12,32 @@ namespace nebula { -class ShowAllHostSentence final : public Sentence { - public: - ShowAllHostSentence() { - kind_ = Kind::kShowAllHost; +class ShowSentence final : public Sentence { +public: + explicit ShowSentence(string cmdstr) { + kind_ = Kind::kShow; + switch (cmdstr) { + case "hosts": + showKind_ = Show_Kind::kShowHosts; + break; + default: + LOG(FATAL) << "Show Sentence kind illegal: " << cmdstr; + break; + } } - std::string toString() const override; + std::string toString() const override; + enum class ShowKind : uint32_t { + kUnknown, + kShowHosts, + }; + + ShowKind showKind() const { + return showKind_; + } + +private: + ShowKind showKind_{ShowKind::kUnknown}; }; } // namespace nebula diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 92d3c3b3bf2..6b30d22a33e 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -58,7 +58,7 @@ class GraphScanner; %token KW_MATCH KW_INSERT KW_VALUES KW_YIELD KW_RETURN KW_DEFINE KW_VERTEX KW_TTL %token KW_EDGE KW_UPDATE KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE %token KW_INT KW_BIGINT KW_DOUBLE KW_STRING KW_BOOL KW_TAG KW_UNION KW_INTERSECT KW_MINUS -%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_SHOW KW_ALL KW_HOST +%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_SHOW KW_HOSTS /* symbols */ %token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA %token PIPE OR AND LT LE GT GE EQ NE ADD SUB MUL DIV MOD NOT NEG ASSIGN @@ -665,8 +665,8 @@ update_edge_sentence ; show_sentence - : KW_SHOW KW_ALL KW_HOST { - auto sentence = new ShowAllHostSentence(); + : KW_SHOW KW_HOSTS { + auto sentence = new ShowSentence("hosts"); $$ = sentence; } ; @@ -685,6 +685,7 @@ maintainance_sentence | alter_edge_sentence {} | describe_tag_sentence {} | describe_edge_sentence {} + | show_sentence {} ; sentence @@ -693,7 +694,6 @@ sentence | piped_sentence {} | assignment_sentence {} | mutate_sentence {} - | show_sentence {} ; sentences diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index 2a93d937b42..89f8ae16982 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -19,101 +19,100 @@ static constexpr size_t MAX_STRING = 4096; %} %x STR -/* These tokens are kept sorted for human lookup */ -ALL ([Aa][Ll][Ll]) -ALTER ([Aa][Ll][Tt][Ee][Rr]) + +GO ([Gg][Oo]) AS ([Aa][Ss]) -BIGINT ([Bb][Ii][Gg][Ii][Nn][Tt]) -BOOL ([Bb][Oo][Oo][Ll]) +TO ([Tt][Oo]) +OR ([Oo][Rr]) +USE ([Uu][Ss][Ee]) +SET ([Ss][Ee][Tt]) +FROM ([Ff][Rr][Oo][Mm]) +WHERE ([Ww][Hh][Ee][Rr][Ee]) +MATCH ([Mm][Aa][Tt][Cc][Hh]) +INSERT ([Ii][Nn][Ss][Ee][Rr][Tt]) +VALUES ([Vv][Aa][Ll][Uu][Ee][Ss]) +YIELD ([Yy][Ii][Ee][Ll][Dd]) +RETURN ([Rr][Ee][Tt][Uu][Rr][Nn]) DEFINE ([Dd][Ee][Ff][Ii][Nn][Ee]) DESCRIBE ([Dd][Ee][Ss][Cc][Rr][Ii][Bb][Ee]) -DOUBLE ([Dd][Oo][Uu][Bb][Ll][Ee]) +VERTEX ([Vv][Ee][Rr][Tt][Ee][Xx]) EDGE ([Ee][Dd][Gg][Ee]) -FALSE ([Ff][Aa][Ll][Ss][Ee]) -FROM ([Ff][Rr][Oo][Mm]) -GO ([Gg][Oo]) -HOST ([Hh][Oo][Ss][Tt]) -INSERT ([Ii][Nn][Ss][Ee][Rr][Tt]) -INT ([Ii][Nn][Tt]) -INTERSECT ([Ii][Nn][Tt][Ee][Rr][Ss][Ee][Cc][Tt]) -MATCH ([Mm][Aa][Tt][Cc][Hh]) -MINUS ([Mm][Ii][Nn][Uu][Ss]) -NO ([Nn][Oo]) -OR ([Oo][Rr]) +UPDATE ([Uu][Pp][Dd][Aa][Tt][Ee]) +ALTER ([Aa][Ll][Tt][Ee][Rr]) +STEPS ([Ss][Tt][Ee][Pp][Ss]) OVER ([Oo][Vv][Ee][Rr]) -OVERWRITE ([Oo][Vv][Ee][Rr][Ww][Rr][Ii][Tt][Ee]) -RETURN ([Rr][Ee][Tt][Uu][Rr][Nn]) +UPTO ([Uu][Pp][Tt][Oo]) REVERSELY ([Rr][Ee][Vv][Ee][Rr][Ss][Ee][Ll][Yy]) -SET ([Ss][Ee][Tt]) -SHOW ([Ss][Hh][Oo][Ww]) SPACE ([Ss][Pp][Aa][Cc][Ee]) -STEPS ([Ss][Tt][Ee][Pp][Ss]) +TTL ([Tt][Tt][Ll]) +INT ([Ii][Nn][Tt]) +BIGINT ([Bb][Ii][Gg][Ii][Nn][Tt]) +DOUBLE ([Dd][Oo][Uu][Bb][Ll][Ee]) STRING ([Ss][Tt][Rr][Ii][Nn][Gg]) +BOOL ([Bb][Oo][Oo][Ll]) TAG ([Tt][Aa][Gg]) -TO ([Tt][Oo]) -TRUE ([Tt][Rr][Uu][Ee]) -TTL ([Tt][Tt][Ll]) UNION ([Uu][Nn][Ii][Oo][Nn]) -UPDATE ([Uu][Pp][Dd][Aa][Tt][Ee]) -UPTO ([Uu][Pp][Tt][Oo]) -USE ([Uu][Ss][Ee]) -VALUES ([Vv][Aa][Ll][Uu][Ee][Ss]) -VERTEX ([Vv][Ee][Rr][Tt][Ee][Xx]) -WHERE ([Ww][Hh][Ee][Rr][Ee]) -YIELD ([Yy][Ii][Ee][Ll][Dd]) +INTERSECT ([Ii][Nn][Tt][Ee][Rr][Ss][Ee][Cc][Tt]) +MINUS ([Mm][Ii][Nn][Uu][Ss]) +NO ([Nn][Oo]) +OVERWRITE ([Oo][Vv][Ee][Rr][Ww][Rr][Ii][Tt][Ee]) +TRUE ([Tt][Rr][Uu][Ee]) +FALSE ([Ff][Aa][Ll][Ss][Ee]) +SHOW ([Ss][Hh][Oo][Ww]) +HOSTS ([Hh][Oo][Ss][Tt][Ss]) + +LABEL ([a-zA-Z][_a-zA-Z0-9]*) DEC ([0-9]) HEX ([0-9a-fA-F]) -LABEL ([a-zA-Z][_a-zA-Z0-9]*) OCT ([0-7]) + %% thread_local static char sbuf[MAX_STRING]; size_t pos = 0; - /* keep same order as above */ -{ALL} { return TokenType::KW_ALL; } -{ALTER} { return TokenType::KW_ALTER; } +{GO} { return TokenType::KW_GO; } {AS} { return TokenType::KW_AS; } -{BIGINT} { return TokenType::KW_BIGINT; } -{BOOL} { return TokenType::KW_BOOL; } +{TO} { return TokenType::KW_TO; } +{OR} { return TokenType::KW_OR; } +{USE} { return TokenType::KW_USE; } +{SET} { return TokenType::KW_SET; } +{FROM} { return TokenType::KW_FROM; } +{WHERE} { return TokenType::KW_WHERE; } +{MATCH} { return TokenType::KW_MATCH; } +{INSERT} { return TokenType::KW_INSERT; } +{VALUES} { return TokenType::KW_VALUES; } +{YIELD} { return TokenType::KW_YIELD; } +{RETURN} { return TokenType::KW_RETURN; } {DEFINE} { return TokenType::KW_DEFINE; } {DESCRIBE} { return TokenType::KW_DESCRIBE; } -{DOUBLE} { return TokenType::KW_DOUBLE; } +{VERTEX} { return TokenType::KW_VERTEX; } {EDGE} { return TokenType::KW_EDGE; } -{FALSE} { yylval->boolval = false; return TokenType::BOOL; } -{FROM} { return TokenType::KW_FROM; } -{GO} { return TokenType::KW_GO; } -{HOST} { return TokenType::KW_HOST; } -{INSERT} { return TokenType::KW_INSERT; } -{INT} { return TokenType::KW_INT; } -{INTERSECT} { return TokenType::KW_INTERSECT; } -{MATCH} { return TokenType::KW_MATCH; } -{MINUS} { return TokenType::KW_MINUS; } -{NO} { return TokenType::KW_NO; } -{OR} { return TokenType::KW_OR; } +{UPDATE} { return TokenType::KW_UPDATE; } +{ALTER} { return TokenType::KW_ALTER; } +{STEPS} { return TokenType::KW_STEPS; } {OVER} { return TokenType::KW_OVER; } -{OVERWRITE} { return TokenType::KW_OVERWRITE; } -{RETURN} { return TokenType::KW_RETURN; } +{UPTO} { return TokenType::KW_UPTO; } {REVERSELY} { return TokenType::KW_REVERSELY; } -{SET} { return TokenType::KW_SET; } -{SHOW} { return TokenType::KW_SHOW; } {SPACE} { return TokenType::KW_SPACE; } -{STEPS} { return TokenType::KW_STEPS; } +{TTL} { return TokenType::KW_TTL; } +{INT} { return TokenType::KW_INT; } +{BIGINT} { return TokenType::KW_BIGINT; } +{DOUBLE} { return TokenType::KW_DOUBLE; } {STRING} { return TokenType::KW_STRING; } +{BOOL} { return TokenType::KW_BOOL; } {TAG} { return TokenType::KW_TAG; } -{TO} { return TokenType::KW_TO; } -{TRUE} { yylval->boolval = true; return TokenType::BOOL; } -{TTL} { return TokenType::KW_TTL; } {UNION} { return TokenType::KW_UNION; } -{UPDATE} { return TokenType::KW_UPDATE; } -{UPTO} { return TokenType::KW_UPTO; } -{USE} { return TokenType::KW_USE; } -{VALUES} { return TokenType::KW_VALUES; } -{VERTEX} { return TokenType::KW_VERTEX; } -{WHERE} { return TokenType::KW_WHERE; } -{YIELD} { return TokenType::KW_YIELD; } +{INTERSECT} { return TokenType::KW_INTERSECT; } +{MINUS} { return TokenType::KW_MINUS; } +{NO} { return TokenType::KW_NO; } +{OVERWRITE} { return TokenType::KW_OVERWRITE; } +{TRUE} { yylval->boolval = true; return TokenType::BOOL; } +{FALSE} { yylval->boolval = false; return TokenType::BOOL; } +{SHOW} { return TokenType::KW_SHOW; } +{HOSTS} { return TokenType::KW_HOSTS; } "." { return TokenType::DOT; } "," { return TokenType::COMMA; } From bf1d053906380acdc3f7adc7b83d52f7898918ef Mon Sep 17 00:00:00 2001 From: yuetong Date: Mon, 14 Jan 2019 04:35:18 -0600 Subject: [PATCH 3/5] endimprove show hosts --- src/graph/ShowExecutor.cpp | 4 ++-- src/parser/ShowSentences.cpp | 6 ++++-- src/parser/ShowSentences.h | 18 +++++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/graph/ShowExecutor.cpp b/src/graph/ShowExecutor.cpp index f66a9d71201..4ab4409972c 100644 --- a/src/graph/ShowExecutor.cpp +++ b/src/graph/ShowExecutor.cpp @@ -26,9 +26,9 @@ Status ShowExecutor::prepare() { void ShowExecutor::execute() { // TODO(YT) when StorageClient fininshed, then implement this interface - auto show_kind = sentence->showKind(); + auto show_kind = sentence_->showKind(); switch (show_kind) { - case (ShowSentence::ShowKind::KShowHost): + case (ShowSentence::ShowKind::kShowHosts): DCHECK(onFinish_); onFinish_(); break; diff --git a/src/parser/ShowSentences.cpp b/src/parser/ShowSentences.cpp index 308999d67ea..18c122c24e5 100644 --- a/src/parser/ShowSentences.cpp +++ b/src/parser/ShowSentences.cpp @@ -10,12 +10,14 @@ namespace nebula { std::string ShowSentence::toString() const { + std::string buf; switch (showKind_) { case ShowKind::kShowHosts: - std::string buf = "SHOW HOSTS"; + buf = "SHOW HOSTS"; break; + case ShowKind::kUnknown: default: - LOG(FATAL) << "Show Sentence kind illegal: " << kind_; + LOG(FATAL) << "Show Sentence kind illegal: " << showKind_; break; } return buf; diff --git a/src/parser/ShowSentences.h b/src/parser/ShowSentences.h index f8fa209811f..cfbd08e66cc 100644 --- a/src/parser/ShowSentences.h +++ b/src/parser/ShowSentences.h @@ -14,16 +14,12 @@ namespace nebula { class ShowSentence final : public Sentence { public: - explicit ShowSentence(string cmdstr) { + explicit ShowSentence(std::string cmdstr) { kind_ = Kind::kShow; - switch (cmdstr) { - case "hosts": - showKind_ = Show_Kind::kShowHosts; - break; - default: - LOG(FATAL) << "Show Sentence kind illegal: " << cmdstr; - break; - } + if (cmdstr.compare("hosts") == 0) + showKind_ = ShowKind::kShowHosts; + else + LOG(FATAL) << "Show Sentence kind illegal: " << cmdstr; } std::string toString() const override; @@ -40,6 +36,10 @@ class ShowSentence final : public Sentence { ShowKind showKind_{ShowKind::kUnknown}; }; +inline std::ostream& operator<<(std::ostream &os, ShowSentence::ShowKind kind) { + return os << static_cast(kind); +} + } // namespace nebula #endif // PARSER_SHOWSENTENCES_H_ From fb2a621cd5b128ff2ef31747de896eb2a2aeb2a7 Mon Sep 17 00:00:00 2001 From: yuetong Date: Tue, 15 Jan 2019 01:25:21 -0600 Subject: [PATCH 4/5] endimprove show hosts --- src/graph/ShowExecutor.cpp | 4 ++-- src/parser/ShowSentences.h | 19 +++++++++---------- src/parser/parser.yy | 2 +- src/parser/test/ScannerTest.cpp | 10 +++++++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/graph/ShowExecutor.cpp b/src/graph/ShowExecutor.cpp index 4ab4409972c..f50867215ad 100644 --- a/src/graph/ShowExecutor.cpp +++ b/src/graph/ShowExecutor.cpp @@ -28,12 +28,12 @@ void ShowExecutor::execute() { // TODO(YT) when StorageClient fininshed, then implement this interface auto show_kind = sentence_->showKind(); switch (show_kind) { - case (ShowSentence::ShowKind::kShowHosts): + case (ShowKind::kShowHosts): DCHECK(onFinish_); onFinish_(); break; default: - LOG(FATAL) << "Show Sentence kind illegal: " << show_kind; + LOG(FATAL) << "Show Sentence kind illegal: " <(kind); } diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 6b30d22a33e..d3fc63b1b57 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -666,7 +666,7 @@ update_edge_sentence show_sentence : KW_SHOW KW_HOSTS { - auto sentence = new ShowSentence("hosts"); + auto sentence = new ShowSentence(ShowKind::kShowHosts); $$ = sentence; } ; diff --git a/src/parser/test/ScannerTest.cpp b/src/parser/test/ScannerTest.cpp index 3d60f0aa2eb..e8a4c5ee48c 100644 --- a/src/parser/test/ScannerTest.cpp +++ b/src/parser/test/ScannerTest.cpp @@ -12,9 +12,7 @@ #include "parser/GraphParser.hpp" #include "parser/GraphScanner.h" -using testing::AssertionFailure; -using testing::AssertionSuccess; -using testing::AssertionResult; +using namespace ::testing; namespace nebula { @@ -203,6 +201,12 @@ TEST(Scanner, Basic) { CHECK_SEMANTIC_TYPE("intersect", TokenType::KW_INTERSECT), CHECK_SEMANTIC_TYPE("MINUS", TokenType::KW_MINUS), CHECK_SEMANTIC_TYPE("minus", TokenType::KW_MINUS), + CHECK_SEMANTIC_TYPE("SHOW", TokenType::KW_SHOW), + CHECK_SEMANTIC_TYPE("show", TokenType::KW_SHOW), + CHECK_SEMANTIC_TYPE("Show", TokenType::KW_SHOW), + CHECK_SEMANTIC_TYPE("HOSTS", TokenType::KW_HOSTS), + CHECK_SEMANTIC_TYPE("hosts", TokenType::KW_HOSTS), + CHECK_SEMANTIC_TYPE("Hosts", TokenType::KW_HOSTS), CHECK_SEMANTIC_TYPE("_type", TokenType::TYPE_PROP), CHECK_SEMANTIC_TYPE("_id", TokenType::ID_PROP), From 904b7ad651991584ca0e112f07107c4211805f3d Mon Sep 17 00:00:00 2001 From: yuetong Date: Tue, 15 Jan 2019 02:34:04 -0600 Subject: [PATCH 5/5] use std::move --- src/parser/ShowSentences.h | 2 +- src/parser/test/ScannerTest.cpp | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/parser/ShowSentences.h b/src/parser/ShowSentences.h index 672c8fafbe8..201a37e79a5 100644 --- a/src/parser/ShowSentences.h +++ b/src/parser/ShowSentences.h @@ -22,7 +22,7 @@ class ShowSentence final : public Sentence { public: explicit ShowSentence(ShowKind sKind) { kind_ = Kind::kShow; - showKind_ = sKind; + showKind_ = std::move(sKind); } std::string toString() const override; diff --git a/src/parser/test/ScannerTest.cpp b/src/parser/test/ScannerTest.cpp index e8a4c5ee48c..19d7cf3ce34 100644 --- a/src/parser/test/ScannerTest.cpp +++ b/src/parser/test/ScannerTest.cpp @@ -12,7 +12,9 @@ #include "parser/GraphParser.hpp" #include "parser/GraphScanner.h" -using namespace ::testing; +using testing::AssertionFailure; +using testing::AssertionSuccess; +using testing::AssertionResult; namespace nebula { @@ -242,11 +244,8 @@ TEST(Scanner, Basic) { CHECK_SEMANTIC_VALUE("\"\\\"Hello\\\"\"", TokenType::STRING, "\"Hello\""), // escape Normal character - // CHECK_SEMANTIC_VALUE("\"Hell\o\"", TokenType::STRING, "Hello"), error CHECK_SEMANTIC_VALUE("\"Hell\\o\"", TokenType::STRING, "Hello"), - //CHECK_SEMANTIC_VALUE("\"Hell\\\o\"", TokenType::STRING, "Hello"), error CHECK_SEMANTIC_VALUE("\"Hell\\\\o\"", TokenType::STRING, "Hell\\o"), - //CHECK_SEMANTIC_VALUE("\"Hell\\\\\o\"", TokenType::STRING, "Hello"), error CHECK_SEMANTIC_VALUE("\"Hell\\\\\\o\"", TokenType::STRING, "Hell\\o"), CHECK_SEMANTIC_VALUE("\"\\110ello\"", TokenType::STRING, "Hello"), CHECK_SEMANTIC_VALUE("\"\110ello\"", TokenType::STRING, "Hello"),