diff --git a/src/context/Symbols.h b/src/context/Symbols.h index ef9454253a02a071a52355c2c02fb886d7693cff..138fd0c927b253f429f4e8cbb654a75e3c2796ca 100644 --- a/src/context/Symbols.h +++ b/src/context/Symbols.h @@ -9,6 +9,8 @@ #include "util/ObjectPool.h" +#include "common/datatypes/Value.h" + namespace nebula { namespace graph { @@ -118,6 +120,7 @@ private: // var name -> variable std::unordered_map<std::string, Variable*> vars_; }; + } // namespace graph } // namespace nebula #endif diff --git a/src/validator/GoValidator.cpp b/src/validator/GoValidator.cpp index e15006203dd712918e9a614d98e5377f46929c0d..828e7d25f3aea0718206c723a045d21a142c5bc4 100644 --- a/src/validator/GoValidator.cpp +++ b/src/validator/GoValidator.cpp @@ -749,10 +749,7 @@ void GoValidator::extractPropExprs(const Expression* expr) { std::unique_ptr<Expression> GoValidator::rewriteToInputProp(Expression* expr) { RewriteInputPropVisitor visitor(propExprColMap_); const_cast<Expression*>(expr)->accept(&visitor); - if (visitor.ok()) { - return std::move(visitor).result(); - } - return nullptr; + return std::move(visitor).result(); } Status GoValidator::buildColumns() { diff --git a/src/visitor/RewriteInputPropVisitor.cpp b/src/visitor/RewriteInputPropVisitor.cpp index e95a5da8089775a45de149950f11547b3ae144c7..4c2bd8fe14b580f336154faebdf95be5758a6dd8 100644 --- a/src/visitor/RewriteInputPropVisitor.cpp +++ b/src/visitor/RewriteInputPropVisitor.cpp @@ -121,36 +121,34 @@ void RewriteInputPropVisitor::visit(VariablePropertyExpression* expr) { } void RewriteInputPropVisitor::visit(ListExpression* expr) { - auto items = std::move(*expr).get(); - for (auto iter = items.begin(); iter < items.end(); ++iter) { - iter->get()->accept(this); + const auto& items = expr->items(); + for (size_t i = 0; i < items.size(); ++i) { + items[i]->accept(this); if (ok()) { - *iter = std::move(result_); + expr->setItem(i, std::move(result_)); } } - expr->setItems(std::move(items)); } void RewriteInputPropVisitor::visit(SetExpression* expr) { - auto items = std::move(*expr).get(); - for (auto iter = items.begin(); iter < items.end(); ++iter) { - iter->get()->accept(this); + const auto& items = expr->items(); + for (size_t i = 0; i < items.size(); ++i) { + items[i]->accept(this); if (ok()) { - *iter = std::move(result_); + expr->setItem(i, std::move(result_)); } } - expr->setItems(std::move(items)); } void RewriteInputPropVisitor::visit(MapExpression* expr) { - auto items = std::move(*expr).get(); - for (auto iter = items.begin(); iter < items.end(); ++iter) { - iter->second.get()->accept(this); + const auto& items = expr->items(); + for (size_t i = 0; i < items.size(); ++i) { + items[i].second->accept(this); if (ok()) { - *iter = std::make_pair(std::move(iter->first), std::move(result_)); + auto key = std::make_unique<std::string>(*items[i].first); + expr->setItem(i, {std::move(key), std::move(result_)}); } } - expr->setItems(std::move(items)); } void RewriteInputPropVisitor::visit(FunctionCallExpression* expr) { @@ -189,49 +187,7 @@ void RewriteInputPropVisitor::visitUnaryExpr(UnaryExpression* expr) { } void RewriteInputPropVisitor::visitVertexEdgePropExpr(PropertyExpression* expr) { - PropertyExpression* propExpr = nullptr; - switch (expr->kind()) { - case Expression::Kind::kTagProperty: { - propExpr = static_cast<TagPropertyExpression*>(expr); - break; - } - case Expression::Kind::kSrcProperty: { - propExpr = static_cast<SourcePropertyExpression*>(expr); - break; - } - case Expression::Kind::kDstProperty: { - propExpr = static_cast<DestPropertyExpression*>(expr); - break; - } - case Expression::Kind::kEdgeProperty: { - propExpr = static_cast<EdgePropertyExpression*>(expr); - break; - } - case Expression::Kind::kEdgeSrc: { - propExpr = static_cast<EdgeSrcIdExpression*>(expr); - break; - } - case Expression::Kind::kEdgeType: { - propExpr = static_cast<EdgeTypeExpression*>(expr); - break; - } - case Expression::Kind::kEdgeRank: { - propExpr = static_cast<EdgeRankExpression*>(expr); - break; - } - case Expression::Kind::kEdgeDst: { - propExpr = static_cast<EdgeDstIdExpression*>(expr); - break; - } - case Expression::Kind::kVarProperty: { - propExpr = static_cast<VariablePropertyExpression*>(expr); - break; - } - default: { - LOG(FATAL) << "Invalid Kind " << expr->kind(); - } - } - auto found = propExprColMap_.find(propExpr->toString()); + auto found = propExprColMap_.find(expr->toString()); DCHECK(found != propExprColMap_.end()); auto alias = new std::string(*(found->second->alias())); result_ = std::make_unique<InputPropertyExpression>(alias); diff --git a/src/visitor/RewriteInputPropVisitor.h b/src/visitor/RewriteInputPropVisitor.h index 791f62497d83c05166cbf333c9d3232ecacf3267..6e4500c51316e613fe30ce1b75b941a027abfc4d 100644 --- a/src/visitor/RewriteInputPropVisitor.h +++ b/src/visitor/RewriteInputPropVisitor.h @@ -15,7 +15,8 @@ namespace graph { class RewriteInputPropVisitor final : public ExprVisitor { public: - explicit RewriteInputPropVisitor(std::unordered_map<std::string, YieldColumn *> &propExprColMap) + explicit RewriteInputPropVisitor( + const std::unordered_map<std::string, YieldColumn *> &propExprColMap) : propExprColMap_(propExprColMap) {} ~RewriteInputPropVisitor() = default; @@ -75,7 +76,7 @@ private: void reportError(const Expression *); private: - std::unordered_map<std::string, YieldColumn *>& propExprColMap_; + const std::unordered_map<std::string, YieldColumn *> &propExprColMap_; std::unique_ptr<Expression> result_; Status status_; diff --git a/tests/pytest.ini b/tests/pytest.ini index 2ea88d151d93e50b9c3dcbd728679c1c802c119e..298bf0165f088fe0196d82dc8e20671f759038b9 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -1,3 +1,3 @@ [pytest] -addopts = -r xfE -v --tb=short --showlocals -s +addopts = -r xfE -v --tb=short --showlocals junit_family=legacy diff --git a/tests/query/v1/test_find_path.py b/tests/query/v1/test_find_path.py index d945f4bf6fa5e8e342b0048f92ff5b3e05a3972a..62402d43da34f87095e3a510b3097cc34846fe68 100644 --- a/tests/query/v1/test_find_path.py +++ b/tests/query/v1/test_find_path.py @@ -5,12 +5,9 @@ # This source code is licensed under Apache 2.0 License, # attached with Common Clause Condition 1.0, found in the LICENSES directory. -import pytest - from tests.common.nebula_test_suite import NebulaTestSuite -@pytest.mark.usefixtures('set_vertices_and_edges') class TestFindPath(NebulaTestSuite): @classmethod def prepare(self): diff --git a/tests/query/conftest.py b/tests/query/v2/conftest.py similarity index 100% rename from tests/query/conftest.py rename to tests/query/v2/conftest.py diff --git a/tests/query/v2/test_match.py b/tests/query/v2/test_match.py index 55eca752f0c6925bee7310c3adb066da491960b3..ee338e55c8e725b7c8999e668305d57313073bbc 100644 --- a/tests/query/v2/test_match.py +++ b/tests/query/v2/test_match.py @@ -5,19 +5,17 @@ # This source code is licensed under Apache 2.0 License, # attached with Common Clause Condition 1.0, found in the LICENSES directory. -from tests.common.nebula_test_suite import NebulaTestSuite -from tests.common.nebula_test_suite import T_NULL, T_EMPTY import pytest +from tests.common.nebula_test_suite import NebulaTestSuite + + @pytest.mark.usefixtures('set_vertices_and_edges') class TestMatch(NebulaTestSuite): @classmethod def prepare(self): self.use_nba() - def cleanup(): - pass - def test_single_node(self): VERTICES = self.VERTEXS stmt = 'MATCH (v:player {name: "Yao Ming"}) RETURN v' @@ -93,10 +91,7 @@ class TestMatch(NebulaTestSuite): self.check_column_names(resp, expected['column_names']) self.check_out_of_order_result(resp, expected['rows']) - def test_one_step(self): - VERTICES = self.VERTEXS - stmt = 'MATCH (v1:player{name: "LeBron James"}) -[r]-> (v2) RETURN type(r) AS Type, v2.name AS Name' resp = self.execute_query(stmt) self.check_resp_succeeded(resp) @@ -164,8 +159,6 @@ class TestMatch(NebulaTestSuite): self.check_out_of_order_result(resp, expected['rows']) def test_two_steps(self): - VERTICES = self.VERTEXS - stmt = ''' MATCH (v1:player{age: 28}) -[:like]-> (v2) -[:like]-> (v3) RETURN v1.name AS Player, v2.name AS Friend, v3.name AS FoF