Skip to content
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

Fix rel delete and create #2427

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/include/processor/operator/persistent/delete_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class NodeDeleteExecutor {
common::ValueVector* nodeIDVector;
};

class SingleLabelNodeDeleteExecutor : public NodeDeleteExecutor {
class SingleLabelNodeDeleteExecutor final : public NodeDeleteExecutor {
public:
SingleLabelNodeDeleteExecutor(storage::NodeTable* table, const DataPos& nodeIDPos)
: NodeDeleteExecutor(nodeIDPos), table{table} {}
SingleLabelNodeDeleteExecutor(const SingleLabelNodeDeleteExecutor& other)
: NodeDeleteExecutor(other.nodeIDPos), table{other.table} {}

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

inline std::unique_ptr<NodeDeleteExecutor> copy() const final {
inline std::unique_ptr<NodeDeleteExecutor> copy() const override {
return std::make_unique<SingleLabelNodeDeleteExecutor>(*this);
}

Expand All @@ -44,7 +44,7 @@ class SingleLabelNodeDeleteExecutor : public NodeDeleteExecutor {
std::unique_ptr<common::ValueVector> pkVector;
};

class MultiLabelNodeDeleteExecutor : public NodeDeleteExecutor {
class MultiLabelNodeDeleteExecutor final : public NodeDeleteExecutor {
public:
MultiLabelNodeDeleteExecutor(
std::unordered_map<common::table_id_t, storage::NodeTable*> tableIDToTableMap,
Expand All @@ -53,10 +53,10 @@ class MultiLabelNodeDeleteExecutor : public NodeDeleteExecutor {
MultiLabelNodeDeleteExecutor(const MultiLabelNodeDeleteExecutor& other)
: NodeDeleteExecutor(other.nodeIDPos), tableIDToTableMap{other.tableIDToTableMap} {}

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

inline std::unique_ptr<NodeDeleteExecutor> copy() const final {
inline std::unique_ptr<NodeDeleteExecutor> copy() const override {
return std::make_unique<MultiLabelNodeDeleteExecutor>(*this);
}

Expand All @@ -75,7 +75,7 @@ class RelDeleteExecutor {

void init(ResultSet* resultSet, ExecutionContext* context);

virtual void delete_() = 0;
virtual void delete_(ExecutionContext* context) = 0;

virtual std::unique_ptr<RelDeleteExecutor> copy() const = 0;

Expand All @@ -97,9 +97,9 @@ class SingleLabelRelDeleteExecutor final : public RelDeleteExecutor {
relsStatistic{relsStatistic}, table{table} {}
SingleLabelRelDeleteExecutor(const SingleLabelRelDeleteExecutor& other) = default;

void delete_();
void delete_(ExecutionContext* context) override;

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

Expand All @@ -119,9 +119,9 @@ class MultiLabelRelDeleteExecutor final : public RelDeleteExecutor {
tableIDToTableMap)} {}
MultiLabelRelDeleteExecutor(const MultiLabelRelDeleteExecutor& other) = default;

void delete_();
void delete_(ExecutionContext* context) override;

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

Expand Down
24 changes: 12 additions & 12 deletions src/include/processor/operator/persistent/set_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
common::column_id_t columnID;
};

class SingleLabelNodeSetExecutor : public NodeSetExecutor {
class SingleLabelNodeSetExecutor final : public NodeSetExecutor {
public:
SingleLabelNodeSetExecutor(NodeSetInfo setInfo, const DataPos& nodeIDPos,
const DataPos& lhsVectorPos, std::unique_ptr<evaluator::ExpressionEvaluator> evaluator)
Expand All @@ -52,17 +52,17 @@
: NodeSetExecutor{other.nodeIDPos, other.lhsVectorPos, other.evaluator->clone()},
setInfo(other.setInfo) {}

void set(ExecutionContext* context) final;
void set(ExecutionContext* context) override;

inline std::unique_ptr<NodeSetExecutor> copy() const final {
inline std::unique_ptr<NodeSetExecutor> copy() const override {
return std::make_unique<SingleLabelNodeSetExecutor>(*this);
}

private:
NodeSetInfo setInfo;
};

class MultiLabelNodeSetExecutor : public NodeSetExecutor {
class MultiLabelNodeSetExecutor final : public NodeSetExecutor {

Check warning on line 65 in src/include/processor/operator/persistent/set_executor.h

View check run for this annotation

Codecov / codecov/patch

src/include/processor/operator/persistent/set_executor.h#L65

Added line #L65 was not covered by tests
public:
MultiLabelNodeSetExecutor(std::unordered_map<common::table_id_t, NodeSetInfo> tableIDToSetInfo,
const DataPos& nodeIDPos, const DataPos& lhsVectorPos,
Expand All @@ -73,9 +73,9 @@
: NodeSetExecutor{other.nodeIDPos, other.lhsVectorPos, other.evaluator->clone()},
tableIDToSetInfo{other.tableIDToSetInfo} {}

void set(ExecutionContext* context) final;
void set(ExecutionContext* context) override;

inline std::unique_ptr<NodeSetExecutor> copy() const final {
inline std::unique_ptr<NodeSetExecutor> copy() const override {
return std::make_unique<MultiLabelNodeSetExecutor>(*this);
}

Expand Down Expand Up @@ -116,7 +116,7 @@
common::ValueVector* rhsVector = nullptr;
};

class SingleLabelRelSetExecutor : public RelSetExecutor {
class SingleLabelRelSetExecutor final : public RelSetExecutor {
public:
SingleLabelRelSetExecutor(storage::RelTable* table, common::column_id_t columnID,
const DataPos& srcNodeIDPos, const DataPos& dstNodeIDPos, const DataPos& relIDPos,
Expand All @@ -128,9 +128,9 @@
other.evaluator->clone()},
table{other.table}, columnID{other.columnID} {}

void set(ExecutionContext* context) final;
void set(ExecutionContext* context) override;

inline std::unique_ptr<RelSetExecutor> copy() const final {
inline std::unique_ptr<RelSetExecutor> copy() const override {
return std::make_unique<SingleLabelRelSetExecutor>(*this);
}

Expand All @@ -139,7 +139,7 @@
common::column_id_t columnID;
};

class MultiLabelRelSetExecutor : public RelSetExecutor {
class MultiLabelRelSetExecutor final : public RelSetExecutor {

Check warning on line 142 in src/include/processor/operator/persistent/set_executor.h

View check run for this annotation

Codecov / codecov/patch

src/include/processor/operator/persistent/set_executor.h#L142

Added line #L142 was not covered by tests
public:
MultiLabelRelSetExecutor(
std::unordered_map<common::table_id_t, std::pair<storage::RelTable*, common::column_id_t>>
Expand All @@ -153,9 +153,9 @@
other.evaluator->clone()},
tableIDToTableAndColumnID{other.tableIDToTableAndColumnID} {}

void set(ExecutionContext* context) final;
void set(ExecutionContext* context) override;

inline std::unique_ptr<RelSetExecutor> copy() const final {
inline std::unique_ptr<RelSetExecutor> copy() const override {
return std::make_unique<MultiLabelRelSetExecutor>(*this);
}

Expand Down
19 changes: 11 additions & 8 deletions src/include/storage/local_storage/local_rel_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ struct RegularRelNGInfo final : public RelNGInfo {
}

void insert(common::offset_t srcNodeOffset, common::offset_t relOffset,
common::row_idx_t adjNodeRowIdx, const std::vector<common::row_idx_t>& propertyNodesRowIdx);
common::row_idx_t adjNodeRowIdx,
const std::vector<common::row_idx_t>& propertyNodesRowIdx) override;
void update(common::offset_t srcNodeOffset, common::offset_t relOffset,
common::column_id_t columnID, common::row_idx_t rowIdx);
bool delete_(common::offset_t srcNodeOffset, common::offset_t relOffset);
common::column_id_t columnID, common::row_idx_t rowIdx) override;
bool delete_(common::offset_t srcNodeOffset, common::offset_t relOffset) final;
};

// Info of node groups with CSR chunks for rel tables.
Expand All @@ -58,10 +59,11 @@ struct CSRRelNGInfo final : public RelNGInfo {
}

void insert(common::offset_t srcNodeOffset, common::offset_t relOffset,
common::row_idx_t adjNodeRowIdx, const std::vector<common::row_idx_t>& propertyNodesRowIdx);
common::row_idx_t adjNodeRowIdx,
const std::vector<common::row_idx_t>& propertyNodesRowIdx) override;
void update(common::offset_t srcNodeOffset, common::offset_t relOffset,
common::column_id_t columnID, common::row_idx_t rowIdx);
bool delete_(common::offset_t srcNodeOffset, common::offset_t relOffset);
common::column_id_t columnID, common::row_idx_t rowIdx) override;
bool delete_(common::offset_t srcNodeOffset, common::offset_t relOffset) override;
};

class LocalRelNG final : public LocalNodeGroup {
Expand All @@ -73,7 +75,7 @@ class LocalRelNG final : public LocalNodeGroup {
const std::vector<common::ValueVector*>& propertyVectors);
void update(common::ValueVector* srcNodeIDVector, common::ValueVector* relIDVector,
common::column_id_t columnID, common::ValueVector* propertyVector);
void delete_(common::ValueVector* srcNodeIDVector, common::ValueVector* relIDVector);
bool delete_(common::ValueVector* srcNodeIDVector, common::ValueVector* relIDVector);

inline LocalVectorCollection* getAdjChunk() { return adjChunk.get(); }
inline LocalVectorCollection* getPropertyChunk(common::column_id_t columnID) {
Expand All @@ -99,7 +101,8 @@ class LocalRelTableData final : public LocalTableData {
const std::vector<common::ValueVector*>& propertyVectors);
void update(common::ValueVector* srcNodeIDVector, common::ValueVector* relIDVector,
common::column_id_t columnID, common::ValueVector* propertyVector);
void delete_(common::ValueVector* srcNodeIDVector, common::ValueVector* relIDVector);
bool delete_(common::ValueVector* srcNodeIDVector, common::ValueVector* dstNodeIDVector,
common::ValueVector* relIDVector);

private:
LocalNodeGroup* getOrCreateLocalNodeGroup(common::ValueVector* nodeIDVector);
Expand Down
6 changes: 3 additions & 3 deletions src/include/storage/local_storage/local_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class LocalVector {
// contains 64 vectors (chunks).
class LocalVectorCollection {
public:
LocalVectorCollection(const common::LogicalType* dataType, MemoryManager* mm)
: dataType{dataType}, mm{mm}, numRows{0} {}
LocalVectorCollection(std::unique_ptr<common::LogicalType> dataType, MemoryManager* mm)
: dataType{std::move(dataType)}, mm{mm}, numRows{0} {}

void read(common::row_idx_t rowIdx, common::ValueVector* outputVector,
common::sel_t posInOutputVector);
Expand All @@ -65,7 +65,7 @@ class LocalVectorCollection {
void prepareAppend();

private:
const common::LogicalType* dataType;
std::unique_ptr<common::LogicalType> dataType;
MemoryManager* mm;
std::vector<std::unique_ptr<LocalVector>> vectors;
common::row_idx_t numRows;
Expand Down
9 changes: 7 additions & 2 deletions src/include/storage/store/rel_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ class RelTable : public Table {
common::ValueVector* inNodeIDVector, RelDataReadState* readState) {
return direction == common::RelDataDirection::FWD ?
fwdRelTableData->initializeReadState(
transaction, direction, columnIDs, inNodeIDVector, readState) :
transaction, columnIDs, inNodeIDVector, readState) :
bwdRelTableData->initializeReadState(
transaction, direction, columnIDs, inNodeIDVector, readState);
transaction, columnIDs, inNodeIDVector, readState);
}
void read(transaction::Transaction* transaction, TableReadState& readState,
common::ValueVector* inNodeIDVector,
const std::vector<common::ValueVector*>& outputVectors) final;

void insert(transaction::Transaction* transaction, common::ValueVector* srcNodeIDVector,
common::ValueVector* dstNodeIDVector,
const std::vector<common::ValueVector*>& propertyVectors);
void update(transaction::Transaction* transaction, common::column_id_t columnID,
common::ValueVector* srcNodeIDVector, common::ValueVector* dstNodeIDVector,
common::ValueVector* relIDVector, common::ValueVector* propertyVector);
void delete_(transaction::Transaction* transaction, common::ValueVector* srcNodeIDVector,
common::ValueVector* dstNodeIDVector, common::ValueVector* relIDVector);

void addColumn(transaction::Transaction* transaction, const catalog::Property& property,
common::ValueVector* defaultValueVector) final;
Expand Down
20 changes: 18 additions & 2 deletions src/include/storage/store/rel_table_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class RelTableData final : public TableData {
common::RelDataDirection direction, bool enableCompression);

void initializeReadState(transaction::Transaction* transaction,
common::RelDataDirection direction, std::vector<common::column_id_t> columnIDs,
common::ValueVector* inNodeIDVector, RelDataReadState* readState);
std::vector<common::column_id_t> columnIDs, common::ValueVector* inNodeIDVector,
RelDataReadState* readState);
inline void scan(transaction::Transaction* transaction, TableReadState& readState,
common::ValueVector* inNodeIDVector,
const std::vector<common::ValueVector*>& outputVectors) {
Expand All @@ -57,9 +57,14 @@ class RelTableData final : public TableData {
common::ValueVector* inNodeIDVector,
const std::vector<common::ValueVector*>& outputVectors);

void insert(transaction::Transaction* transaction, common::ValueVector* srcNodeIDVector,
common::ValueVector* dstNodeIDVector,
const std::vector<common::ValueVector*>& propertyVectors);
void update(transaction::Transaction* transaction, common::column_id_t columnID,
common::ValueVector* srcNodeIDVector, common::ValueVector* relIDVector,
common::ValueVector* propertyVector);
bool delete_(transaction::Transaction* transaction, common::ValueVector* srcNodeIDVector,
common::ValueVector* dstNodeIDVector, common::ValueVector* relIDVector);

void append(NodeGroup* nodeGroup);

Expand Down Expand Up @@ -87,6 +92,17 @@ class RelTableData final : public TableData {
void prepareCommitCSRNGWithoutSliding(transaction::Transaction* transaction,
common::node_group_idx_t nodeGroupIdx, CSRRelNGInfo* relNodeGroupInfo,
ColumnChunk* csrOffsetChunk, ColumnChunk* relIDChunk, LocalRelNG* localNodeGroup);
void prepareCommitCSRNGWithSliding(transaction::Transaction* transaction,
common::node_group_idx_t nodeGroupIdx, CSRRelNGInfo* relNodeGroupInfo,
ColumnChunk* csrOffsetChunk, ColumnChunk* relIDChunk, LocalRelNG* localNodeGroup);

std::unique_ptr<ColumnChunk> slideCSROffsetColumnChunk(ColumnChunk* csrOffsetChunk,
CSRRelNGInfo* relNodeGroupInfo, common::offset_t nodeGroupStartOffset);
std::unique_ptr<ColumnChunk> slideCSRColumnChunk(transaction::Transaction* transaction,
ColumnChunk* csrOffsetChunk, ColumnChunk* slidedCSROffsetChunkForCheck,
ColumnChunk* relIDChunk, const offset_to_offset_to_row_idx_t& insertInfo,
const offset_to_offset_to_row_idx_t& updateInfo, const offset_to_offset_set_t& deleteInfo,
common::node_group_idx_t nodeGroupIdx, Column* column, LocalVectorCollection* localChunk);

static inline common::ColumnDataFormat getDataFormatFromSchema(
catalog::RelTableSchema* tableSchema, common::RelDataDirection direction) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/operator/persistent/delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool DeleteRel::getNextTuplesInternal(ExecutionContext* context) {
return false;
}
for (auto& executor : executors) {
executor->delete_();
executor->delete_(context);
}
return true;
}
Expand Down
15 changes: 6 additions & 9 deletions src/processor/operator/persistent/delete_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,19 @@ void RelDeleteExecutor::init(ResultSet* resultSet, ExecutionContext* /*context*/
relIDVector = resultSet->getValueVector(relIDPos).get();
}

void SingleLabelRelDeleteExecutor::delete_() {
// TODO(Guodong): Fix delete.
// table->deleteRel(srcNodeIDVector, dstNodeIDVector, relIDVector);
// relsStatistic->updateNumRelsByValue(table->getTableID(), -1);
void SingleLabelRelDeleteExecutor::delete_(ExecutionContext* context) {
table->delete_(context->clientContext->getActiveTransaction(), srcNodeIDVector, dstNodeIDVector,
relIDVector);
}

void MultiLabelRelDeleteExecutor::delete_() {
void MultiLabelRelDeleteExecutor::delete_(ExecutionContext* context) {
KU_ASSERT(relIDVector->state->isFlat());
auto pos = relIDVector->state->selVector->selectedPositions[0];
auto relID = relIDVector->getValue<internalID_t>(pos);
KU_ASSERT(tableIDToTableMap.contains(relID.tableID));
auto [table, statistic] = tableIDToTableMap.at(relID.tableID);
// TODO(Guodong): Fix delete.
// table->deleteRel(srcNodeIDVector, dstNodeIDVector, relIDVector);
// KU_ASSERT(table->getTableID() == relID.tableID);
// statistic->updateNumRelsByValue(table->getTableID(), -1);
table->delete_(context->clientContext->getActiveTransaction(), srcNodeIDVector, dstNodeIDVector,
relIDVector);
}

} // namespace processor
Expand Down
4 changes: 1 addition & 3 deletions src/processor/operator/persistent/insert_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ void RelInsertExecutor::insert(transaction::Transaction* tx) {
for (auto i = 1; i < propertyRhsEvaluators.size(); ++i) {
propertyRhsEvaluators[i]->evaluate();
}
// TODO(Guodong): Fix insert.
// table->insertRel(srcNodeIDVector, dstNodeIDVector, propertyRhsVectors);
// relsStatistics.updateNumRelsByValue(table->getRelTableID(), 1);
table->insert(tx, srcNodeIDVector, dstNodeIDVector, propertyRhsVectors);
for (auto i = 0u; i < propertyLhsVectors.size(); ++i) {
auto lhsVector = propertyLhsVectors[i];
auto rhsVector = propertyRhsVectors[i];
Expand Down
Loading