Skip to content
Snippets Groups Projects
Unverified Commit 32618fc1 authored by CPWstatic's avatar CPWstatic Committed by GitHub
Browse files

Add contains. (#178)

* Add contains.

* Update test.

* Update.
parent b50f9d21
Branches
No related tags found
No related merge requests found
...@@ -136,6 +136,7 @@ static constexpr size_t MAX_ABS_INTEGER = 9223372036854775808ULL; ...@@ -136,6 +136,7 @@ static constexpr size_t MAX_ABS_INTEGER = 9223372036854775808ULL;
%token KW_GOD KW_ADMIN KW_DBA KW_GUEST KW_GRANT KW_REVOKE KW_ON %token KW_GOD KW_ADMIN KW_DBA KW_GUEST KW_GRANT KW_REVOKE KW_ON
%token KW_OUT KW_BOTH KW_SUBGRAPH %token KW_OUT KW_BOTH KW_SUBGRAPH
%token KW_EXPLAIN KW_PROFILE KW_FORMAT %token KW_EXPLAIN KW_PROFILE KW_FORMAT
%token KW_CONTAINS
/* symbols */ /* symbols */
%token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA %token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA
...@@ -325,6 +326,7 @@ unreserved_keyword ...@@ -325,6 +326,7 @@ unreserved_keyword
| KW_ALL { $$ = new std::string("all"); } | KW_ALL { $$ = new std::string("all"); }
| KW_SHORTEST { $$ = new std::string("shortest"); } | KW_SHORTEST { $$ = new std::string("shortest"); }
| KW_COUNT_DISTINCT { $$ = new std::string("count_distinct"); } | KW_COUNT_DISTINCT { $$ = new std::string("count_distinct"); }
| KW_CONTAINS { $$ = new std::string("contains"); }
; ;
agg_function agg_function
...@@ -559,6 +561,9 @@ relational_expression ...@@ -559,6 +561,9 @@ relational_expression
| relational_expression GE additive_expression { | relational_expression GE additive_expression {
$$ = new RelationalExpression(Expression::Kind::kRelGE, $1, $3); $$ = new RelationalExpression(Expression::Kind::kRelGE, $1, $3);
} }
| relational_expression KW_CONTAINS additive_expression {
$$ = new RelationalExpression(Expression::Kind::kContains, $1, $3);
}
; ;
equality_expression equality_expression
......
...@@ -167,6 +167,7 @@ DBA ([Dd][Bb][Aa]) ...@@ -167,6 +167,7 @@ DBA ([Dd][Bb][Aa])
OUT ([Oo][Uu][Tt]) OUT ([Oo][Uu][Tt])
BOTH ([Bb][Oo][Tt][Hh]) BOTH ([Bb][Oo][Tt][Hh])
SUBGRAPH ([Ss][Uu][Bb][Gg][Rr][Aa][Pp][Hh]) SUBGRAPH ([Ss][Uu][Bb][Gg][Rr][Aa][Pp][Hh])
CONTAINS ([Cc][Oo][Nn][Tt][Aa][Ii][Nn][Ss])
LABEL ([a-zA-Z][_a-zA-Z0-9]*) LABEL ([a-zA-Z][_a-zA-Z0-9]*)
DEC ([0-9]) DEC ([0-9])
...@@ -335,6 +336,7 @@ FORMAT ([Ff][Oo][Rr][Mm][Aa][Tt]) ...@@ -335,6 +336,7 @@ FORMAT ([Ff][Oo][Rr][Mm][Aa][Tt])
{OUT} { return TokenType::KW_OUT; } {OUT} { return TokenType::KW_OUT; }
{BOTH} { return TokenType::KW_BOTH; } {BOTH} { return TokenType::KW_BOTH; }
{SUBGRAPH} { return TokenType::KW_SUBGRAPH; } {SUBGRAPH} { return TokenType::KW_SUBGRAPH; }
{CONTAINS} { return TokenType::KW_CONTAINS; }
{TRUE} { yylval->boolval = true; return TokenType::BOOL; } {TRUE} { yylval->boolval = true; return TokenType::BOOL; }
......
...@@ -65,6 +65,7 @@ public: ...@@ -65,6 +65,7 @@ public:
case Expression::Kind::kRelGE: case Expression::Kind::kRelGE:
case Expression::Kind::kRelIn: case Expression::Kind::kRelIn:
case Expression::Kind::kRelNotIn: case Expression::Kind::kRelNotIn:
case Expression::Kind::kContains:
case Expression::Kind::kLogicalAnd: case Expression::Kind::kLogicalAnd:
case Expression::Kind::kLogicalOr: case Expression::Kind::kLogicalOr:
case Expression::Kind::kLogicalXor: { case Expression::Kind::kLogicalXor: {
...@@ -271,6 +272,7 @@ public: ...@@ -271,6 +272,7 @@ public:
case Expression::Kind::kRelGE: case Expression::Kind::kRelGE:
case Expression::Kind::kRelIn: case Expression::Kind::kRelIn:
case Expression::Kind::kRelNotIn: case Expression::Kind::kRelNotIn:
case Expression::Kind::kContains:
case Expression::Kind::kLogicalAnd: case Expression::Kind::kLogicalAnd:
case Expression::Kind::kLogicalOr: case Expression::Kind::kLogicalOr:
case Expression::Kind::kLogicalXor: { case Expression::Kind::kLogicalXor: {
......
...@@ -770,6 +770,7 @@ void GoValidator::extractPropExprs(const Expression* expr) { ...@@ -770,6 +770,7 @@ void GoValidator::extractPropExprs(const Expression* expr) {
case Expression::Kind::kRelLE: case Expression::Kind::kRelLE:
case Expression::Kind::kRelGT: case Expression::Kind::kRelGT:
case Expression::Kind::kRelGE: case Expression::Kind::kRelGE:
case Expression::Kind::kContains:
case Expression::Kind::kLogicalAnd: case Expression::Kind::kLogicalAnd:
case Expression::Kind::kLogicalOr: case Expression::Kind::kLogicalOr:
case Expression::Kind::kLogicalXor: { case Expression::Kind::kLogicalXor: {
...@@ -876,6 +877,7 @@ std::unique_ptr<Expression> GoValidator::rewriteToInputProp(Expression* expr) { ...@@ -876,6 +877,7 @@ std::unique_ptr<Expression> GoValidator::rewriteToInputProp(Expression* expr) {
case Expression::Kind::kRelLE: case Expression::Kind::kRelLE:
case Expression::Kind::kRelGT: case Expression::Kind::kRelGT:
case Expression::Kind::kRelGE: case Expression::Kind::kRelGE:
case Expression::Kind::kContains:
case Expression::Kind::kLogicalAnd: case Expression::Kind::kLogicalAnd:
case Expression::Kind::kLogicalOr: case Expression::Kind::kLogicalOr:
case Expression::Kind::kLogicalXor: { case Expression::Kind::kLogicalXor: {
......
...@@ -645,6 +645,7 @@ std::unique_ptr<Expression> UpdateValidator::rewriteSymExpr(Expression* expr, ...@@ -645,6 +645,7 @@ std::unique_ptr<Expression> UpdateValidator::rewriteSymExpr(Expression* expr,
case Expression::Kind::kRelGE: case Expression::Kind::kRelGE:
case Expression::Kind::kRelIn: case Expression::Kind::kRelIn:
case Expression::Kind::kRelNotIn: case Expression::Kind::kRelNotIn:
case Expression::Kind::kContains:
case Expression::Kind::kLogicalAnd: case Expression::Kind::kLogicalAnd:
case Expression::Kind::kLogicalOr: case Expression::Kind::kLogicalOr:
case Expression::Kind::kLogicalXor: { case Expression::Kind::kLogicalXor: {
......
...@@ -302,7 +302,11 @@ StatusOr<Value::Type> Validator::deduceExprType(const Expression* expr) const { ...@@ -302,7 +302,11 @@ StatusOr<Value::Type> Validator::deduceExprType(const Expression* expr) const {
case Expression::Kind::kRelLT: case Expression::Kind::kRelLT:
case Expression::Kind::kRelLE: case Expression::Kind::kRelLE:
case Expression::Kind::kRelGT: case Expression::Kind::kRelGT:
case Expression::Kind::kRelGE: { case Expression::Kind::kRelGE:
case Expression::Kind::kContains: {
auto biExpr = static_cast<const BinaryExpression*>(expr);
NG_RETURN_IF_ERROR(deduceExprType(biExpr->left()));
NG_RETURN_IF_ERROR(deduceExprType(biExpr->right()));
// TODO: Should deduce. // TODO: Should deduce.
return Value::Type::BOOL; return Value::Type::BOOL;
} }
...@@ -548,6 +552,7 @@ Status Validator::deduceProps(const Expression* expr) { ...@@ -548,6 +552,7 @@ Status Validator::deduceProps(const Expression* expr) {
case Expression::Kind::kRelLE: case Expression::Kind::kRelLE:
case Expression::Kind::kRelGT: case Expression::Kind::kRelGT:
case Expression::Kind::kRelGE: case Expression::Kind::kRelGE:
case Expression::Kind::kContains:
case Expression::Kind::kLogicalAnd: case Expression::Kind::kLogicalAnd:
case Expression::Kind::kLogicalOr: case Expression::Kind::kLogicalOr:
case Expression::Kind::kLogicalXor: { case Expression::Kind::kLogicalXor: {
...@@ -664,6 +669,7 @@ bool Validator::evaluableExpr(const Expression* expr) const { ...@@ -664,6 +669,7 @@ bool Validator::evaluableExpr(const Expression* expr) const {
case Expression::Kind::kRelGE: case Expression::Kind::kRelGE:
case Expression::Kind::kRelIn: case Expression::Kind::kRelIn:
case Expression::Kind::kRelNotIn: case Expression::Kind::kRelNotIn:
case Expression::Kind::kContains:
case Expression::Kind::kLogicalAnd: case Expression::Kind::kLogicalAnd:
case Expression::Kind::kLogicalOr: case Expression::Kind::kLogicalOr:
case Expression::Kind::kLogicalXor: { case Expression::Kind::kLogicalXor: {
......
...@@ -391,6 +391,36 @@ class TestGoQuery(NebulaTestSuite): ...@@ -391,6 +391,36 @@ class TestGoQuery(NebulaTestSuite):
} }
self.check_out_of_order_result(resp, expected_data["rows"]) self.check_out_of_order_result(resp, expected_data["rows"])
@pytest.mark.skip(reason = 'return diffrent numbers when edge type wanted.')
def test_edge_type(self):
stmt = '''GO FROM "Russell Westbrook" OVER serve, like \
YIELD serve.start_year, like.likeness, serve._type, like._type'''
resp = self.execute_query(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names" : [],
"rows" : [
[2008, T_NULL, 6, T_NULL],
[T_NULL, 90, T_NULL, 5],
[T_NULL, 90, T_NULL, 5]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = '''GO FROM "Russell Westbrook" OVER serve, like REVERSELY \
YIELD serve._dst, like._dst, serve._type, like._type'''
resp = self.execute_query(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names" : [],
"rows" : [
[T_NULL, "James Harden", T_NULL, -5],
[T_NULL, "Dejounte Murray", T_NULL, -5],
[T_NULL, "Paul George", T_NULL, -5],
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
def test_multi_edges(self): def test_multi_edges(self):
stmt = '''GO FROM "Russell Westbrook" OVER serve, like \ stmt = '''GO FROM "Russell Westbrook" OVER serve, like \
YIELD serve.start_year, like.likeness''' YIELD serve.start_year, like.likeness'''
...@@ -423,6 +453,7 @@ class TestGoQuery(NebulaTestSuite): ...@@ -423,6 +453,7 @@ class TestGoQuery(NebulaTestSuite):
] ]
} }
self.check_out_of_order_result(resp, expected_data["rows"]) self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "GO FROM 'Russell Westbrook' OVER serve, like" stmt = "GO FROM 'Russell Westbrook' OVER serve, like"
resp = self.execute_query(stmt) resp = self.execute_query(stmt)
self.check_resp_succeeded(resp) self.check_resp_succeeded(resp)
...@@ -1218,8 +1249,8 @@ class TestGoQuery(NebulaTestSuite): ...@@ -1218,8 +1249,8 @@ class TestGoQuery(NebulaTestSuite):
resp = self.execute_query(stmt) resp = self.execute_query(stmt)
self.check_resp_failed(resp) self.check_resp_failed(resp)
@pytest.mark.skip(reason = 'not implement')
def test_contains(self): def test_contains(self):
""" the name_label is not a string any more, will be deprecated such a way of writing.
stmt = '''GO FROM 'Boris Diaw' OVER serve WHERE $$.team.name CONTAINS Haw\ stmt = '''GO FROM 'Boris Diaw' OVER serve WHERE $$.team.name CONTAINS Haw\
YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name''' YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name'''
resp = self.execute_query(stmt) resp = self.execute_query(stmt)
...@@ -1232,6 +1263,22 @@ class TestGoQuery(NebulaTestSuite): ...@@ -1232,6 +1263,22 @@ class TestGoQuery(NebulaTestSuite):
} }
self.check_column_names(resp, expected_data["column_names"]) self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"]) self.check_out_of_order_result(resp, expected_data["rows"])
"""
stmt = '''GO FROM 'Boris Diaw' OVER serve WHERE $$.team.name CONTAINS \"Haw\"\
YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name'''
resp = self.execute_query(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names" : ["$^.player.name", "serve.start_year", "serve.end_year", "$$.team.name"],
"rows" : [
["Boris Diaw", 2003, 2005, "Hawks"]
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = '''GO FROM 'Boris Diaw' OVER serve WHERE (string)serve.start_year CONTAINS "05" \ stmt = '''GO FROM 'Boris Diaw' OVER serve WHERE (string)serve.start_year CONTAINS "05" \
YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name''' YIELD $^.player.name, serve.start_year, serve.end_year, $$.team.name'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment