Skip to content

Commit

Permalink
Implement show hosts (vesoft-inc#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayyt authored and dutor committed Jan 16, 2019
1 parent 52d4f97 commit 93e041c
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_library(
DescribeEdgeExecutor.cpp
InsertVertexExecutor.cpp
InsertEdgeExecutor.cpp
ShowExecutor.cpp
mock/PropertiesSchema.cpp
mock/EdgeSchema.cpp
mock/TagSchema.cpp
Expand Down
5 changes: 5 additions & 0 deletions src/graph/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,6 +21,7 @@
#include "graph/DescribeEdgeExecutor.h"
#include "graph/InsertVertexExecutor.h"
#include "graph/InsertEdgeExecutor.h"
#include "graph/ShowExecutor.h"

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -61,6 +63,9 @@ std::unique_ptr<Executor> Executor::makeExecutor(Sentence *sentence) {
case Sentence::Kind::kInsertEdge:
executor = std::make_unique<InsertEdgeExecutor>(sentence, ectx());
break;
case Sentence::Kind::kShow:
executor = std::make_unique<ShowExecutor>(sentence, ectx());
break;
case Sentence::Kind::kUnknown:
LOG(FATAL) << "Sentence kind unknown";
break;
Expand Down
47 changes: 47 additions & 0 deletions src/graph/ShowExecutor.cpp
Original file line number Diff line number Diff line change
@@ -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<ShowSentence*>(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 (ShowKind::kShowHosts):
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
39 changes: 39 additions & 0 deletions src/graph/ShowExecutor.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_SHOWEXECUTOR_H_
#define GRAPH_SHOWEXECUTOR_H_

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

namespace nebula {
namespace graph {

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

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

Status MUST_USE_RESULT prepare() override;

void execute() override;

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

private:
ShowSentence *sentence_{nullptr};
std::unique_ptr<cpp2::ExecutionResponse> resp_;
};


} // namespace graph
} // namespace nebula

#endif // GRAPH_SHOWEXECUTOR_H_
1 change: 1 addition & 0 deletions src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_library(
MaintainSentences.cpp
MutateSentences.cpp
TraverseSentences.cpp
ShowSentences.cpp
)

add_dependencies(parser_obj base_obj)
Expand Down
1 change: 1 addition & 0 deletions src/parser/Sentence.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Sentence {
kDescribeEdge,
kInsertVertex,
kInsertEdge,
kShow,
};

Kind kind() const {
Expand Down
1 change: 1 addition & 0 deletions src/parser/SequentialSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "parser/MaintainSentences.h"
#include "parser/TraverseSentences.h"
#include "parser/MutateSentences.h"
#include "parser/ShowSentences.h"

namespace nebula {

Expand Down
26 changes: 26 additions & 0 deletions src/parser/ShowSentences.cpp
Original file line number Diff line number Diff line change
@@ -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)
*/

#include "base/Base.h"
#include "parser/ShowSentences.h"

namespace nebula {

std::string ShowSentence::toString() const {
std::string buf;
switch (showKind_) {
case ShowKind::kShowHosts:
buf = "SHOW HOSTS";
break;
case ShowKind::kUnknown:
default:
LOG(FATAL) << "Show Sentence kind illegal: " << showKind_;
break;
}
return buf;
}

} // namespace nebula
44 changes: 44 additions & 0 deletions src/parser/ShowSentences.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* 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 {

enum class ShowKind : uint32_t {
kUnknown,
kShowHosts,
};


class ShowSentence final : public Sentence {
public:
explicit ShowSentence(ShowKind sKind) {
kind_ = Kind::kShow;
showKind_ = std::move(sKind);
}

std::string toString() const override;

ShowKind showKind() const {
return showKind_;
}

private:
ShowKind showKind_{ShowKind::kUnknown};
};

inline std::ostream& operator<<(std::ostream &os, ShowKind kind) {
return os << static_cast<uint32_t>(kind);
}

} // namespace nebula

#endif // PARSER_SHOWSENTENCES_H_
11 changes: 10 additions & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
Expand Down Expand Up @@ -102,6 +102,7 @@ class GraphScanner;
%type <sentence> traverse_sentence set_sentence piped_sentence assignment_sentence
%type <sentence> maintainance_sentence insert_vertex_sentence insert_edge_sentence
%type <sentence> mutate_sentence update_vertex_sentence update_edge_sentence
%type <sentence> show_sentence
%type <sentence> sentence
%type <sentences> sentences

Expand Down Expand Up @@ -663,6 +664,13 @@ update_edge_sentence
}
;

show_sentence
: KW_SHOW KW_HOSTS {
auto sentence = new ShowSentence(ShowKind::kShowHosts);
$$ = sentence;
}
;

mutate_sentence
: insert_vertex_sentence {}
| insert_edge_sentence {}
Expand All @@ -677,6 +685,7 @@ maintainance_sentence
| alter_edge_sentence {}
| describe_tag_sentence {}
| describe_edge_sentence {}
| show_sentence {}
;

sentence
Expand Down
5 changes: 5 additions & 0 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ 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])
Expand Down Expand Up @@ -108,6 +111,8 @@ OCT ([0-7])
{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; }
Expand Down
23 changes: 22 additions & 1 deletion src/parser/test/ScannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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),
Expand Down Expand Up @@ -233,11 +239,26 @@ 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"),
CHECK_SEMANTIC_VALUE("\"Hell\\\\o\"", TokenType::STRING, "Hell\\o"),
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
Expand Down

0 comments on commit 93e041c

Please sign in to comment.