Skip to content

Commit

Permalink
Enhancement/set expression depth by flag (#3722)
Browse files Browse the repository at this point in the history
* Set expression depth limit by flag.

* Format.

Co-authored-by: Yichen Wang <[email protected]>
  • Loading branch information
Shylock-Hg and Aiee authored Jan 18, 2022
1 parent 3c0e4d3 commit 33dea60
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/graph/util/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "graph/context/QueryExpressionContext.h"
#include "graph/visitor/FoldConstantExprVisitor.h"

DEFINE_int32(max_expression_depth, 512, "Max depth of expression tree.");

namespace nebula {
namespace graph {

Expand Down Expand Up @@ -1221,7 +1223,7 @@ bool ExpressionUtils::checkExprDepth(const Expression *expr) {
size -= 1;
}
depth += 1;
if (depth > ExpressionUtils::kMaxDepth) {
if (depth > FLAGS_max_expression_depth) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/graph/util/ExpressionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "graph/visitor/FindVisitor.h"
#include "graph/visitor/RewriteVisitor.h"

DECLARE_int32(max_expression_depth);

namespace nebula {
class ObjectPool;
namespace graph {
Expand Down Expand Up @@ -166,8 +168,6 @@ class ExpressionUtils {
static bool isGeoIndexAcceleratedPredicate(const Expression* expr);

static bool checkExprDepth(const Expression* expr);

static constexpr int32_t kMaxDepth = 512;
};

} // namespace graph
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ expression
if(!graph::ExpressionUtils::checkExprDepth($1)){
// delete $1;
std::ostringstream errStr;
errStr << "The above expression's depth exceeds the maximum depth:" << graph::ExpressionUtils::kMaxDepth;
errStr << "The above expression's depth exceeds the maximum depth:" << FLAGS_max_expression_depth;
throw nebula::GraphParser::syntax_error(@1, errStr.str());
}
$$ = $1;
Expand Down
2 changes: 2 additions & 0 deletions tests/common/nebula_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def _make_params(self, **kwargs):
# Login retry
self.graphd_param['failed_login_attempts'] = '5'
self.graphd_param['password_lock_time_in_secs'] = '10'
# expression depth limit
self.graphd_param['max_expression_depth'] = '128'

self.storaged_param = copy.copy(_params)
self.storaged_param['local_config'] = 'false'
Expand Down
22 changes: 3 additions & 19 deletions tests/tck/features/expression/Depth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,16 @@ Feature: Check Expression Depth
Scenario: yield exceeds expression
When executing query:
"""
YIELD 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 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 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 AS result
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS result
"""
Then the result should be, in any order:
| result |
| 488 |
| 128 |
When executing query:
"""
YIELD 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
Expand Down

0 comments on commit 33dea60

Please sign in to comment.