Skip to content

Commit

Permalink
Add multi-label set
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Aug 2, 2023
1 parent baf9e56 commit 3f71578
Show file tree
Hide file tree
Showing 17 changed files with 532 additions and 215 deletions.
2 changes: 0 additions & 2 deletions src/binder/bind/bind_updating_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,10 @@ std::unique_ptr<BoundSetPropertyInfo> Binder::bindSetPropertyInfo(
auto left = expressionBinder.bindExpression(*setItem.first->getChild(0));
switch (left->dataType.getLogicalTypeID()) {
case LogicalTypeID::NODE: {
validateSetNodeProperty(*left);
return std::make_unique<BoundSetPropertyInfo>(
UpdateTableType::NODE, left, bindSetItem(setItem));
}
case LogicalTypeID::REL: {
validateSetRelProperty(*left);
return std::make_unique<BoundSetPropertyInfo>(
UpdateTableType::REL, left, bindSetItem(setItem));
}
Expand Down
90 changes: 46 additions & 44 deletions src/include/planner/logical_plan/logical_operator/logical_set.h
Original file line number Diff line number Diff line change
@@ -1,69 +1,71 @@
#pragma once

#include "base_logical_operator.h"
#include "logical_update.h"
#include "planner/logical_plan/logical_operator/flatten_resolver.h"

namespace kuzu {
namespace planner {

class LogicalSetNodeProperty : public LogicalUpdateNode {
public:
LogicalSetNodeProperty(std::vector<std::shared_ptr<binder::NodeExpression>> nodes,
std::vector<binder::expression_pair> setItems, std::shared_ptr<LogicalOperator> child)
: LogicalUpdateNode{LogicalOperatorType::SET_NODE_PROPERTY, std::move(nodes),
std::move(child)},
setItems{std::move(setItems)} {}

inline void computeFactorizedSchema() override { copyChildSchema(0); }
inline void computeFlatSchema() override { copyChildSchema(0); }

inline std::string getExpressionsForPrinting() const override {
std::string result;
for (auto& [lhs, rhs] : setItems) {
result += lhs->toString() + " = " + rhs->toString() + ",";
}
return result;
struct LogicalSetPropertyInfo {
std::shared_ptr<binder::Expression> nodeOrRel;
binder::expression_pair setItem;

LogicalSetPropertyInfo(
std::shared_ptr<binder::Expression> nodeOrRel, binder::expression_pair setItem)
: nodeOrRel{std::move(nodeOrRel)}, setItem{std::move(setItem)} {}
LogicalSetPropertyInfo(const LogicalSetPropertyInfo& other)
: nodeOrRel{other.nodeOrRel}, setItem{other.setItem} {}

inline std::unique_ptr<LogicalSetPropertyInfo> copy() const {
return std::make_unique<LogicalSetPropertyInfo>(*this);
}
};

class LogicalSetNodeProperty : public LogicalOperator {
public:
LogicalSetNodeProperty(std::vector<std::unique_ptr<LogicalSetPropertyInfo>> infos,
std::shared_ptr<LogicalOperator> child)
: LogicalOperator{LogicalOperatorType::SET_NODE_PROPERTY, std::move(child)},
infos{std::move(infos)} {}

inline binder::expression_pair getSetItem(size_t idx) const { return setItems[idx]; }
inline void computeFactorizedSchema() final { copyChildSchema(0); }
inline void computeFlatSchema() final { copyChildSchema(0); }

inline std::unique_ptr<LogicalOperator> copy() override {
return make_unique<LogicalSetNodeProperty>(nodes, setItems, children[0]->copy());
inline const std::vector<std::unique_ptr<LogicalSetPropertyInfo>>& getInfosRef() const {
return infos;
}

std::string getExpressionsForPrinting() const final;

std::unique_ptr<LogicalOperator> copy() final;

private:
std::vector<binder::expression_pair> setItems;
std::vector<std::unique_ptr<LogicalSetPropertyInfo>> infos;
};

class LogicalSetRelProperty : public LogicalUpdateRel {
class LogicalSetRelProperty : public LogicalOperator {
public:
LogicalSetRelProperty(std::vector<std::shared_ptr<binder::RelExpression>> rels,
std::vector<binder::expression_pair> setItems, std::shared_ptr<LogicalOperator> child)
: LogicalUpdateRel{LogicalOperatorType::SET_REL_PROPERTY, std::move(rels),
std::move(child)},
setItems{std::move(setItems)} {}

inline void computeFactorizedSchema() override { copyChildSchema(0); }
inline void computeFlatSchema() override { copyChildSchema(0); }

f_group_pos_set getGroupsPosToFlatten(uint32_t setItemIdx);

inline std::string getExpressionsForPrinting() const override {
std::string result;
for (auto& [lhs, rhs] : setItems) {
result += lhs->toString() + " = " + rhs->toString() + ",";
}
return result;
}
LogicalSetRelProperty(std::vector<std::unique_ptr<LogicalSetPropertyInfo>> infos,
std::shared_ptr<LogicalOperator> child)
: LogicalOperator{LogicalOperatorType::SET_REL_PROPERTY, std::move(child)}, infos{std::move(
infos)} {}

inline binder::expression_pair getSetItem(size_t idx) const { return setItems[idx]; }
inline void computeFactorizedSchema() final { copyChildSchema(0); }
inline void computeFlatSchema() final { copyChildSchema(0); }

inline std::unique_ptr<LogicalOperator> copy() override {
return make_unique<LogicalSetRelProperty>(rels, setItems, children[0]->copy());
inline const std::vector<std::unique_ptr<LogicalSetPropertyInfo>>& getInfosRef() const {
return infos;
}

f_group_pos_set getGroupsPosToFlatten(uint32_t idx);

std::string getExpressionsForPrinting() const final;

std::unique_ptr<LogicalOperator> copy() final;

private:
std::vector<binder::expression_pair> setItems;
std::vector<std::unique_ptr<LogicalSetPropertyInfo>> infos;
};

} // namespace planner
Expand Down
4 changes: 2 additions & 2 deletions src/include/planner/query_planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class QueryPlanner {
void appendCreateRel(
const std::vector<binder::BoundCreateInfo*>& createInfos, LogicalPlan& plan);
void appendSetNodeProperty(
const std::vector<binder::BoundSetPropertyInfo*>& infos, LogicalPlan& plan);
const std::vector<binder::BoundSetPropertyInfo*>& boundInfos, LogicalPlan& plan);
void appendSetRelProperty(
const std::vector<binder::BoundSetPropertyInfo*>& infos, LogicalPlan& plan);
const std::vector<binder::BoundSetPropertyInfo*>& boundInfos, LogicalPlan& plan);
void appendDeleteNode(
const std::vector<binder::BoundDeleteInfo*>& boundInfos, LogicalPlan& plan);
void appendDeleteRel(
Expand Down
90 changes: 29 additions & 61 deletions src/include/processor/operator/update/set.h
Original file line number Diff line number Diff line change
@@ -1,94 +1,62 @@
#pragma once

#include "expression_evaluator/base_evaluator.h"
#include "processor/operator/physical_operator.h"
#include "storage/store/node_table.h"
#include "storage/store/rel_table.h"
#include "set_executor.h"

namespace kuzu {
namespace processor {

class SetNodePropertyInfo {
public:
SetNodePropertyInfo(storage::NodeTable* table, common::property_id_t propertyID,
const DataPos& nodeIDPos, std::unique_ptr<evaluator::BaseExpressionEvaluator> evaluator)
: table{table}, propertyID{propertyID}, nodeIDPos{nodeIDPos}, evaluator{
std::move(evaluator)} {}

inline std::unique_ptr<SetNodePropertyInfo> clone() const {
return make_unique<SetNodePropertyInfo>(table, propertyID, nodeIDPos, evaluator->clone());
}

storage::NodeTable* table;
common::property_id_t propertyID;
DataPos nodeIDPos;
std::unique_ptr<evaluator::BaseExpressionEvaluator> evaluator;
};
// class SetNodePropertyInfo {
// public:
// SetNodePropertyInfo(storage::NodeTable* table, common::property_id_t propertyID,
// const DataPos& nodeIDPos, std::unique_ptr<evaluator::BaseExpressionEvaluator> evaluator)
// : table{table}, propertyID{propertyID}, nodeIDPos{nodeIDPos}, evaluator{
// std::move(evaluator)} {}
//
// inline std::unique_ptr<SetNodePropertyInfo> clone() const {
// return make_unique<SetNodePropertyInfo>(table, propertyID, nodeIDPos, evaluator->clone());
// }
//
// storage::NodeTable* table;
// common::property_id_t propertyID;
// DataPos nodeIDPos;
// std::unique_ptr<evaluator::BaseExpressionEvaluator> evaluator;
//};

class SetNodeProperty : public PhysicalOperator {
public:
SetNodeProperty(std::vector<std::unique_ptr<SetNodePropertyInfo>> infos,
SetNodeProperty(std::vector<std::unique_ptr<NodeSetExecutor>> executors,
std::unique_ptr<PhysicalOperator> child, uint32_t id, const std::string& paramsString)
: PhysicalOperator{PhysicalOperatorType::SET_NODE_PROPERTY, std::move(child), id,
paramsString},
infos{std::move(infos)} {}

~SetNodeProperty() override = default;
executors{std::move(executors)} {}

void initLocalStateInternal(ResultSet* resultSet, ExecutionContext* context) override;
void initLocalStateInternal(ResultSet* resultSet, ExecutionContext* context) final;

bool getNextTuplesInternal(ExecutionContext* context) override;
bool getNextTuplesInternal(ExecutionContext* context) final;

std::unique_ptr<PhysicalOperator> clone() override;
std::unique_ptr<PhysicalOperator> clone() final;

private:
std::vector<std::unique_ptr<SetNodePropertyInfo>> infos;

std::vector<common::ValueVector*> nodeIDVectors;
};

struct SetRelPropertyInfo {
storage::RelTable* table;
DataPos srcNodePos;
DataPos dstNodePos;
DataPos relIDPos;
common::property_id_t propertyId;
std::unique_ptr<evaluator::BaseExpressionEvaluator> evaluator;

SetRelPropertyInfo(storage::RelTable* table, const DataPos& srcNodePos,
const DataPos& dstNodePos, const DataPos& relIDPos, common::property_id_t propertyId,
std::unique_ptr<evaluator::BaseExpressionEvaluator> evaluator)
: table{table}, srcNodePos{srcNodePos}, dstNodePos{dstNodePos}, relIDPos{relIDPos},
propertyId{propertyId}, evaluator{std::move(evaluator)} {}

inline std::unique_ptr<SetRelPropertyInfo> clone() const {
return make_unique<SetRelPropertyInfo>(
table, srcNodePos, dstNodePos, relIDPos, propertyId, evaluator->clone());
}
std::vector<std::unique_ptr<NodeSetExecutor>> executors;
};

class SetRelProperty : public PhysicalOperator {
public:
SetRelProperty(std::vector<std::unique_ptr<SetRelPropertyInfo>> infos,
SetRelProperty(std::vector<std::unique_ptr<RelSetExecutor>> executors,
std::unique_ptr<PhysicalOperator> child, uint32_t id, const std::string& paramsString)
: PhysicalOperator{PhysicalOperatorType::SET_NODE_PROPERTY, std::move(child), id,
paramsString},
infos{std::move(infos)} {}

~SetRelProperty() override = default;
executors{std::move(executors)} {}

void initLocalStateInternal(ResultSet* resultSet, ExecutionContext* context) override;
void initLocalStateInternal(ResultSet* resultSet, ExecutionContext* context) final;

bool getNextTuplesInternal(ExecutionContext* context) override;
bool getNextTuplesInternal(ExecutionContext* context) final;

std::unique_ptr<PhysicalOperator> clone() override;
std::unique_ptr<PhysicalOperator> clone() final;

private:
std::vector<std::unique_ptr<SetRelPropertyInfo>> infos;

std::vector<common::ValueVector*> srcNodeVectors;
std::vector<common::ValueVector*> dstNodeVectors;
std::vector<common::ValueVector*> relIDVectors;
std::vector<std::unique_ptr<RelSetExecutor>> executors;
};

} // namespace processor
Expand Down
Loading

0 comments on commit 3f71578

Please sign in to comment.