Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Feb 21, 2023
1 parent 82cf285 commit 0096f2e
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace kuzu {
namespace planner {
namespace factorization {

struct FlattenAllButOneFactorizationSolver {
static std::unordered_set<f_group_pos> getGroupsPosToFlatten(
const std::unordered_set<f_group_pos>& groupsPos, Schema* schema);
struct FlattenAllButOne {
static f_group_pos_set getGroupsPosToFlatten(const f_group_pos_set& groupsPos, Schema* schema);
};

struct FlattenAllFactorizationSolver {
static std::unordered_set<f_group_pos> getGroupsPosToFlatten(
const std::unordered_set<f_group_pos>& groupsPos, Schema* schema);
struct FlattenAll {
static f_group_pos_set getGroupsPosToFlatten(const f_group_pos_set& groupsPos, Schema* schema);
};

} // namespace factorization
} // namespace planner
} // namespace kuzu
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LogicalCreateNode : public LogicalUpdateNode {
// Flatten all inputs. E.g. MATCH (a) CREATE (b). We need to create b for each tuple in the
// match clause. This is to simplify operator implementation.
auto childSchema = children[0]->getSchema();
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(
return factorization::FlattenAll::getGroupsPosToFlatten(
childSchema->getGroupsPosInScope(), childSchema);
}

Expand All @@ -47,7 +47,7 @@ class LogicalCreateRel : public LogicalUpdateRel {

inline f_group_pos_set getGroupsPosToFlatten() {
auto childSchema = children[0]->getSchema();
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(
return factorization::FlattenAll::getGroupsPosToFlatten(
childSchema->getGroupsPosInScope(), childSchema);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LogicalDeleteRel : public LogicalUpdateRel {
auto childSchema = children[0]->getSchema();
result.insert(childSchema->getGroupPos(*rel->getSrcNode()->getInternalIDProperty()));
result.insert(childSchema->getGroupPos(*rel->getDstNode()->getInternalIDProperty()));
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(result, childSchema);
return factorization::FlattenAll::getGroupsPosToFlatten(result, childSchema);
}

inline std::unique_ptr<LogicalOperator> copy() override {
Expand Down
4 changes: 2 additions & 2 deletions src/optimizer/factorization_rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void FactorizationRewriter::visitProjection(planner::LogicalOperator* op) {
auto projection = (LogicalProjection*)op;
for (auto& expression : projection->getExpressionsToProject()) {
auto dependentGroupsPos = op->getChild(0)->getSchema()->getDependentGroupsPos(expression);
auto groupsPosToFlatten = FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
auto groupsPosToFlatten = factorization::FlattenAllButOne::getGroupsPosToFlatten(
dependentGroupsPos, op->getChild(0)->getSchema());
projection->setChild(0, appendFlattens(projection->getChild(0), groupsPosToFlatten));
}
Expand Down Expand Up @@ -185,7 +185,7 @@ void FactorizationRewriter::visitSetNodeProperty(planner::LogicalOperator* op) {
auto rhs = setNodeProperty->getSetItem(i).second;
// flatten rhs
auto rhsDependentGroupsPos = op->getChild(0)->getSchema()->getDependentGroupsPos(rhs);
auto rhsGroupsPosToFlatten = FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
auto rhsGroupsPosToFlatten = factorization::FlattenAllButOne::getGroupsPosToFlatten(
rhsDependentGroupsPos, op->getChild(0)->getSchema());
setNodeProperty->setChild(
0, appendFlattens(setNodeProperty->getChild(0), rhsGroupsPosToFlatten));
Expand Down
16 changes: 8 additions & 8 deletions src/planner/operator/factorization_resolver.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
#include "planner/logical_plan/logical_operator/factorization_resolver.h"

#include "planner/logical_plan/logical_operator/logical_flatten.h"

namespace kuzu {
namespace planner {
namespace factorization {

std::unordered_set<f_group_pos> FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
const std::unordered_set<f_group_pos>& groupsPos, Schema* schema) {
f_group_pos_set FlattenAllButOne::getGroupsPosToFlatten(
const f_group_pos_set& groupsPos, Schema* schema) {
std::vector<f_group_pos> unFlatGroupsPos;
for (auto groupPos : groupsPos) {
if (!schema->getGroup(groupPos)->isFlat()) {
unFlatGroupsPos.push_back(groupPos);
}
}
std::unordered_set<f_group_pos> result;
f_group_pos_set result;
// Keep the first group as unFlat.
for (auto i = 1u; i < unFlatGroupsPos.size(); ++i) {
result.insert(unFlatGroupsPos[i]);
}
return result;
}

std::unordered_set<f_group_pos> FlattenAllFactorizationSolver::getGroupsPosToFlatten(
const std::unordered_set<f_group_pos>& groupsPos, Schema* schema) {
std::unordered_set<f_group_pos> result;
f_group_pos_set FlattenAll::getGroupsPosToFlatten(
const f_group_pos_set& groupsPos, Schema* schema) {
f_group_pos_set result;
for (auto groupPos : groupsPos) {
if (!schema->getGroup(groupPos)->isFlat()) {
result.insert(groupPos);
Expand All @@ -32,5 +31,6 @@ std::unordered_set<f_group_pos> FlattenAllFactorizationSolver::getGroupsPosToFla
return result;
}

} // namespace factorization
} // namespace planner
} // namespace kuzu
10 changes: 5 additions & 5 deletions src/planner/operator/logical_aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace kuzu {
namespace planner {

using namespace factorization;

f_group_pos_set LogicalAggregate::getGroupsPosToFlattenForGroupBy() {
f_group_pos_set dependentGroupsPos;
for (auto& expression : expressionsToGroupBy) {
Expand All @@ -14,10 +16,9 @@ f_group_pos_set LogicalAggregate::getGroupsPosToFlattenForGroupBy() {
}
}
if (hasDistinctAggregate()) {
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(
dependentGroupsPos, children[0]->getSchema());
return FlattenAll::getGroupsPosToFlatten(dependentGroupsPos, children[0]->getSchema());
} else {
return FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
return FlattenAllButOne::getGroupsPosToFlatten(
dependentGroupsPos, children[0]->getSchema());
}
}
Expand All @@ -30,8 +31,7 @@ f_group_pos_set LogicalAggregate::getGroupsPosToFlattenForAggregate() {
dependentGroupsPos.insert(groupPos);
}
}
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(
dependentGroupsPos, children[0]->getSchema());
return FlattenAll::getGroupsPosToFlatten(dependentGroupsPos, children[0]->getSchema());
}
return f_group_pos_set{};
}
Expand Down
2 changes: 1 addition & 1 deletion src/planner/operator/logical_distinct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ f_group_pos_set LogicalDistinct::getGroupsPosToFlatten() {
dependentGroupsPos.insert(groupPos);
}
}
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(dependentGroupsPos, childSchema);
return factorization::FlattenAll::getGroupsPosToFlatten(dependentGroupsPos, childSchema);
}

std::string LogicalDistinct::getExpressionsForPrinting() const {
Expand Down
3 changes: 1 addition & 2 deletions src/planner/operator/logical_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace planner {
f_group_pos_set LogicalFilter::getGroupsPosToFlatten() {
auto childSchema = children[0]->getSchema();
auto dependentGroupsPos = childSchema->getDependentGroupsPos(expression);
return FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
dependentGroupsPos, childSchema);
return factorization::FlattenAllButOne::getGroupsPosToFlatten(dependentGroupsPos, childSchema);
}

f_group_pos LogicalFilter::getGroupPosToSelect() const {
Expand Down
3 changes: 1 addition & 2 deletions src/planner/operator/logical_hash_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ f_group_pos_set LogicalHashJoin::getGroupsPosToFlattenOnBuildSide() {
for (auto& joinNodeID : joinNodeIDs) {
joinNodesGroupPos.insert(buildSchema->getGroupPos(*joinNodeID));
}
return FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
joinNodesGroupPos, buildSchema);
return factorization::FlattenAllButOne::getGroupsPosToFlatten(joinNodesGroupPos, buildSchema);
}

void LogicalHashJoin::computeSchema() {
Expand Down
2 changes: 1 addition & 1 deletion src/planner/operator/logical_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace planner {

f_group_pos_set LogicalLimit::getGroupsPosToFlatten() {
auto childSchema = children[0]->getSchema();
return FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
return factorization::FlattenAllButOne::getGroupsPosToFlatten(
childSchema->getGroupsPosInScope(), childSchema);
}

Expand Down
3 changes: 1 addition & 2 deletions src/planner/operator/logical_order_by.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ f_group_pos_set LogicalOrderBy::getGroupsPosToFlatten() {
dependentGroupsPos.insert(groupPos);
}
}
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(
dependentGroupsPos, childSchema);
return factorization::FlattenAll::getGroupsPosToFlatten(dependentGroupsPos, childSchema);
}
return f_group_pos_set{};
}
Expand Down
2 changes: 1 addition & 1 deletion src/planner/operator/logical_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ f_group_pos_set LogicalSetRelProperty::getGroupsPosToFlatten(uint32_t setItemIdx
for (auto groupPos : childSchema->getDependentGroupsPos(rhs)) {
result.insert(groupPos);
}
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(result, childSchema);
return factorization::FlattenAll::getGroupsPosToFlatten(result, childSchema);
}

} // namespace planner
Expand Down
2 changes: 1 addition & 1 deletion src/planner/operator/logical_skip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace planner {

f_group_pos_set LogicalSkip::getGroupsPosToFlatten() {
auto childSchema = children[0]->getSchema();
return FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
return factorization::FlattenAllButOne::getGroupsPosToFlatten(
childSchema->getGroupsPosInScope(), childSchema);
}

Expand Down
2 changes: 1 addition & 1 deletion src/planner/operator/logical_union.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ f_group_pos_set LogicalUnion::getGroupsPosToFlatten(uint32_t childIdx) {
groupsPos.insert(childSchema->getGroupPos(*expression));
}
}
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(groupsPos, childSchema);
return factorization::FlattenAll::getGroupsPosToFlatten(groupsPos, childSchema);
}

void LogicalUnion::computeSchema() {
Expand Down
2 changes: 1 addition & 1 deletion src/planner/operator/logical_unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace planner {
f_group_pos_set LogicalUnwind::getGroupsPosToFlatten() {
auto childSchema = children[0]->getSchema();
auto dependentGroupsPos = childSchema->getDependentGroupsPos(expression);
return FlattenAllFactorizationSolver::getGroupsPosToFlatten(dependentGroupsPos, childSchema);
return factorization::FlattenAll::getGroupsPosToFlatten(dependentGroupsPos, childSchema);
}

void LogicalUnwind::computeSchema() {
Expand Down
2 changes: 1 addition & 1 deletion src/planner/projection_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void ProjectionPlanner::appendProjection(
}
for (auto& expression : expressionsToProject) {
auto dependentGroupsPos = plan.getSchema()->getDependentGroupsPos(expression);
auto groupsPosToFlatten = FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
auto groupsPosToFlatten = factorization::FlattenAllButOne::getGroupsPosToFlatten(
dependentGroupsPos, plan.getSchema());
QueryPlanner::appendFlattens(groupsPosToFlatten, plan);
}
Expand Down
2 changes: 1 addition & 1 deletion src/planner/update_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void UpdatePlanner::appendSetNodeProperty(
auto rhs = setItems[i].second;
// flatten rhs
auto rhsDependentGroupsPos = plan.getSchema()->getDependentGroupsPos(rhs);
auto rhsGroupsPosToFlatten = FlattenAllButOneFactorizationSolver::getGroupsPosToFlatten(
auto rhsGroupsPosToFlatten = factorization::FlattenAllButOne::getGroupsPosToFlatten(
rhsDependentGroupsPos, plan.getSchema());
QueryPlanner::appendFlattens(rhsGroupsPosToFlatten, plan);
// flatten lhs if needed
Expand Down

0 comments on commit 0096f2e

Please sign in to comment.