Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable yield var #3271

Merged
merged 19 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/graph/optimizer/rule/TopNRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "graph/optimizer/rule/TopNRule.h"

#include "graph/optimizer/OptContext.h"
#include "graph/optimizer/OptGroup.h"
#include "graph/planner/plan/PlanNode.h"
Expand Down
10 changes: 10 additions & 0 deletions src/graph/util/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ std::vector<const Expression *> ExpressionUtils::collectAll(
return std::move(visitor).results();
}

bool ExpressionUtils::checkVarExprIfExist(const Expression *expr) {
auto vars = ExpressionUtils::collectAll(expr, {Expression::Kind::kVar});
for (auto *var : vars) {
if (!static_cast<const VariableExpression *>(var)->isInner()) {
return true;
}
}
return false;
}

std::vector<const Expression *> ExpressionUtils::findAllStorage(const Expression *expr) {
return collectAll(expr,
{Expression::Kind::kTagProperty,
Expand Down
2 changes: 2 additions & 0 deletions src/graph/util/ExpressionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ExpressionUtils {
static std::vector<const Expression*> collectAll(
const Expression* self, const std::unordered_set<Expression::Kind>& expected);

static bool checkVarExprIfExist(const Expression* expr);

static std::vector<const Expression*> findAllStorage(const Expression* expr);

static std::vector<const Expression*> findAllInputVariableProp(const Expression* expr);
Expand Down
7 changes: 7 additions & 0 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1448,9 +1448,16 @@ yield_column
delete $3;
}
| expression {
if (graph::ExpressionUtils::checkVarExprIfExist($1)) {
throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited");
}
$$ = new YieldColumn($1);
}
| expression KW_AS name_label {
if (graph::ExpressionUtils::checkVarExprIfExist($1)) {
delete $3;
throw nebula::GraphParser::syntax_error(@1, "Direct output of variable is prohibited");
}
$$ = new YieldColumn($1, *$3);
delete $3;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/tck/features/bugfix/VariableExpression.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2021 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.
czpmango marked this conversation as resolved.
Show resolved Hide resolved
Feature: Variable usage

Background:
Given a graph with space named "nba"

Scenario: disable yield $var
When executing query:
"""
$var = yield 1;$var2 = yield 3;yield $var1 + $var2
"""
Then a SyntaxError should be raised at runtime: Direct output of variable is prohibited near `$var1 + $var2'
When executing query:
"""
$var=go from "Tim Duncan" over like yield like._dst as dst;yield $var
"""
Then a SyntaxError should be raised at runtime: Direct output of variable is prohibited near `$var'
Then drop the used space
When executing query:
"""
$var=go from "Tim Duncan" over like yield like._dst as dst;yield $var[0][0]
"""
Then a SyntaxError should be raised at runtime: Direct output of variable is prohibited near `$var[0][0]'
2 changes: 1 addition & 1 deletion tests/tck/features/go/GroupbyLimit.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Groupby & limit Sentence
"""
GO FROM hash("Marco Belinelli") OVER serve YIELD $$.team.name AS name | GROUP BY $-.start_year YIELD COUNT($var)
"""
Then a SemanticError should be raised at runtime:
Then a SyntaxError should be raised at runtime:

Scenario: Syntax test4
When executing query:
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/go/GroupbyLimit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Groupby & limit Sentence
"""
GO FROM "Marco Belinelli" OVER serve YIELD $$.team.name AS name | GROUP BY $-.start_year YIELD COUNT($var)
"""
Then a SemanticError should be raised at runtime:
Then a SyntaxError should be raised at runtime:

Scenario: Syntax test4
When executing query:
Expand Down