From 128d4a8335a889164d117f80e9f2f56c515ee600 Mon Sep 17 00:00:00 2001
From: laura-ding <48548375+laura-ding@users.noreply.github.com>
Date: Mon, 19 Aug 2019 11:42:23 +0800
Subject: [PATCH] Return error msg for find and match sentence (#794)

---
 src/executor/CMakeLists.txt       |  2 ++
 src/executor/Executor.cpp         |  8 +++++++
 src/executor/FindExecutor.cpp     | 24 +++++++++++++++++++
 src/executor/FindExecutor.h       | 40 +++++++++++++++++++++++++++++++
 src/executor/MatchExecutor.cpp    | 24 +++++++++++++++++++
 src/executor/MatchExecutor.h      | 40 +++++++++++++++++++++++++++++++
 src/executor/TraverseExecutor.cpp |  8 +++++++
 src/executor/test/DataTest.cpp    | 19 ++++++++++++++-
 8 files changed, 164 insertions(+), 1 deletion(-)
 create mode 100644 src/executor/FindExecutor.cpp
 create mode 100644 src/executor/FindExecutor.h
 create mode 100644 src/executor/MatchExecutor.cpp
 create mode 100644 src/executor/MatchExecutor.h

diff --git a/src/executor/CMakeLists.txt b/src/executor/CMakeLists.txt
index 6304ef9d..7df169c3 100644
--- a/src/executor/CMakeLists.txt
+++ b/src/executor/CMakeLists.txt
@@ -42,6 +42,8 @@ add_library(
     FetchEdgesExecutor.cpp
     FetchExecutor.cpp
     SetExecutor.cpp
+    FindExecutor.cpp
+    MatchExecutor.cpp
 )
 add_dependencies(
     graph_obj
diff --git a/src/executor/Executor.cpp b/src/executor/Executor.cpp
index a30006f2..683d0633 100644
--- a/src/executor/Executor.cpp
+++ b/src/executor/Executor.cpp
@@ -39,6 +39,8 @@
 #include "graph/FetchEdgesExecutor.h"
 #include "graph/ConfigExecutor.h"
 #include "graph/SetExecutor.h"
+#include "graph/FindExecutor.h"
+#include "graph/MatchExecutor.h"
 
 namespace nebula {
 namespace graph {
@@ -131,6 +133,12 @@ std::unique_ptr<Executor> Executor::makeExecutor(Sentence *sentence) {
         case Sentence::Kind::kSet:
             executor = std::make_unique<SetExecutor>(sentence, ectx());
             break;
+        case Sentence::Kind::kMatch:
+            executor = std::make_unique<MatchExecutor>(sentence, ectx());
+            break;
+        case Sentence::Kind::kFind:
+            executor = std::make_unique<FindExecutor>(sentence, ectx());
+            break;
         case Sentence::Kind::kUnknown:
             LOG(FATAL) << "Sentence kind unknown";
             break;
diff --git a/src/executor/FindExecutor.cpp b/src/executor/FindExecutor.cpp
new file mode 100644
index 00000000..ea4cc865
--- /dev/null
+++ b/src/executor/FindExecutor.cpp
@@ -0,0 +1,24 @@
+/* Copyright (c) 2019 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 "base/Base.h"
+#include "graph/FindExecutor.h"
+
+namespace nebula {
+namespace graph {
+
+FindExecutor::FindExecutor(Sentence *sentence, ExecutionContext *ectx)
+    : TraverseExecutor(ectx) {
+    sentence_ = static_cast<FindSentence*>(sentence);
+}
+
+
+Status FindExecutor::prepare() {
+    return Status::Error("Does not support");
+}
+
+}   // namespace graph
+}   // namespace nebula
diff --git a/src/executor/FindExecutor.h b/src/executor/FindExecutor.h
new file mode 100644
index 00000000..4064b9b6
--- /dev/null
+++ b/src/executor/FindExecutor.h
@@ -0,0 +1,40 @@
+/* Copyright (c) 2019 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_FINDEXECUTOR_H_
+#define GRAPH_FINDEXECUTOR_H_
+
+#include "base/Base.h"
+#include "graph/TraverseExecutor.h"
+
+namespace nebula {
+namespace graph {
+
+class FindExecutor final : public TraverseExecutor {
+public:
+    FindExecutor(Sentence *sentence, ExecutionContext *ectx);
+
+    const char* name() const override {
+        return "FindExecutor";
+    }
+
+    Status MUST_USE_RESULT prepare() override;
+
+    void feedResult(std::unique_ptr<InterimResult> result) override {
+        UNUSED(result);
+    }
+
+    void execute() override {}
+
+private:
+    FindSentence                                *sentence_{nullptr};
+};
+
+}   // namespace graph
+}   // namespace nebula
+
+
+#endif  // GRAPH_FINDEXECUTOR_H_
diff --git a/src/executor/MatchExecutor.cpp b/src/executor/MatchExecutor.cpp
new file mode 100644
index 00000000..e058f4fb
--- /dev/null
+++ b/src/executor/MatchExecutor.cpp
@@ -0,0 +1,24 @@
+/* Copyright (c) 2019 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 "base/Base.h"
+#include "graph/MatchExecutor.h"
+
+namespace nebula {
+namespace graph {
+
+MatchExecutor::MatchExecutor(Sentence *sentence, ExecutionContext *ectx)
+    : TraverseExecutor(ectx) {
+    sentence_ = static_cast<MatchSentence*>(sentence);
+}
+
+
+Status MatchExecutor::prepare() {
+    return Status::Error("Does not support");
+}
+
+}   // namespace graph
+}   // namespace nebula
diff --git a/src/executor/MatchExecutor.h b/src/executor/MatchExecutor.h
new file mode 100644
index 00000000..53d88964
--- /dev/null
+++ b/src/executor/MatchExecutor.h
@@ -0,0 +1,40 @@
+/* Copyright (c) 2019 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_MATCHEXECUTOR_H_
+#define GRAPH_MATCHEXECUTOR_H_
+
+#include "base/Base.h"
+#include "graph/TraverseExecutor.h"
+
+namespace nebula {
+namespace graph {
+
+class MatchExecutor final : public TraverseExecutor {
+public:
+    MatchExecutor(Sentence *sentence, ExecutionContext *ectx);
+
+    const char* name() const override {
+        return "UseExecutor";
+    }
+
+    Status MUST_USE_RESULT prepare() override;
+
+    void feedResult(std::unique_ptr<InterimResult> result) override {
+        UNUSED(result);
+    }
+
+    void execute() override {}
+
+private:
+    MatchSentence                                *sentence_{nullptr};
+};
+
+}   // namespace graph
+}   // namespace nebula
+
+
+#endif  // GRAPH_MATCHEXECUTOR_H_
diff --git a/src/executor/TraverseExecutor.cpp b/src/executor/TraverseExecutor.cpp
index d9f214f8..7ad71fe2 100644
--- a/src/executor/TraverseExecutor.cpp
+++ b/src/executor/TraverseExecutor.cpp
@@ -15,6 +15,8 @@
 #include "dataman/RowReader.h"
 #include "dataman/RowWriter.h"
 #include "graph/SetExecutor.h"
+#include "graph/FindExecutor.h"
+#include "graph/MatchExecutor.h"
 
 namespace nebula {
 namespace graph {
@@ -48,6 +50,12 @@ TraverseExecutor::makeTraverseExecutor(Sentence *sentence, ExecutionContext *ect
         case Sentence::Kind::kSet:
             executor = std::make_unique<SetExecutor>(sentence, ectx);
             break;
+        case Sentence::Kind::kMatch:
+            executor = std::make_unique<MatchExecutor>(sentence, ectx);
+            break;
+        case Sentence::Kind::kFind:
+            executor = std::make_unique<FindExecutor>(sentence, ectx);
+            break;
         case Sentence::Kind::kUnknown:
             LOG(FATAL) << "Sentence kind unknown";
             break;
diff --git a/src/executor/test/DataTest.cpp b/src/executor/test/DataTest.cpp
index b52c49f1..581a2798 100644
--- a/src/executor/test/DataTest.cpp
+++ b/src/executor/test/DataTest.cpp
@@ -359,6 +359,23 @@ TEST_F(DataTest, InsertVertex) {
     // TODO: Test insert multi tags, and delete one of them then check other existent
 }
 
+TEST_F(DataTest, FindTest) {
+    {
+        cpp2::ExecutionResponse resp;
+        std::string cmd = "FIND name FROM person";
+        auto code = client_->execute(cmd, resp);
+        ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code);
+    }
+}
+
+TEST_F(DataTest, MatchTest) {
+    {
+        cpp2::ExecutionResponse resp;
+        std::string cmd = "MATCH";
+        auto code = client_->execute(cmd, resp);
+        ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code);
+    }
+}
+
 }   // namespace graph
 }   // namespace nebula
-
-- 
GitLab