From 99d729b8d69ce3fba528b15117fe55b1baab3b04 Mon Sep 17 00:00:00 2001 From: nebula-bots <88429921+nebula-bots@users.noreply.github.com> Date: Fri, 10 Mar 2023 11:13:24 +0800 Subject: [PATCH] Fix use switch space combine with match (#2480) Co-authored-by: Yichen Wang <18348405+Aiee@users.noreply.github.com> --- src/graph/visitor/PropertyTrackerVisitor.cpp | 19 +++++---- .../features/bugfix/UseSpaceAndMatch.feature | 41 +++++++++++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 tests/tck/features/bugfix/UseSpaceAndMatch.feature diff --git a/src/graph/visitor/PropertyTrackerVisitor.cpp b/src/graph/visitor/PropertyTrackerVisitor.cpp index 451f9ded7b7..ede1c764fea 100644 --- a/src/graph/visitor/PropertyTrackerVisitor.cpp +++ b/src/graph/visitor/PropertyTrackerVisitor.cpp @@ -162,19 +162,24 @@ void PropertyTrackerVisitor::visit(EdgePropertyExpression *expr) { } void PropertyTrackerVisitor::visit(LabelTagPropertyExpression *expr) { - auto status = qctx_->schemaMng()->toTagID(space_, expr->sym()); - if (!status.ok()) { - status_ = std::move(status).status(); - return; - } auto &nodeAlias = static_cast(expr->label())->prop(); auto &tagName = expr->sym(); auto &propName = expr->prop(); + auto ret = qctx_->schemaMng()->toTagID(space_, tagName); if (!ret.ok()) { - status_ = std::move(ret).status(); - return; + // if the we switch space in the query, we need to get the space id from the validation context + // use xxx; match xxx + if (qctx_->vctx()->spaceChosen()) { + space_ = qctx_->vctx()->whichSpace().id; + ret = qctx_->schemaMng()->toTagID(qctx_->vctx()->whichSpace().id, tagName); + if (!ret.ok()) { + status_ = std::move(ret).status(); + return; + } + } } + auto tagId = ret.value(); propsUsed_.insertVertexProp(nodeAlias, tagId, propName); } diff --git a/tests/tck/features/bugfix/UseSpaceAndMatch.feature b/tests/tck/features/bugfix/UseSpaceAndMatch.feature new file mode 100644 index 00000000000..c9883160f09 --- /dev/null +++ b/tests/tck/features/bugfix/UseSpaceAndMatch.feature @@ -0,0 +1,41 @@ +# Copyright (c) 2023 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. +# Fix https://github.com/vesoft-inc/nebula/issues/5263 +Feature: Use space combine with Match + + Scenario: Use space combine with Match + Given an empty graph + And load "nba" csv data to a new space + When executing query: + """ + CREATE USER IF NOT EXISTS new_user_5263 WITH PASSWORD 'nebula'; + """ + Then the execution should be successful + When executing query: + """ + GRANT ROLE ADMIN ON nba TO new_user_5263; + """ + Then the execution should be successful + And wait 3 seconds + When executing query with user "new_user_5263" and password "nebula": + """ + USE nba; MATCH (p)-[e]->(v) WHERE id(p)=="Tony Parker" RETURN v.player.age + """ + Then the result should be, in any order, with relax comparison: + | v.player.age | + | NULL | + | NULL | + | 25 | + | 33 | + | 41 | + | 42 | + | 33 | + | 41 | + | 42 | + When executing query: + """ + DROP USER IF EXISTS new_user_5263; + """ + Then the execution should be successful + Then drop the used space