-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1887 from kuzudb/create-refactor
Refactor create operators
- Loading branch information
Showing
17 changed files
with
392 additions
and
337 deletions.
There are no files selected for viewing
105 changes: 60 additions & 45 deletions
105
src/include/planner/logical_plan/logical_operator/logical_create.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,86 @@ | ||
#pragma once | ||
|
||
#include "flatten_resolver.h" | ||
#include "logical_update.h" | ||
#include "base_logical_operator.h" | ||
#include "binder/expression/rel_expression.h" | ||
|
||
namespace kuzu { | ||
namespace planner { | ||
|
||
class LogicalCreateNode : public LogicalUpdateNode { | ||
public: | ||
LogicalCreateNode(std::vector<std::shared_ptr<binder::NodeExpression>> nodes, | ||
binder::expression_vector primaryKeys, std::shared_ptr<LogicalOperator> child) | ||
: LogicalUpdateNode{LogicalOperatorType::CREATE_NODE, std::move(nodes), std::move(child)}, | ||
primaryKeys{std::move(primaryKeys)} {} | ||
~LogicalCreateNode() override = default; | ||
|
||
void computeFactorizedSchema() override; | ||
void computeFlatSchema() override; | ||
|
||
inline f_group_pos_set getGroupsPosToFlatten() { | ||
// 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 factorization::FlattenAll::getGroupsPosToFlatten( | ||
childSchema->getGroupsPosInScope(), childSchema); | ||
struct LogicalCreateNodeInfo { | ||
std::shared_ptr<binder::NodeExpression> node; | ||
std::shared_ptr<binder::Expression> primaryKey; | ||
|
||
LogicalCreateNodeInfo(std::shared_ptr<binder::NodeExpression> node, | ||
std::shared_ptr<binder::Expression> primaryKey) | ||
: node{std::move(node)}, primaryKey{std::move(primaryKey)} {} | ||
LogicalCreateNodeInfo(const LogicalCreateNodeInfo& other) | ||
: node{other.node}, primaryKey{other.primaryKey} {} | ||
|
||
inline std::unique_ptr<LogicalCreateNodeInfo> copy() const { | ||
return std::make_unique<LogicalCreateNodeInfo>(*this); | ||
} | ||
}; | ||
|
||
struct LogicalCreateRelInfo { | ||
std::shared_ptr<binder::RelExpression> rel; | ||
std::vector<binder::expression_pair> setItems; | ||
|
||
inline std::shared_ptr<binder::Expression> getPrimaryKey(size_t idx) const { | ||
return primaryKeys[idx]; | ||
LogicalCreateRelInfo( | ||
std::shared_ptr<binder::RelExpression> rel, std::vector<binder::expression_pair> setItems) | ||
: rel{std::move(rel)}, setItems{std::move(setItems)} {} | ||
LogicalCreateRelInfo(const LogicalCreateRelInfo& other) | ||
: rel{other.rel}, setItems{other.setItems} {} | ||
|
||
inline std::unique_ptr<LogicalCreateRelInfo> copy() const { | ||
return std::make_unique<LogicalCreateRelInfo>(*this); | ||
} | ||
}; | ||
|
||
class LogicalCreateNode : public LogicalOperator { | ||
public: | ||
LogicalCreateNode(std::vector<std::unique_ptr<LogicalCreateNodeInfo>> infos, | ||
std::shared_ptr<LogicalOperator> child) | ||
: LogicalOperator{LogicalOperatorType::CREATE_NODE, std::move(child)}, infos{std::move( | ||
infos)} {} | ||
|
||
void computeFactorizedSchema() final; | ||
void computeFlatSchema() final; | ||
|
||
std::string getExpressionsForPrinting() const final; | ||
|
||
inline std::unique_ptr<LogicalOperator> copy() override { | ||
return make_unique<LogicalCreateNode>(nodes, primaryKeys, children[0]->copy()); | ||
f_group_pos_set getGroupsPosToFlatten(); | ||
|
||
inline const std::vector<std::unique_ptr<LogicalCreateNodeInfo>>& getInfosRef() const { | ||
return infos; | ||
} | ||
|
||
std::unique_ptr<LogicalOperator> copy() final; | ||
|
||
private: | ||
binder::expression_vector primaryKeys; | ||
std::vector<std::unique_ptr<LogicalCreateNodeInfo>> infos; | ||
}; | ||
|
||
class LogicalCreateRel : public LogicalUpdateRel { | ||
class LogicalCreateRel : public LogicalOperator { | ||
public: | ||
LogicalCreateRel(std::vector<std::shared_ptr<binder::RelExpression>> rels, | ||
std::vector<std::vector<binder::expression_pair>> setItemsPerRel, | ||
LogicalCreateRel(std::vector<std::unique_ptr<LogicalCreateRelInfo>> infos, | ||
std::shared_ptr<LogicalOperator> child) | ||
: LogicalUpdateRel{LogicalOperatorType::CREATE_REL, std::move(rels), std::move(child)}, | ||
setItemsPerRel{std::move(setItemsPerRel)} {} | ||
~LogicalCreateRel() override = default; | ||
: LogicalOperator{LogicalOperatorType::CREATE_REL, std::move(child)}, infos{std::move( | ||
infos)} {} | ||
|
||
inline void computeFactorizedSchema() override { copyChildSchema(0); } | ||
inline void computeFlatSchema() override { copyChildSchema(0); } | ||
inline void computeFactorizedSchema() final { copyChildSchema(0); } | ||
inline void computeFlatSchema() final { copyChildSchema(0); } | ||
|
||
inline f_group_pos_set getGroupsPosToFlatten() { | ||
auto childSchema = children[0]->getSchema(); | ||
return factorization::FlattenAll::getGroupsPosToFlatten( | ||
childSchema->getGroupsPosInScope(), childSchema); | ||
} | ||
std::string getExpressionsForPrinting() const final; | ||
|
||
inline std::vector<binder::expression_pair> getSetItems(uint32_t idx) const { | ||
return setItemsPerRel[idx]; | ||
} | ||
f_group_pos_set getGroupsPosToFlatten(); | ||
|
||
inline std::unique_ptr<LogicalOperator> copy() override { | ||
return make_unique<LogicalCreateRel>(rels, setItemsPerRel, children[0]->copy()); | ||
} | ||
inline const std::vector<std::unique_ptr<LogicalCreateRelInfo>>& getInfosRef() { return infos; } | ||
|
||
std::unique_ptr<LogicalOperator> copy() final; | ||
|
||
private: | ||
std::vector<std::vector<binder::expression_pair>> setItemsPerRel; | ||
std::vector<std::unique_ptr<LogicalCreateRelInfo>> infos; | ||
}; | ||
|
||
} // namespace planner | ||
} // namespace kuzu | ||
} // namespace kuzu |
4 changes: 2 additions & 2 deletions
4
src/include/planner/logical_plan/logical_operator/logical_delete.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/include/planner/logical_plan/logical_operator/logical_set.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/include/planner/logical_plan/logical_operator/logical_update.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.