-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor create operators #1887
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line here.