diff --git a/.gitignore b/.gitignore index a48fe9252491fb374830295132609ad1b8dcd3fe..2212a28ce81ae35a7ecd07685ddbc8460a67293e 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ nebula-python .classpath cmake-build*/ .vscode/ +.cache/ core.* workspace.* diff --git a/src/visitor/DeduceTypeVisitor.cpp b/src/visitor/DeduceTypeVisitor.cpp index dc8ee02bd3637cc56152cd113cd6ed765b71df98..14f87e2830c88de5666d5d88581a02ec036f1369 100644 --- a/src/visitor/DeduceTypeVisitor.cpp +++ b/src/visitor/DeduceTypeVisitor.cpp @@ -245,10 +245,13 @@ void DeduceTypeVisitor::visit(RelationalExpression *expr) { if (expr->kind() == Expression::Kind::kRelIn || expr->kind() == Expression::Kind::kRelNotIn) { auto right = type_; - if (right != Value::Type::LIST && right != Value::Type::SET && right != Value::Type::MAP) { - status_ = Status::SemanticError( - "`%s': Invalid expression for IN operator, expecting List/Set/Map", - expr->toString().c_str()); + if (right != Value::Type::LIST && right != Value::Type::SET && right != Value::Type::MAP && + !isSuperiorType(right)) { + std::stringstream ss; + ss << "`" << expr->right()->toString() + << "', expected List/Set/Map, but was " + << type_; + status_ = Status::SemanticError(ss.str()); return; } } @@ -601,10 +604,10 @@ void DeduceTypeVisitor::visit(CaseExpression *expr) { for (const auto &whenThen : expr->cases()) { whenThen.when->accept(this); if (!ok()) return; - if (!expr->hasCondition() && type_ != Value::Type::BOOL) { - status_ = Status::SemanticError( - "`%s': Invalid expression type, expecting expression of type BOOL", - expr->toString().c_str()); + if (!expr->hasCondition() && type_ != Value::Type::BOOL && !isSuperiorType(type_)) { + std::stringstream ss; + ss << "`" << whenThen.when->toString() << "', expected BOOL, but was " << type_; + status_ = Status::SemanticError(ss.str()); return; } whenThen.then->accept(this); @@ -626,8 +629,8 @@ void DeduceTypeVisitor::visit(PredicateExpression *expr) { } if (type_ != Value::Type::LIST) { std::stringstream ss; - ss << "`" << expr->toString().c_str() - << "': Invalid colletion type, expected type of LIST, but was: " << type_; + ss << "`" << expr->collection()->toString() + << "', expected LIST, but was " << type_; status_ = Status::SemanticError(ss.str()); return; } @@ -660,8 +663,8 @@ void DeduceTypeVisitor::visit(ListComprehensionExpression *expr) { if (type_ != Value::Type::LIST) { std::stringstream ss; - ss << "`" << expr->toString().c_str() - << "': Invalid colletion type, expected type of LIST, but was: " << type_; + ss << "`" << expr->collection()->toString() + << "', expected LIST, but was " << type_; status_ = Status::SemanticError(ss.str()); return; } @@ -684,8 +687,8 @@ void DeduceTypeVisitor::visit(ReduceExpression *expr) { if (type_ != Value::Type::LIST) { std::stringstream ss; - ss << "`" << expr->toString().c_str() - << "': Invalid colletion type, expected type of LIST, but was: " << type_; + ss << "`" << expr->collection()->toString() + << "', expected LIST, but was " << type_; status_ = Status::SemanticError(ss.str()); return; } diff --git a/tests/tck/features/expression/In.feature b/tests/tck/features/expression/In.feature index 3d910de43cb9ce39bac6ef8117bfc0c2f124a0f8..b82b8ea2c5565855be265ff76ef27a0683bc0e14 100644 --- a/tests/tck/features/expression/In.feature +++ b/tests/tck/features/expression/In.feature @@ -132,3 +132,24 @@ Feature: In Expression | 'LaMarcus Aldridge' | 90 | | 'Manu Ginobili' | 95 | | 'Tim Duncan' | 95 | + + Scenario: Using IN list in MATCH + Given a graph with space named "nba" + When executing query: + """ + MATCH (v:player) + WHERE "Parker" IN split(v.name, " ") + RETURN v.name + """ + Then the result should be, in any order: + | v.name | + | "Tony Parker" | + When executing query: + """ + MATCH (v:player) + WHERE "ing" IN [n IN split(v.name, "M") WHERE true] + RETURN v.name + """ + Then the result should be, in any order: + | v.name | + | "Yao Ming" | diff --git a/tests/tck/features/expression/ListComprehension.feature b/tests/tck/features/expression/ListComprehension.feature index ac057b3b56eebd7fae6e42498b371e22c2f0e2c9..2a08998d7ca3467d24c3992899c12d65c3addca0 100644 --- a/tests/tck/features/expression/ListComprehension.feature +++ b/tests/tck/features/expression/ListComprehension.feature @@ -87,7 +87,7 @@ Feature: ListComprehension """ YIELD [n IN 18 WHERE n > 2 | n + 10] AS a """ - Then a SemanticError should be raised at runtime: `[n IN 18 WHERE (n>2) | (n+10)]': Invalid colletion type, expected type of LIST, but was: INT + Then a SemanticError should be raised at runtime: `18', expected LIST, but was INT When executing query: """ YIELD [n IN NULL WHERE n > 2 | n + 10] AS a diff --git a/tests/tck/features/expression/Predicate.feature b/tests/tck/features/expression/Predicate.feature index 79e7d5858f0160b07fb2a3977a420b6c99e2406c..5c07ab98d1cc6e2633e49fe33bd4cf0025b3ca08 100644 --- a/tests/tck/features/expression/Predicate.feature +++ b/tests/tck/features/expression/Predicate.feature @@ -88,7 +88,7 @@ Feature: Predicate """ YIELD single(n IN "Tom" WHERE n == 3) AS r """ - Then a SemanticError should be raised at runtime: `single(n IN "Tom" WHERE (n==3))': Invalid colletion type, expected type of LIST, but was: STRING + Then a SemanticError should be raised at runtime: `"Tom"', expected LIST, but was STRING When executing query: """ YIELD single(n IN NULL WHERE n == 3) AS r diff --git a/tests/tck/features/expression/Reduce.feature b/tests/tck/features/expression/Reduce.feature index 25ad1710b85501bb40b7126a1db5ec362dd7b27c..6110cc45b3b9b182a4a75443355903373cfd6e1f 100644 --- a/tests/tck/features/expression/Reduce.feature +++ b/tests/tck/features/expression/Reduce.feature @@ -86,7 +86,7 @@ Feature: Reduce """ YIELD reduce(totalNum = 10, n IN "jerry" | totalNum + n) AS r """ - Then a SemanticError should be raised at runtime: `reduce(totalNum = 10, n IN "jerry" | (totalNum+n))': Invalid colletion type, expected type of LIST, but was: STRING + Then a SemanticError should be raised at runtime: `"jerry"', expected LIST, but was STRING When executing query: """ YIELD reduce(totalNum = 10, n IN NULL | totalNum + n) AS r