Skip to content

Commit

Permalink
Fix get edges transform rule. (#4328)
Browse files Browse the repository at this point in the history
1. Input/Ouput variables.
2. Keep column names of Limit same with input plan node.

Co-authored-by: Sophie <[email protected]>
  • Loading branch information
Shylock-Hg and Sophie-Xie authored Jun 21, 2022
1 parent 533d359 commit 7be5638
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/graph/optimizer/rule/CollapseProjectRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ StatusOr<OptRule::TransformResult> CollapseProjectRule::transform(
// 2. find link according to propRefNames and colNames in ProjBelow
std::unordered_map<std::string, Expression*> rewriteMap;
auto colNames = projBelow->colNames();
DCHECK_EQ(colNames.size(), colsBelow.size());
for (size_t i = 0; i < colNames.size(); ++i) {
if (uniquePropRefNames.count(colNames[i])) {
auto colExpr = colsBelow[i]->expr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformAppendVerticesLimitRule::tra
auto newLimit = limit->clone();
auto newLimitGroup = OptGroup::create(ctx);
auto newLimitGroupNode = newLimitGroup->makeGroupNode(newLimit);
newLimit->setOutputVar(limit->outputVar());
newProject->setInputVar(newLimit->outputVar());

newProjectGroupNode->dependsOn(newLimitGroup);
Expand All @@ -105,8 +104,8 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformAppendVerticesLimitRule::tra
auto newAppendVertices = appendVertices->clone();
auto newAppendVerticesGroup = OptGroup::create(ctx);
auto colSize = appendVertices->colNames().size();
newAppendVertices->setOutputVar(appendVertices->outputVar());
newLimit->setInputVar(newAppendVertices->outputVar());
newLimit->setColNames(newAppendVertices->colNames()); // Limit keep column names same with input
newAppendVertices->setColNames(
{appendVertices->colNames()[colSize - 2], appendVertices->colNames()[colSize - 1]});
auto newAppendVerticesGroupNode = newAppendVerticesGroup->makeGroupNode(newAppendVertices);
Expand All @@ -123,19 +122,19 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformAppendVerticesLimitRule::tra
auto *newProj =
GetEdgesTransformUtils::projectEdges(qctx, newScanEdges, traverse->colNames().back());
newProj->setInputVar(newScanEdges->outputVar());
newProj->setOutputVar(newAppendVertices->inputVar());
newProj->setColNames({traverse->colNames().back()});
auto newProjGroup = OptGroup::create(ctx);
auto newProjGroupNode = newProjGroup->makeGroupNode(newProj);

newAppendVerticesGroupNode->dependsOn(newProjGroup);
newAppendVertices->setInputVar(newProj->outputVar());
newProjGroupNode->dependsOn(newScanEdgesGroup);
for (auto dep : scanVerticesGroupNode->dependencies()) {
newScanEdgesGroupNode->dependsOn(dep);
}

TransformResult result;
result.eraseCurr = true;
result.eraseAll = true;
result.newGroupNodes.emplace_back(newProjectGroupNode);
return result;
}
Expand Down
9 changes: 5 additions & 4 deletions src/graph/optimizer/rule/GetEdgesTransformRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformRule::transform(
auto project = static_cast<const Project *>(projectGroupNode->node());

auto newProject = project->clone();
auto newProjectGroupNode = OptGroupNode::create(ctx, newProject, projectGroupNode->group());
newProject->setOutputVar(project->outputVar());
auto newProjectGroupNode = OptGroupNode::create(ctx, newProject, projectGroupNode->group());

auto limitGroupNode = matched.dependencies.front().node;
auto limit = static_cast<const Limit *>(limitGroupNode->node());
Expand All @@ -85,11 +85,11 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformRule::transform(

auto newLimit = limit->clone();
auto newLimitGroup = OptGroup::create(ctx);
newLimit->setOutputVar(limit->outputVar());

auto newLimitGroupNode = newLimitGroup->makeGroupNode(newLimit);

newProjectGroupNode->dependsOn(newLimitGroup);
newProject->setInputVar(newLimit->outputVar());

auto *newScanEdges = GetEdgesTransformUtils::traverseToScanEdges(traverse, limit->count(qctx));
if (newScanEdges == nullptr) {
Expand All @@ -100,14 +100,15 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformRule::transform(

auto *newProj =
GetEdgesTransformUtils::projectEdges(qctx, newScanEdges, traverse->colNames().back());
newProj->setInputVar(newScanEdges->outputVar());
newProj->setOutputVar(traverse->outputVar());
newProj->setColNames({traverse->colNames().back()});
auto newProjGroup = OptGroup::create(ctx);
auto newProjGroupNode = newProjGroup->makeGroupNode(newProj);

newLimitGroupNode->dependsOn(newProjGroup);
newLimit->setInputVar(newProj->outputVar());
newLimit->setColNames(newProj->colNames()); // Limit keep column names same with input
newProjGroupNode->dependsOn(newScanEdgesGroup);
newProj->setInputVar(newScanEdges->outputVar());
newScanEdgesGroupNode->setDeps(scanVerticesGroupNode->dependencies());

TransformResult result;
Expand Down
1 change: 1 addition & 0 deletions src/graph/optimizer/rule/GetEdgesTransformUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class GetEdgesTransformUtils final {
return scanEdges;
}

// [EDGE] AS <e>
static graph::Project *projectEdges(graph::QueryContext *qctx,
PlanNode *input,
const std::string &colName) {
Expand Down

0 comments on commit 7be5638

Please sign in to comment.