-
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 #2425 from kuzudb/fix-rel-updates
Fix rel updates
- Loading branch information
Showing
42 changed files
with
960 additions
and
383 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,11 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace kuzu { | ||
namespace common { | ||
|
||
enum class RelDataDirection : uint8_t { FWD = 0, BWD = 1 }; | ||
|
||
struct RelDataDirectionUtils { | ||
static inline std::vector<RelDataDirection> getRelDataDirections() { | ||
return std::vector<RelDataDirection>{RelDataDirection::FWD, RelDataDirection::BWD}; | ||
} | ||
|
||
static std::string relDataDirectionToString(RelDataDirection direction); | ||
}; | ||
|
||
} // namespace common | ||
} // namespace kuzu |
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include "local_table.h" | ||
|
||
namespace kuzu { | ||
namespace storage { | ||
|
||
class LocalNodeNG final : public LocalNodeGroup { | ||
public: | ||
LocalNodeNG(std::vector<common::LogicalType*> dataTypes, MemoryManager* mm) | ||
: LocalNodeGroup{dataTypes, mm} { | ||
insertInfo.resize(dataTypes.size()); | ||
updateInfo.resize(dataTypes.size()); | ||
} | ||
|
||
void scan(common::ValueVector* nodeIDVector, const std::vector<common::column_id_t>& columnIDs, | ||
const std::vector<common::ValueVector*>& outputVectors); | ||
void lookup(common::offset_t nodeOffset, common::column_id_t columnID, | ||
common::ValueVector* outputVector, common::sel_t posInOutputVector); | ||
void insert(common::ValueVector* nodeIDVector, | ||
const std::vector<common::ValueVector*>& propertyVectors); | ||
void update(common::ValueVector* nodeIDVector, common::column_id_t columnID, | ||
common::ValueVector* propertyVector); | ||
void delete_(common::ValueVector* nodeIDVector); | ||
|
||
common::row_idx_t getRowIdx(common::column_id_t columnID, common::offset_t nodeOffset); | ||
|
||
inline const offset_to_row_idx_t& getInsertInfoRef(common::column_id_t columnID) { | ||
KU_ASSERT(columnID < insertInfo.size()); | ||
return insertInfo[columnID]; | ||
} | ||
inline const offset_to_row_idx_t& getUpdateInfoRef(common::column_id_t columnID) { | ||
KU_ASSERT(columnID < updateInfo.size()); | ||
return updateInfo[columnID]; | ||
} | ||
|
||
private: | ||
std::vector<offset_to_row_idx_t> insertInfo; | ||
std::vector<offset_to_row_idx_t> updateInfo; | ||
}; | ||
|
||
class LocalNodeTableData final : public LocalTableData { | ||
public: | ||
LocalNodeTableData(std::vector<common::LogicalType*> dataTypes, MemoryManager* mm, | ||
common::ColumnDataFormat dataFormat) | ||
: LocalTableData{dataTypes, mm, dataFormat} {} | ||
|
||
void scan(common::ValueVector* nodeIDVector, const std::vector<common::column_id_t>& columnIDs, | ||
const std::vector<common::ValueVector*>& outputVectors); | ||
void lookup(common::ValueVector* nodeIDVector, | ||
const std::vector<common::column_id_t>& columnIDs, | ||
const std::vector<common::ValueVector*>& outputVectors); | ||
void insert(common::ValueVector* nodeIDVector, | ||
const std::vector<common::ValueVector*>& propertyVectors); | ||
void update(common::ValueVector* nodeIDVector, common::column_id_t columnID, | ||
common::ValueVector* propertyVector); | ||
void delete_(common::ValueVector* nodeIDVector); | ||
|
||
private: | ||
LocalNodeGroup* getOrCreateLocalNodeGroup(common::ValueVector* nodeIDVector); | ||
}; | ||
|
||
} // namespace storage | ||
} // namespace kuzu |
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#pragma once | ||
|
||
#include "common/column_data_format.h" | ||
#include "storage/local_storage/local_table.h" | ||
|
||
namespace kuzu { | ||
namespace storage { | ||
|
||
static constexpr common::column_id_t REL_ID_COLUMN_ID = 0; | ||
|
||
struct RelNGInfo { | ||
virtual ~RelNGInfo() = default; | ||
|
||
virtual void insert(common::offset_t srcNodeOffset, common::offset_t relOffset, | ||
common::row_idx_t adjNodeRowIdx, | ||
const std::vector<common::row_idx_t>& propertyNodesRowIdx) = 0; | ||
virtual void update(common::offset_t srcNodeOffset, common::offset_t relOffset, | ||
common::column_id_t columnID, common::row_idx_t rowIdx) = 0; | ||
virtual bool delete_(common::offset_t srcNodeOffset, common::offset_t relOffset) = 0; | ||
|
||
protected: | ||
inline static bool contains( | ||
const std::unordered_set<common::offset_t>& set, common::offset_t value) { | ||
return set.find(value) != set.end(); | ||
} | ||
}; | ||
|
||
// Info of node groups with regular chunks for rel tables. | ||
struct RegularRelNGInfo final : public RelNGInfo { | ||
// Note that adj chunk cannot be directly updated. It can only be inserted or deleted. | ||
offset_to_row_idx_t adjInsertInfo; // insert info for adj chunk. | ||
std::vector<offset_to_row_idx_t> insertInfoPerChunk; // insert info for property chunks. | ||
std::vector<offset_to_row_idx_t> updateInfoPerChunk; // insert info for property chunks. | ||
offset_set_t deleteInfo; // the set of deleted node offsets. | ||
|
||
RegularRelNGInfo(common::column_id_t numChunks) { | ||
insertInfoPerChunk.resize(numChunks); | ||
updateInfoPerChunk.resize(numChunks); | ||
} | ||
|
||
void insert(common::offset_t srcNodeOffset, common::offset_t relOffset, | ||
common::row_idx_t adjNodeRowIdx, const std::vector<common::row_idx_t>& propertyNodesRowIdx); | ||
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); | ||
}; | ||
|
||
// Info of node groups with CSR chunks for rel tables. | ||
struct CSRRelNGInfo final : public RelNGInfo { | ||
offset_to_offset_to_row_idx_t adjInsertInfo; | ||
std::vector<offset_to_offset_to_row_idx_t> insertInfoPerChunk; | ||
std::vector<offset_to_offset_to_row_idx_t> updateInfoPerChunk; | ||
offset_to_offset_set_t deleteInfo; | ||
|
||
CSRRelNGInfo(common::column_id_t numChunks) { | ||
insertInfoPerChunk.resize(numChunks); | ||
updateInfoPerChunk.resize(numChunks); | ||
} | ||
|
||
void insert(common::offset_t srcNodeOffset, common::offset_t relOffset, | ||
common::row_idx_t adjNodeRowIdx, const std::vector<common::row_idx_t>& propertyNodesRowIdx); | ||
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); | ||
}; | ||
|
||
class LocalRelNG final : public LocalNodeGroup { | ||
public: | ||
LocalRelNG(common::ColumnDataFormat dataFormat, std::vector<common::LogicalType*> dataTypes, | ||
MemoryManager* mm); | ||
|
||
void insert(common::ValueVector* srcNodeIDVector, common::ValueVector* dstNodeIDVector, | ||
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); | ||
|
||
inline LocalVectorCollection* getAdjChunk() { return adjChunk.get(); } | ||
inline LocalVectorCollection* getPropertyChunk(common::column_id_t columnID) { | ||
KU_ASSERT(columnID < chunks.size()); | ||
return chunks[columnID].get(); | ||
} | ||
inline RelNGInfo* getRelNGInfo() { return relNGInfo.get(); } | ||
|
||
private: | ||
std::unique_ptr<LocalVectorCollection> adjChunk; | ||
std::unique_ptr<RelNGInfo> relNGInfo; | ||
}; | ||
|
||
class LocalRelTableData final : public LocalTableData { | ||
friend class RelTableData; | ||
|
||
public: | ||
LocalRelTableData(std::vector<common::LogicalType*> dataTypes, MemoryManager* mm, | ||
common::ColumnDataFormat dataFormat) | ||
: LocalTableData{dataTypes, mm, dataFormat} {} | ||
|
||
void insert(common::ValueVector* srcNodeIDVector, common::ValueVector* dstNodeIDVector, | ||
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); | ||
|
||
private: | ||
LocalNodeGroup* getOrCreateLocalNodeGroup(common::ValueVector* nodeIDVector); | ||
}; | ||
|
||
} // namespace storage | ||
} // namespace kuzu |
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.