Skip to content

Commit

Permalink
Refactor all the setting of outputVar() to enforce the assignment of …
Browse files Browse the repository at this point in the history
…colNames explicitly.
  • Loading branch information
xtcyclist committed Dec 5, 2022
1 parent 04ea700 commit f86422a
Show file tree
Hide file tree
Showing 51 changed files with 69 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/graph/executor/test/DedupTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DedupTest : public QueryTestBase {
auto yieldSentence = getYieldSentence(sentence, qctx_.get()); \
auto* dedupNode = Dedup::make(qctx_.get(), nullptr); \
dedupNode->setInputVar(inputName); \
dedupNode->setOutputVar(outputName); \
dedupNode->setOutputVar(outputName, expected.colNames); \
auto dedupExec = std::make_unique<DedupExecutor>(dedupNode, qctx_.get()); \
if (!expected.colNames.empty()) { \
EXPECT_TRUE(dedupExec->execute().get().ok()); \
Expand Down
2 changes: 1 addition & 1 deletion src/graph/executor/test/FilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FilterTest : public QueryTestBase {
whereSentence->setFilter(ExpressionUtils::rewriteLabelAttr2EdgeProp(whereSentence->filter())); \
auto* filterNode = Filter::make(qctx_.get(), nullptr, yieldSentence->where()->filter()); \
filterNode->setInputVar(inputName); \
filterNode->setOutputVar(outputName); \
filterNode->setOutputVar(outputName, expected.colNames); \
auto filterExec = std::make_unique<FilterExecutor>(filterNode, qctx_.get()); \
EXPECT_TRUE(filterExec->execute().get().ok()); \
auto& filterResult = qctx_->ectx()->getResult(filterNode->outputVar()); \
Expand Down
12 changes: 4 additions & 8 deletions src/graph/executor/test/JoinTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,9 @@ TEST_F(JoinTest, HashInnerJoin) {
std::vector<Expression*> probeKeys = {probe1, probe2};

auto lhs = Project::make(qctx_.get(), nullptr, nullptr);
lhs->setOutputVar("var4");
lhs->setColNames({"v1", "e1", "v2", "v3"});
lhs->setOutputVar("var4", {"v1", "e1", "v2", "v3"});
auto rhs = Project::make(qctx_.get(), nullptr, nullptr);
rhs->setOutputVar("var5");
rhs->setColNames({"v2", "e2", "v3"});
rhs->setOutputVar("var5", {"v2", "e2", "v3"});

auto* join =
HashInnerJoin::make(qctx_.get(), lhs, rhs, std::move(hashKeys), std::move(probeKeys));
Expand Down Expand Up @@ -417,11 +415,9 @@ TEST_F(JoinTest, HashLeftJoin) {
std::vector<Expression*> probeKeys = {probe1, probe2};

auto lhs = Project::make(qctx_.get(), nullptr, nullptr);
lhs->setOutputVar("var5");
lhs->setColNames({"v2", "e2", "v3"});
lhs->setOutputVar("var5", {"v2", "e2", "v3"});
auto rhs = Project::make(qctx_.get(), nullptr, nullptr);
rhs->setOutputVar("var4");
rhs->setColNames({"v1", "e1", "v2", "v3"});
rhs->setOutputVar("var4", {"v1", "e1", "v2", "v3"});

auto* join = HashLeftJoin::make(qctx_.get(), lhs, rhs, std::move(hashKeys), std::move(probeKeys));

Expand Down
2 changes: 1 addition & 1 deletion src/graph/executor/test/LimitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LimitTest : public QueryTestBase {};
auto start = StartNode::make(qctx_.get()); \
auto* limitNode = Limit::make(qctx_.get(), start, offset, count); \
limitNode->setInputVar("input_sequential"); \
limitNode->setOutputVar(outputName); \
limitNode->setOutputVar(outputName, expected.colNames); \
auto limitExec = Executor::create(limitNode, qctx_.get()); \
EXPECT_TRUE(limitExec->execute().get().ok()); \
auto& limitResult = qctx_->ectx()->getResult(limitNode->outputVar()); \
Expand Down
4 changes: 2 additions & 2 deletions src/graph/executor/test/SampleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SampleTest : public QueryTestBase {};
auto start = StartNode::make(qctx_.get()); \
auto* sampleNode = Sample::make(qctx_.get(), start, count); \
sampleNode->setInputVar("input_sequential"); \
sampleNode->setOutputVar(outputName); \
sampleNode->setOutputVar(outputName, {}); \
auto sampleExec = Executor::create(sampleNode, qctx_.get()); \
EXPECT_TRUE(sampleExec->execute().get().ok()); \
auto& sampleResult = qctx_->ectx()->getResult(sampleNode->outputVar()); \
Expand Down Expand Up @@ -59,7 +59,7 @@ TEST_F(SampleTest, SequentialOutRange2) {
auto start = StartNode::make(qctx_.get()); \
auto* sampleNode = Sample::make(qctx_.get(), start, count); \
sampleNode->setInputVar("input_neighbor"); \
sampleNode->setOutputVar(outputName); \
sampleNode->setOutputVar(outputName, {}); \
auto sampleExec = Executor::create(sampleNode, qctx_.get()); \
EXPECT_TRUE(sampleExec->execute().get().ok()); \
auto& sampleResult = qctx_->ectx()->getResult(sampleNode->outputVar()); \
Expand Down
2 changes: 1 addition & 1 deletion src/graph/executor/test/SortTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SortTest : public QueryTestBase {};
auto start = StartNode::make(qctx_.get()); \
auto* sortNode = Sort::make(qctx_.get(), start, factors); \
sortNode->setInputVar(input_name); \
sortNode->setOutputVar(outputName); \
sortNode->setOutputVar(outputName, expected.colNames); \
auto sortExec = Executor::create(sortNode, qctx_.get()); \
EXPECT_TRUE(sortExec->execute().get().ok()); \
auto& sortResult = qctx_->ectx()->getResult(sortNode->outputVar()); \
Expand Down
2 changes: 1 addition & 1 deletion src/graph/executor/test/TopNTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TopNTest : public QueryTestBase {};
auto start = StartNode::make(qctx_.get()); \
auto* topnNode = TopN::make(qctx_.get(), start, factors, offset, count); \
topnNode->setInputVar(input_name); \
topnNode->setOutputVar(outputName); \
topnNode->setOutputVar(outputName, expected.colNames); \
auto topnExec = Executor::create(topnNode, qctx_.get()); \
EXPECT_TRUE(topnExec->execute().get().ok()); \
auto& topnResult = qctx_->ectx()->getResult(topnNode->outputVar()); \
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/CollapseProjectRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ StatusOr<OptRule::TransformResult> CollapseProjectRule::transform(

// 4. rebuild OptGroupNode
newProj->setInputVar(projBelow->inputVar());
newProj->setOutputVar(projAbove->outputVar());
newProj->setOutputVar(projAbove->outputVar(), projAbove->colNames());
auto* newGroupNode = OptGroupNode::create(octx, newProj, projGroup);
newGroupNode->setDeps(groupNodeBelow->dependencies());

Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/CombineFilterRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ StatusOr<OptRule::TransformResult> CombineFilterRule::transform(
auto* conditionCombine =
LogicalExpression::makeAnd(pool, conditionAbove->clone(), conditionBelow->clone());
newFilter->setCondition(conditionCombine);
newFilter->setOutputVar(filterAbove->outputVar());
newFilter->setOutputVar(filterAbove->outputVar(), filterAbove->colNames());
auto* newGroupNode = OptGroupNode::create(octx, newFilter, filterGroup);
newGroupNode->setDeps(groupNode->dependencies());
result.newGroupNodes.emplace_back(newGroupNode);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/EliminateAppendVerticesRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ StatusOr<OptRule::TransformResult> EliminateAppendVerticesRule::transform(
const auto appendVertices = static_cast<const AppendVertices*>(appendVerticesGroupNode->node());

auto newProj = static_cast<Project*>(project->clone());
newProj->setOutputVar(project->outputVar());
newProj->setOutputVar(project->outputVar(), project->colNames());
newProj->setInputVar(appendVertices->inputVar());
auto newProjGroupNode = OptGroupNode::create(octx, newProj, projectGroupNode->group());
newProjGroupNode->setDeps(appendVerticesGroupNode->dependencies());
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/EliminateRowCollectRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ StatusOr<OptRule::TransformResult> EliminateRowCollectRule::transform(
const auto proj = static_cast<const Project*>(projGroupNode->node());

auto newProj = static_cast<Project*>(proj->clone());
newProj->setOutputVar(dataCollect->outputVar());
newProj->setOutputVar(dataCollect->outputVar(), dataCollect->colNames());
auto newProjGroupNode = OptGroupNode::create(octx, newProj, dataCollectGroupNode->group());

for (auto dep : projGroupNode->dependencies()) {
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
scanNode->setIndexQueryContext(std::move(idxCtxs));
// TODO(jie): geo predicate's calculation is a little heavy,
// which is not suitable to push down to the storage
scanNode->setOutputVar(filter->outputVar());
scanNode->setOutputVar(filter->outputVar(), filter->colNames());
scanNode->setColNames(filter->colNames());
auto filterGroup = matched.node->group();
auto optScanNode = OptGroupNode::create(ctx, scanNode, filterGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformAppendVerticesLimitRule::tra

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

auto limitGroupNode = matched.dependencies.front().node;
auto limit = static_cast<const Limit *>(limitGroupNode->node());
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/GetEdgesTransformRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ StatusOr<OptRule::TransformResult> GetEdgesTransformRule::transform(
auto project = static_cast<const Project *>(projectGroupNode->node());

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

auto limitGroupNode = matched.dependencies.front().node;
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/IndexFullScanBaseRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ StatusOr<TransformResult> IndexFullScanBaseRule::transform(OptContext* ctx,

auto scanNode = this->scan(ctx, scan);
OptimizerUtils::copyIndexScanData(scan, scanNode, ctx->qctx());
scanNode->setOutputVar(scan->outputVar());
scanNode->setOutputVar(scan->outputVar(), scan->colNames());
scanNode->setColNames(scan->colNames());
scanNode->setIndexQueryContext(std::move(idxCtxs));
auto filterGroup = matched.node->group();
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/IndexScanRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ StatusOr<OptRule::TransformResult> IndexScanRule::transform(OptContext* ctx,
const auto* oldIN = groupNode->node();
DCHECK_EQ(oldIN->kind(), graph::PlanNode::Kind::kIndexScan);
auto* newIN = static_cast<IndexScan*>(oldIN->clone());
newIN->setOutputVar(oldIN->outputVar());
newIN->setOutputVar(oldIN->outputVar(), oldIN->colNames());
newIN->setIndexQueryContext(std::move(iqctx));
auto newGroupNode = OptGroupNode::create(ctx, newIN, groupNode->group());
if (groupNode->dependencies().size() != 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/MergeGetNbrsAndDedupRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ StatusOr<OptRule::TransformResult> MergeGetNbrsAndDedupRule::transform(
newGN->setDedup();
}
newGN->setInputVar(dedup->inputVar());
newGN->setOutputVar(gn->outputVar());
newGN->setOutputVar(gn->outputVar(), gn->colNames());
auto newOptGV = OptGroupNode::create(octx, newGN, optGN->group());
for (auto dep : optDedup->dependencies()) {
newOptGV->dependsOn(dep);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/MergeGetNbrsAndProjectRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ StatusOr<OptRule::TransformResult> MergeGetNbrsAndProjectRule::transform(
auto srcExpr = column->expr()->clone();
newGN->setSrc(srcExpr);
newGN->setInputVar(project->inputVar());
newGN->setOutputVar(gn->outputVar());
newGN->setOutputVar(gn->outputVar(), gn->colNames());
auto newOptGV = OptGroupNode::create(ctx, newGN, optGN->group());
for (auto dep : optProj->dependencies()) {
newOptGV->dependsOn(dep);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/MergeGetVerticesAndDedupRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ StatusOr<OptRule::TransformResult> MergeGetVerticesAndDedupRule::transform(
newGV->setDedup();
}
newGV->setInputVar(dedup->inputVar());
newGV->setOutputVar(gv->outputVar());
newGV->setOutputVar(gv->outputVar(), gv->colNames());
auto newOptGV = OptGroupNode::create(ctx, newGV, optGV->group());
for (auto dep : optDedup->dependencies()) {
newOptGV->dependsOn(dep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ StatusOr<OptRule::TransformResult> MergeGetVerticesAndProjectRule::transform(
auto srcExpr = column->expr()->clone();
newGV->setSrc(srcExpr);
newGV->setInputVar(project->inputVar());
newGV->setOutputVar(gv->outputVar());
newGV->setOutputVar(gv->outputVar(), gv->colNames());
auto newOptGV = OptGroupNode::create(ctx, newGV, optGV->group());
for (auto dep : optProj->dependencies()) {
newOptGV->dependsOn(dep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ StatusOr<TransformResult> OptimizeEdgeIndexScanByFilterRule::transform(
std::vector<IndexQueryContext> idxCtxs = {ictx};
auto scanNode = makeEdgeIndexScan(ctx->qctx(), scan, isPrefixScan);
scanNode->setIndexQueryContext(std::move(idxCtxs));
scanNode->setOutputVar(filter->outputVar());
scanNode->setOutputVar(filter->outputVar(), filter->colNames());
scanNode->setColNames(filter->colNames());
auto filterGroup = matched.node->group();
auto optScanNode = OptGroupNode::create(ctx, scanNode, filterGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ StatusOr<TransformResult> OptimizeTagIndexScanByFilterRule::transform(
std::vector<IndexQueryContext> idxCtxs = {ictx};
auto scanNode = makeTagIndexScan(ctx->qctx(), scan, isPrefixScan);
scanNode->setIndexQueryContext(std::move(idxCtxs));
scanNode->setOutputVar(filter->outputVar());
scanNode->setOutputVar(filter->outputVar(), filter->colNames());
scanNode->setColNames(filter->colNames());
auto filterGroup = matched.node->group();
auto optScanNode = OptGroupNode::create(ctx, scanNode, filterGroup);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/PushEFilterDownRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ StatusOr<OptRule::TransformResult> PushEFilterDownRule::transform(

auto remainedExpr = std::move(visitor).remainedExpr();
auto newTraverse = traverse->clone();
newTraverse->setOutputVar(traverse->outputVar());
newTraverse->setOutputVar(traverse->outputVar(), traverse->colNames());
newTraverse->setEdgeFilter(remainedExpr);
if (newTraverse->filter() != nullptr) {
newTraverse->setFilter(
Expand Down
4 changes: 2 additions & 2 deletions src/graph/optimizer/rule/PushFilterDownAggregateRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownAggregateRule::transform(

// Exchange planNode
// newAggNode shall inherit the output of the oldFilterNode
newAggNode->setOutputVar(oldFilterNode->outputVar());
newAggNode->setOutputVar(oldFilterNode->outputVar(), oldFilterNode->colNames());
// as the new agg node now inherits the output var ptr from a filter node, the action of
// which alters its own colNames, its colNames need to be explicitly preserved.
newAggNode->setColNames(oldAggNode->colNames());
Expand All @@ -100,7 +100,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownAggregateRule::transform(
DCHECK_EQ(oldAggNode->outputVar(), oldFilterNode->inputVar());
// newAggNode shall inherit oldFilterNode's inputs
newAggNode->setInputVar(oldFilterNode->inputVar());
newFilterNode->setOutputVar(newAggNode->inputVar());
newFilterNode->setOutputVar(newAggNode->inputVar(), newAggNode->colNames());

// Push down filter's optGroup and embed newAggGroupNode into old filter's
// Group
Expand Down
4 changes: 2 additions & 2 deletions src/graph/optimizer/rule/PushFilterDownGetNbrsRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownGetNbrsRule::transform(
PlanNode *newFilter = nullptr;
if (remainedExpr != nullptr) {
newFilter = Filter::make(qctx, nullptr, remainedExpr);
newFilter->setOutputVar(filter->outputVar());
newFilter->setOutputVar(filter->outputVar(), filter->colNames());
newFilterGroupNode = OptGroupNode::create(ctx, newFilter, filterGroupNode->group());
}

Expand All @@ -89,7 +89,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownGetNbrsRule::transform(
} else {
// Filter(A)<-GetNeighbors(C) => GetNeighbors(A&&C)
newGnGroupNode = OptGroupNode::create(ctx, newGN, filterGroupNode->group());
newGN->setOutputVar(filter->outputVar());
newGN->setOutputVar(filter->outputVar(), filter->colNames());
}

for (auto dep : gnGroupNode->dependencies()) {
Expand Down
4 changes: 2 additions & 2 deletions src/graph/optimizer/rule/PushFilterDownInnerJoinRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownInnerJoinRule::transform(
result.eraseAll = true;
if (filterUnpicked) {
auto* newAboveFilterNode = graph::Filter::make(octx->qctx(), newInnerJoinNode);
newAboveFilterNode->setOutputVar(oldFilterNode->outputVar());
newAboveFilterNode->setOutputVar(oldFilterNode->outputVar(), oldFilterNode->colNames());
newAboveFilterNode->setCondition(filterUnpicked);
auto newAboveFilterGroupNode =
OptGroupNode::create(octx, newAboveFilterNode, filterGroupNode->group());
Expand All @@ -116,7 +116,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownInnerJoinRule::transform(
newInnerJoinGroupNode->setDeps({newFilterGroup});
result.newGroupNodes.emplace_back(newAboveFilterGroupNode);
} else {
newInnerJoinNode->setOutputVar(oldFilterNode->outputVar());
newInnerJoinNode->setOutputVar(oldFilterNode->outputVar(), oldFilterNode->colNames());
newInnerJoinNode->setColNames(oldInnerJoinNode->colNames());
auto newInnerJoinGroupNode =
OptGroupNode::create(octx, newInnerJoinNode, filterGroupNode->group());
Expand Down
4 changes: 2 additions & 2 deletions src/graph/optimizer/rule/PushFilterDownLeftJoinRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownLeftJoinRule::transform(
result.eraseAll = true;
if (filterUnpicked) {
auto* newAboveFilterNode = graph::Filter::make(octx->qctx(), newLeftJoinNode);
newAboveFilterNode->setOutputVar(oldFilterNode->outputVar());
newAboveFilterNode->setOutputVar(oldFilterNode->outputVar(), oldFilterNode->colNames());
newAboveFilterNode->setCondition(filterUnpicked);
auto newAboveFilterGroupNode =
OptGroupNode::create(octx, newAboveFilterNode, filterGroupNode->group());
Expand All @@ -116,7 +116,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownLeftJoinRule::transform(
newLeftJoinGroupNode->setDeps({newFilterGroup});
result.newGroupNodes.emplace_back(newAboveFilterGroupNode);
} else {
newLeftJoinNode->setOutputVar(oldFilterNode->outputVar());
newLeftJoinNode->setOutputVar(oldFilterNode->outputVar(), oldFilterNode->colNames());
newLeftJoinNode->setColNames(oldLeftJoinNode->colNames());
auto newLeftJoinGroupNode =
OptGroupNode::create(octx, newLeftJoinNode, filterGroupNode->group());
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/PushFilterDownNodeRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownNodeRule::transform(
auto remainedExpr = std::move(visitor).remainedExpr();
auto *explore = static_cast<const Explore *>(node);
auto *newExplore = static_cast<Explore *>(node->clone());
newExplore->setOutputVar(explore->outputVar());
newExplore->setOutputVar(explore->outputVar(), explore->colNames());
auto newExploreGroupNode = OptGroupNode::create(ctx, newExplore, groupNode->group());
if (explore->filter() != nullptr) {
vFilter = LogicalExpression::makeAnd(pool, vFilter, newExplore->filter());
Expand Down
Loading

0 comments on commit f86422a

Please sign in to comment.