Skip to content

Commit

Permalink
Support Index Operations (vesoft-inc#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaphet authored and dutor committed Jan 6, 2020
1 parent d27325f commit 046c0bf
Show file tree
Hide file tree
Showing 44 changed files with 2,029 additions and 193 deletions.
55 changes: 55 additions & 0 deletions src/graph/BuildEdgeIndexExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* 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 "graph/BuildEdgeIndexExecutor.h"

namespace nebula {
namespace graph {

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

Status BuildEdgeIndexExecutor::prepare() {
return Status::OK();
}

void BuildEdgeIndexExecutor::execute() {
auto status = checkIfGraphSpaceChosen();
if (!status.ok()) {
DCHECK(onError_);
onError_(std::move(status));
return;
}

auto *mc = ectx()->getMetaClient();
auto *name = sentence_->indexName();
auto spaceId = ectx()->rctx()->session()->space();

auto future = mc->buildEdgeIndex(spaceId, *name);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(resp.status());
return;
}

DCHECK(onFinish_);
onFinish_(Executor::ProcessControl::kNext);
};

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

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

} // namespace graph
} // namespace nebula
35 changes: 35 additions & 0 deletions src/graph/BuildEdgeIndexExecutor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* 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_BUILDEDGEINDEXEXECUTOR_H_
#define GRAPH_BUILDEDGEINDEXEXECUTOR_H_

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

namespace nebula {
namespace graph {

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

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

Status MUST_USE_RESULT prepare() override;

void execute() override;

private:
BuildEdgeIndexSentence *sentence_{nullptr};
};

} // namespace graph
} // namespace nebula

#endif // GRAPH_BUILDEDGEINDEXEXECUTOR_H_
55 changes: 55 additions & 0 deletions src/graph/BuildTagIndexExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* 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 "graph/BuildTagIndexExecutor.h"

namespace nebula {
namespace graph {

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

Status BuildTagIndexExecutor::prepare() {
return Status::OK();
}

void BuildTagIndexExecutor::execute() {
auto status = checkIfGraphSpaceChosen();
if (!status.ok()) {
DCHECK(onError_);
onError_(std::move(status));
return;
}

auto *mc = ectx()->getMetaClient();
auto *name = sentence_->indexName();
auto spaceId = ectx()->rctx()->session()->space();

auto future = mc->buildTagIndex(spaceId, *name);
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(resp.status());
return;
}

DCHECK(onFinish_);
onFinish_(Executor::ProcessControl::kNext);
};

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

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

} // namespace graph
} // namespace nebula
36 changes: 36 additions & 0 deletions src/graph/BuildTagIndexExecutor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* 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_BUILDTAGINDEXEXECUTOR_H_
#define GRAPH_BUILDTAGINDEXEXECUTOR_H_

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

namespace nebula {
namespace graph {

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

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

Status MUST_USE_RESULT prepare() override;

void execute() override;

private:
BuildTagIndexSentence *sentence_{nullptr};
};

} // namespace graph
} // namespace nebula

#endif // GRAPH_BUILDTAGINDEXEXECUTOR_H_

12 changes: 10 additions & 2 deletions src/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ nebula_add_library(
GoExecutor.cpp
PipeExecutor.cpp
CreateEdgeExecutor.cpp
CreateTagExecutor.cpp
AlterEdgeExecutor.cpp
DescribeEdgeExecutor.cpp
CreateTagExecutor.cpp
AlterTagExecutor.cpp
DropTagExecutor.cpp
DropEdgeExecutor.cpp
DescribeTagExecutor.cpp
DescribeEdgeExecutor.cpp
InsertVertexExecutor.cpp
UpdateVertexExecutor.cpp
InsertEdgeExecutor.cpp
CreateEdgeIndexExecutor.cpp
DropEdgeIndexExecutor.cpp
DescribeEdgeIndexExecutor.cpp
BuildEdgeIndexExecutor.cpp
CreateTagIndexExecutor.cpp
DropTagIndexExecutor.cpp
DescribeTagIndexExecutor.cpp
BuildTagIndexExecutor.cpp
UpdateEdgeExecutor.cpp
AssignmentExecutor.cpp
InterimResult.cpp
Expand Down
1 change: 0 additions & 1 deletion src/graph/CreateEdgeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Status CreateEdgeExecutor::getSchema() {

const auto& specs = sentence_->columnSpecs();
const auto& schemaProps = sentence_->getSchemaProps();

return SchemaHelper::createSchema(specs, schemaProps, schema_);
}

Expand Down
62 changes: 62 additions & 0 deletions src/graph/CreateEdgeIndexExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* 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 "graph/CreateEdgeIndexExecutor.h"

namespace nebula {
namespace graph {

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

Status CreateEdgeIndexExecutor::prepare() {
return Status::OK();
}

void CreateEdgeIndexExecutor::execute() {
auto status = checkIfGraphSpaceChosen();
if (!status.ok()) {
DCHECK(onError_);
onError_(std::move(status));
return;
}

auto *mc = ectx()->getMetaClient();
const auto *name = sentence_->indexName();
auto *edgeName = sentence_->edgeName();
auto columns = sentence_->names();
auto spaceId = ectx()->rctx()->session()->space();

auto future = mc->createEdgeIndex(spaceId,
*name,
*edgeName,
columns,
sentence_->isIfNotExist());
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(resp.status());
return;
}

DCHECK(onFinish_);
onFinish_(Executor::ProcessControl::kNext);
};

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

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

} // namespace graph
} // namespace nebula

35 changes: 35 additions & 0 deletions src/graph/CreateEdgeIndexExecutor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* 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_CREATEEDGEINDEXEXECUTOR_H
#define GRAPH_CREATEEDGEINDEXEXECUTOR_H

#include "graph/Executor.h"

namespace nebula {
namespace graph {

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

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

Status MUST_USE_RESULT prepare() override;

void execute() override;

private:
CreateEdgeIndexSentence *sentence_{nullptr};
};

} // namespace graph
} // namespace nebula

#endif // GRAPH_CREATEEDGEINDEXEXECUTOR_H

62 changes: 62 additions & 0 deletions src/graph/CreateTagIndexExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* 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 "graph/CreateTagIndexExecutor.h"

namespace nebula {
namespace graph {

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

Status CreateTagIndexExecutor::prepare() {
return Status::OK();
}

void CreateTagIndexExecutor::execute() {
auto status = checkIfGraphSpaceChosen();
if (!status.ok()) {
DCHECK(onError_);
onError_(std::move(status));
return;
}

auto *mc = ectx()->getMetaClient();
auto *name = sentence_->indexName();
auto *tagName = sentence_->tagName();
auto columns = sentence_->names();
auto spaceId = ectx()->rctx()->session()->space();

auto future = mc->createTagIndex(spaceId,
*name,
*tagName,
columns,
sentence_->isIfNotExist());
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
DCHECK(onError_);
onError_(resp.status());
return;
}

DCHECK(onFinish_);
onFinish_(Executor::ProcessControl::kNext);
};

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

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

} // namespace graph
} // namespace nebula

Loading

0 comments on commit 046c0bf

Please sign in to comment.