forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateTagIndexExecutor.cpp
62 lines (50 loc) · 1.76 KB
/
CreateTagIndexExecutor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* 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