From e5c2101e4c12fd6e989ad813f22f0cf73df419a8 Mon Sep 17 00:00:00 2001 From: CPWstatic <13495049+CPWstatic@users.noreply.github.com> Date: Thu, 23 Dec 2021 13:41:40 +0800 Subject: [PATCH] Fix aliases not pass to next query parts. --- src/graph/validator/MatchValidator.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index ed76f355077..6a750e45612 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -41,17 +41,22 @@ Status MatchValidator::validateImpl() { for (size_t j = 0; j < matchClause->path()->pathSize(); ++j) { NG_RETURN_IF_ERROR(validatePath(matchClause->path()->path(j), *matchClauseCtx)); } + + // Available aliases include the aliases pass from the with/unwind + // And previous aliases are all available to next match + auto aliasesTmp = matchClauseCtx->aliasesGenerated; + aliasesAvailable.merge(aliasesTmp); + if (matchClause->where() != nullptr) { auto whereClauseCtx = getContext(); - whereClauseCtx->aliasesAvailable = matchClauseCtx->aliasesGenerated; + whereClauseCtx->aliasesAvailable = aliasesAvailable; NG_RETURN_IF_ERROR(validateFilter(matchClause->where()->filter(), *whereClauseCtx)); matchClauseCtx->where = std::move(whereClauseCtx); } // Copy the aliases without delete the origins. - auto aliasesTmp = matchClauseCtx->aliasesGenerated; + aliasesTmp = matchClauseCtx->aliasesGenerated; cypherCtx_->queryParts.back().aliasesGenerated.merge(aliasesTmp); - aliasesAvailable = cypherCtx_->queryParts.back().aliasesGenerated; cypherCtx_->queryParts.back().matchs.emplace_back(std::move(matchClauseCtx)); break; @@ -62,7 +67,7 @@ Status MatchValidator::validateImpl() { unwindClauseCtx->aliasesAvailable = aliasesAvailable; NG_RETURN_IF_ERROR(validateUnwind(unwindClause, *unwindClauseCtx)); - // An unwind bypass all available aliases. + // An unwind pass all available aliases. aliasesAvailable.insert(unwindClauseCtx->aliasesGenerated.begin(), unwindClauseCtx->aliasesGenerated.end()); cypherCtx_->queryParts.back().boundary = std::move(unwindClauseCtx); @@ -85,6 +90,7 @@ Status MatchValidator::validateImpl() { withClauseCtx->where = std::move(whereClauseCtx); } + // A with pass all named aliases to the next query part. aliasesAvailable = withClauseCtx->aliasesGenerated; cypherCtx_->queryParts.back().boundary = std::move(withClauseCtx); cypherCtx_->queryParts.emplace_back();