6
6
7
7
#include " graph/validator/OrderByValidator.h"
8
8
9
- #include " common/expression/LabelExpression.h"
10
9
#include " graph/planner/plan/Query.h"
11
10
#include " parser/TraverseSentences.h"
12
11
13
12
namespace nebula {
14
13
namespace graph {
15
14
Status OrderByValidator::validateImpl () {
16
15
auto sentence = static_cast <OrderBySentence *>(sentence_);
17
- outputs_ = inputCols ();
18
16
auto &factors = sentence->factors ();
19
- auto *pool = qctx_->objPool ();
20
17
for (auto &factor : factors) {
21
- if (factor->expr ()->kind () == Expression::Kind::kLabel ) {
22
- auto *label = static_cast <const LabelExpression *>(factor->expr ());
23
- auto *expr = InputPropertyExpression::make (pool, label->name ());
24
- factor->setExpr (expr);
25
- }
26
- if (factor->expr ()->kind () != Expression::Kind::kInputProperty ) {
18
+ if (factor->expr ()->kind () == Expression::Kind::kInputProperty ) {
19
+ auto expr = static_cast <InputPropertyExpression *>(factor->expr ());
20
+ NG_RETURN_IF_ERROR (deduceExprType (expr));
21
+ NG_RETURN_IF_ERROR (deduceProps (expr, exprProps_));
22
+ const auto &cols = inputCols ();
23
+ auto &name = expr->prop ();
24
+ auto eq = [&](const ColDef &col) { return col.name == name; };
25
+ auto iter = std::find_if (cols.cbegin (), cols.cend (), eq);
26
+ size_t colIdx = std::distance (cols.cbegin (), iter);
27
+ colOrderTypes_.emplace_back (std::make_pair (colIdx, factor->orderType ()));
28
+ } else if (factor->expr ()->kind () == Expression::Kind::kVarProperty ) {
29
+ auto expr = static_cast <VariablePropertyExpression *>(factor->expr ());
30
+ NG_RETURN_IF_ERROR (deduceExprType (expr));
31
+ NG_RETURN_IF_ERROR (deduceProps (expr, exprProps_));
32
+ const auto &cols = vctx_->getVar (expr->sym ());
33
+ auto &name = expr->prop ();
34
+ auto eq = [&](const ColDef &col) { return col.name == name; };
35
+ auto iter = std::find_if (cols.cbegin (), cols.cend (), eq);
36
+ size_t colIdx = std::distance (cols.cbegin (), iter);
37
+ colOrderTypes_.emplace_back (std::make_pair (colIdx, factor->orderType ()));
38
+ } else {
27
39
return Status::SemanticError (" Order by with invalid expression `%s'" ,
28
40
factor->expr ()->toString ().c_str ());
29
41
}
30
- auto expr = static_cast <InputPropertyExpression *>(factor->expr ());
31
- NG_RETURN_IF_ERROR (deduceExprType (expr));
32
- auto &name = expr->prop ();
33
- auto eq = [&](const ColDef &col) { return col.name == name; };
34
- auto iter = std::find_if (outputs_.cbegin (), outputs_.cend (), eq);
35
- size_t colIdx = std::distance (outputs_.cbegin (), iter);
36
- colOrderTypes_.emplace_back (std::make_pair (colIdx, factor->orderType ()));
42
+ }
43
+
44
+ if (!exprProps_.inputProps ().empty () && !exprProps_.varProps ().empty ()) {
45
+ return Status::SemanticError (" Not support both input and variable." );
46
+ } else if (!exprProps_.inputProps ().empty ()) {
47
+ outputs_ = inputCols ();
48
+ } else if (!exprProps_.varProps ().empty ()) {
49
+ if (!userDefinedVarNameList_.empty ()) {
50
+ if (userDefinedVarNameList_.size () != 1 ) {
51
+ return Status::SemanticError (" Multiple user defined vars are not supported yet." );
52
+ }
53
+ userDefinedVarName_ = *userDefinedVarNameList_.begin ();
54
+ outputs_ = vctx_->getVar (userDefinedVarName_);
55
+ }
37
56
}
38
57
39
58
return Status::OK ();
@@ -47,6 +66,10 @@ Status OrderByValidator::toPlan() {
47
66
colNames.emplace_back (col.name );
48
67
}
49
68
sortNode->setColNames (std::move (colNames));
69
+ if (!userDefinedVarName_.empty ()) {
70
+ sortNode->setInputVar (userDefinedVarName_);
71
+ }
72
+
50
73
root_ = sortNode;
51
74
tail_ = root_;
52
75
return Status::OK ();
0 commit comments