forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlterEdgeExecutor.cpp
73 lines (56 loc) · 2.02 KB
/
AlterEdgeExecutor.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
62
63
64
65
66
67
68
69
70
71
72
73
/* Copyright (c) 2018 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/AlterEdgeExecutor.h"
#include "graph/SchemaHelper.h"
namespace nebula {
namespace graph {
AlterEdgeExecutor::AlterEdgeExecutor(Sentence *sentence,
ExecutionContext *ectx)
: Executor(ectx, "alter_edge") {
sentence_ = static_cast<AlterEdgeSentence*>(sentence);
}
Status AlterEdgeExecutor::prepare() {
return Status::OK();
}
Status AlterEdgeExecutor::getSchema() {
auto status = checkIfGraphSpaceChosen();
if (!status.ok()) {
return status;
}
const auto& schemaOpts = sentence_->getSchemaOpts();
const auto& schemaProps = sentence_->getSchemaProps();
return SchemaHelper::alterSchema(schemaOpts, schemaProps, options_, schemaProp_);
}
void AlterEdgeExecutor::execute() {
auto status = getSchema();
if (!status.ok()) {
doError(std::move(status));
return;
}
auto *mc = ectx()->getMetaClient();
auto *name = sentence_->name();
auto spaceId = ectx()->rctx()->session()->space();
auto future = mc->alterEdgeSchema(spaceId, *name, std::move(options_), std::move(schemaProp_));
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
if (!resp.ok()) {
doError(Status::Error("Alter edge `%s' failed: %s.",
sentence_->name()->c_str(), resp.status().toString().c_str()));
return;
}
doFinish(Executor::ProcessControl::kNext);
};
auto error = [this] (auto &&e) {
auto msg = folly::stringPrintf("Alter edge `%s' exception: %s.",
sentence_->name()->c_str(), e.what().c_str());
LOG(ERROR) << msg;
doError(Status::Error(std::move(msg)));
};
std::move(future).via(runner).thenValue(cb).thenError(error);
}
} // namespace graph
} // namespace nebula