-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
SequentialPlanner.cpp
63 lines (58 loc) · 1.97 KB
/
SequentialPlanner.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
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/
#include "graph/planner/SequentialPlanner.h"
#include "graph/planner/plan/Logic.h"
#include "graph/planner/plan/Query.h"
#include "graph/validator/SequentialValidator.h"
#include "parser/Sentence.h"
namespace nebula {
namespace graph {
bool SequentialPlanner::match(AstContext* astCtx) {
return astCtx->sentence->kind() == Sentence::Kind::kSequential;
}
StatusOr<SubPlan> SequentialPlanner::transform(AstContext* astCtx) {
SubPlan subPlan;
auto* seqCtx = static_cast<SequentialAstContext*>(astCtx);
auto* qctx = seqCtx->qctx;
const auto& validators = seqCtx->validators;
subPlan.root = validators.back()->root();
ifBuildDataCollect(subPlan, qctx);
for (auto iter = validators.begin(); iter < validators.end() - 1; ++iter) {
NG_RETURN_IF_ERROR((iter + 1)->get()->appendPlan(iter->get()->root()));
}
if (validators.front()->tail()->isSingleInput()) {
subPlan.tail = seqCtx->startNode;
NG_RETURN_IF_ERROR(validators.front()->appendPlan(subPlan.tail));
} else {
subPlan.tail = validators.front()->tail();
}
VLOG(1) << subPlan;
return subPlan;
}
void SequentialPlanner::ifBuildDataCollect(SubPlan& subPlan, QueryContext* qctx) {
switch (subPlan.root->kind()) {
case PlanNode::Kind::kSort:
case PlanNode::Kind::kLimit:
case PlanNode::Kind::kSample:
case PlanNode::Kind::kDedup:
case PlanNode::Kind::kUnion:
case PlanNode::Kind::kUnionAllVersionVar:
case PlanNode::Kind::kIntersect:
case PlanNode::Kind::kCartesianProduct:
case PlanNode::Kind::kMinus:
case PlanNode::Kind::kFilter: {
auto* dc = DataCollect::make(qctx, DataCollect::DCKind::kRowBasedMove);
dc->addDep(subPlan.root);
dc->setInputVars({subPlan.root->outputVar()});
dc->setColNames(subPlan.root->colNames());
subPlan.root = dc;
break;
}
default:
break;
}
}
} // namespace graph
} // namespace nebula