Skip to content

Commit

Permalink
Merge pull request #1147 from kuzudb/remove-unstructured
Browse files Browse the repository at this point in the history
Clean up unstructured related code and force using property_id_t
  • Loading branch information
ray6080 committed Jan 6, 2023
2 parents 6ae651c + cdd9659 commit 9b478eb
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 215 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)

project(Kuzu VERSION 0.0.1 LANGUAGES CXX)
project(Kuzu VERSION 0.0.1.1 LANGUAGES CXX)

find_package(Threads REQUIRED)

Expand Down
29 changes: 15 additions & 14 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ uint64_t SerDeser::serializeValue<Property>(
const Property& value, FileInfo* fileInfo, uint64_t offset) {
offset = SerDeser::serializeValue<string>(value.name, fileInfo, offset);
offset = SerDeser::serializeValue<DataType>(value.dataType, fileInfo, offset);
offset = SerDeser::serializeValue<uint32_t>(value.propertyID, fileInfo, offset);
offset = SerDeser::serializeValue<property_id_t>(value.propertyID, fileInfo, offset);
return SerDeser::serializeValue<table_id_t>(value.tableID, fileInfo, offset);
}

Expand All @@ -70,7 +70,7 @@ uint64_t SerDeser::deserializeValue<Property>(
Property& value, FileInfo* fileInfo, uint64_t offset) {
offset = SerDeser::deserializeValue<string>(value.name, fileInfo, offset);
offset = SerDeser::deserializeValue<DataType>(value.dataType, fileInfo, offset);
offset = SerDeser::deserializeValue<uint32_t>(value.propertyID, fileInfo, offset);
offset = SerDeser::deserializeValue<property_id_t>(value.propertyID, fileInfo, offset);
return SerDeser::deserializeValue<table_id_t>(value.tableID, fileInfo, offset);
}

Expand Down Expand Up @@ -128,7 +128,7 @@ uint64_t SerDeser::serializeValue<NodeTableSchema>(
const NodeTableSchema& value, FileInfo* fileInfo, uint64_t offset) {
offset = SerDeser::serializeValue<string>(value.tableName, fileInfo, offset);
offset = SerDeser::serializeValue<table_id_t>(value.tableID, fileInfo, offset);
offset = SerDeser::serializeValue<uint64_t>(value.primaryKeyPropertyIdx, fileInfo, offset);
offset = SerDeser::serializeValue<property_id_t>(value.primaryKeyPropertyIdx, fileInfo, offset);
offset = SerDeser::serializeVector<Property>(value.properties, fileInfo, offset);
offset = SerDeser::serializeUnorderedSet<table_id_t>(value.fwdRelTableIDSet, fileInfo, offset);
return SerDeser::serializeUnorderedSet<table_id_t>(value.bwdRelTableIDSet, fileInfo, offset);
Expand All @@ -139,7 +139,8 @@ uint64_t SerDeser::deserializeValue<NodeTableSchema>(
NodeTableSchema& value, FileInfo* fileInfo, uint64_t offset) {
offset = SerDeser::deserializeValue<string>(value.tableName, fileInfo, offset);
offset = SerDeser::deserializeValue<table_id_t>(value.tableID, fileInfo, offset);
offset = SerDeser::deserializeValue<uint64_t>(value.primaryKeyPropertyIdx, fileInfo, offset);
offset =
SerDeser::deserializeValue<property_id_t>(value.primaryKeyPropertyIdx, fileInfo, offset);
offset = SerDeser::deserializeVector<Property>(value.properties, fileInfo, offset);
offset =
SerDeser::deserializeUnorderedSet<table_id_t>(value.fwdRelTableIDSet, fileInfo, offset);
Expand Down Expand Up @@ -199,16 +200,16 @@ CatalogContent::CatalogContent(const CatalogContent& other) {
nextTableID = other.nextTableID;
}

table_id_t CatalogContent::addNodeTableSchema(
string tableName, uint32_t primaryKeyIdx, vector<PropertyNameDataType> propertyDefinitions) {
table_id_t CatalogContent::addNodeTableSchema(string tableName, property_id_t primaryKeyId,
vector<PropertyNameDataType> propertyDefinitions) {
table_id_t tableID = assignNextTableID();
vector<Property> properties;
for (auto i = 0u; i < propertyDefinitions.size(); ++i) {
auto& propertyDefinition = propertyDefinitions[i];
properties.push_back(Property::constructNodeProperty(propertyDefinition, i, tableID));
}
auto nodeTableSchema = make_unique<NodeTableSchema>(
std::move(tableName), tableID, primaryKeyIdx, std::move(properties));
std::move(tableName), tableID, primaryKeyId, std::move(properties));
nodeTableNameToIDMap[nodeTableSchema->tableName] = tableID;
nodeTableSchemas[tableID] = std::move(nodeTableSchema);
return tableID;
Expand Down Expand Up @@ -341,7 +342,7 @@ void CatalogContent::removeTableSchema(TableSchema* tableSchema) {
}
}

Catalog::Catalog() {
Catalog::Catalog() : wal{nullptr} {
catalogContentForReadOnlyTrx = make_unique<CatalogContent>();
builtInVectorOperations = make_unique<BuiltInVectorOperations>();
builtInAggregateFunctions = make_unique<BuiltInAggregateFunctions>();
Expand Down Expand Up @@ -370,21 +371,21 @@ ExpressionType Catalog::getFunctionType(const string& name) const {
}
}

table_id_t Catalog::addNodeTableSchema(
string tableName, uint32_t primaryKeyIdx, vector<PropertyNameDataType> propertyDefinitions) {
table_id_t Catalog::addNodeTableSchema(string tableName, property_id_t primaryKeyId,
vector<PropertyNameDataType> propertyDefinitions) {
initCatalogContentForWriteTrxIfNecessary();
auto tableID = catalogContentForWriteTrx->addNodeTableSchema(
std::move(tableName), primaryKeyIdx, std::move(propertyDefinitions));
std::move(tableName), primaryKeyId, std::move(propertyDefinitions));
wal->logNodeTableRecord(tableID);
return tableID;
}

table_id_t Catalog::addRelTableSchema(string tableName, RelMultiplicity relMultiplicity,
vector<PropertyNameDataType> propertyDefinitions,
const vector<PropertyNameDataType>& propertyDefinitions,
vector<pair<table_id_t, table_id_t>> srcDstTableIDs) {
initCatalogContentForWriteTrxIfNecessary();
auto tableID = catalogContentForWriteTrx->addRelTableSchema(std::move(tableName),
relMultiplicity, std::move(propertyDefinitions), std::move(srcDstTableIDs));
auto tableID = catalogContentForWriteTrx->addRelTableSchema(
std::move(tableName), relMultiplicity, propertyDefinitions, std::move(srcDstTableIDs));
wal->logRelTableRecord(tableID);
return tableID;
}
Expand Down
1 change: 0 additions & 1 deletion src/common/type_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <climits>

#include "common/exception.h"
#include "common/types/value.h"
#include "common/utils.h"

namespace kuzu {
Expand Down
3 changes: 1 addition & 2 deletions src/common/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ add_library(kuzu_common_types
ku_string.cpp
literal.cpp
timestamp_t.cpp
types.cpp
value.cpp)
types.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_common_types>
Expand Down
1 change: 0 additions & 1 deletion src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "common/exception.h"
#include "common/types/types_include.h"
#include "common/types/value.h"

namespace kuzu {
namespace common {
Expand Down
41 changes: 0 additions & 41 deletions src/common/types/value.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/common/vector/value_vector_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace kuzu;
using namespace common;

void ValueVectorUtils::addLiteralToStructuredVector(
void ValueVectorUtils::addLiteralToValueVector(
ValueVector& resultVector, uint64_t pos, const Literal& literal) {
if (literal.isNull()) {
resultVector.setNull(pos, true);
Expand Down
2 changes: 1 addition & 1 deletion src/expression_evaluator/literal_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool LiteralExpressionEvaluator::select(SelectionVector& selVector) {
void LiteralExpressionEvaluator::resolveResultVector(
const ResultSet& resultSet, MemoryManager* memoryManager) {
resultVector = make_shared<ValueVector>(literal->dataType, memoryManager);
ValueVectorUtils::addLiteralToStructuredVector(*resultVector, 0, *literal);
ValueVectorUtils::addLiteralToValueVector(*resultVector, 0, *literal);
resultVector->state = DataChunkState::getSingleValueDataChunkState();
}

Expand Down
19 changes: 8 additions & 11 deletions src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class logger;

namespace kuzu {
namespace catalog {

typedef vector<atomic<uint64_t>> atomic_uint64_vec_t;

class CatalogContent {
public:
// This constructor is only used for mock catalog testing only.
Expand All @@ -40,8 +37,8 @@ class CatalogContent {
/**
* Node and Rel table functions.
*/
table_id_t addNodeTableSchema(
string tableName, uint32_t primaryKeyIdx, vector<PropertyNameDataType> propertyDefinitions);
table_id_t addNodeTableSchema(string tableName, property_id_t primaryKeyId,
vector<PropertyNameDataType> propertyDefinitions);

table_id_t addRelTableSchema(string tableName, RelMultiplicity relMultiplicity,
const vector<PropertyNameDataType>& propertyDefinitions,
Expand Down Expand Up @@ -115,7 +112,7 @@ class CatalogContent {
inline unordered_map<table_id_t, unique_ptr<RelTableSchema>>& getRelTableSchemas() {
return relTableSchemas;
}
inline const unordered_set<table_id_t> getNodeTableIDsForRelTableDirection(
inline unordered_set<table_id_t> getNodeTableIDsForRelTableDirection(
table_id_t relTableID, RelDirection direction) const {
auto relTableSchema = getRelTableSchema(relTableID);
return direction == FWD ? relTableSchema->getUniqueSrcTableIDs() :
Expand Down Expand Up @@ -171,8 +168,8 @@ class Catalog {
}
}

inline void writeCatalogForWALRecord(string directory) {
catalogContentForWriteTrx->saveToFile(std::move(directory), DBFileType::WAL_VERSION);
inline void writeCatalogForWALRecord(const string& directory) {
catalogContentForWriteTrx->saveToFile(directory, DBFileType::WAL_VERSION);
}

static inline void saveInitialCatalogToFile(const string& directory) {
Expand All @@ -181,11 +178,11 @@ class Catalog {

ExpressionType getFunctionType(const string& name) const;

table_id_t addNodeTableSchema(
string tableName, uint32_t primaryKeyIdx, vector<PropertyNameDataType> propertyDefinitions);
table_id_t addNodeTableSchema(string tableName, property_id_t primaryKeyId,
vector<PropertyNameDataType> propertyDefinitions);

table_id_t addRelTableSchema(string tableName, RelMultiplicity relMultiplicity,
vector<PropertyNameDataType> propertyDefinitions,
const vector<PropertyNameDataType>& propertyDefinitions,
vector<pair<table_id_t, table_id_t>> srcDstTableIDs);

inline void removeTableSchema(TableSchema* tableSchema) {
Expand Down
6 changes: 3 additions & 3 deletions src/include/catalog/catalog_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ struct TableSchema {
struct NodeTableSchema : TableSchema {
NodeTableSchema()
: NodeTableSchema{"", INVALID_TABLE_ID, INVALID_PROPERTY_ID, vector<Property>{}} {}
NodeTableSchema(string tableName, table_id_t tableID, uint64_t primaryPropertyId,
NodeTableSchema(string tableName, table_id_t tableID, property_id_t primaryPropertyId,
vector<Property> properties)
: TableSchema{std::move(tableName), tableID, true /* isNodeTable */},
primaryKeyPropertyIdx{primaryPropertyId}, properties{std::move(properties)} {}

inline uint64_t getNumStructuredProperties() const { return properties.size(); }
inline property_id_t getNumProperties() const { return properties.size(); }

inline void addFwdRelTableID(table_id_t tableID) { fwdRelTableIDSet.insert(tableID); }
inline void addBwdRelTableID(table_id_t tableID) { bwdRelTableIDSet.insert(tableID); }
Expand All @@ -94,7 +94,7 @@ struct NodeTableSchema : TableSchema {
// a more robust mechanism to keep track of which property is the primary key (e.g., store this
// information with the property). This is an idx, not an ID, so as the columns/properties of
// the table change, the idx can change.
uint64_t primaryKeyPropertyIdx;
property_id_t primaryKeyPropertyIdx;
vector<Property> properties;
unordered_set<table_id_t> fwdRelTableIDSet; // srcNode->rel
unordered_set<table_id_t> bwdRelTableIDSet; // dstNode->rel
Expand Down
58 changes: 0 additions & 58 deletions src/include/common/types/value.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/include/common/vector/value_vector_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace common {
class ValueVectorUtils {

public:
static void addLiteralToStructuredVector(
static void addLiteralToValueVector(
ValueVector& resultVector, uint64_t pos, const Literal& literal);

// These two functions assume that the given uint8_t* srcData/dstData are pointing to a data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InMemNodeCSVCopier : public InMemStructuresCSVCopier {

private:
void initializeColumnsAndList();
void countLinesPerBlock(uint64_t numProperties);
void countLinesPerBlock();
template<typename T>
void populateColumns();

Expand Down
6 changes: 3 additions & 3 deletions src/include/storage/storage_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ class StorageUtils {
FileUtils::joinPath(directory, fName + StorageConfig::COLUMN_FILE_SUFFIX), dbFileType);
}

static inline StorageStructureIDAndFName getStructuredNodePropertyColumnStructureIDAndFName(
static inline StorageStructureIDAndFName getNodePropertyColumnStructureIDAndFName(
const string& directory, const catalog::Property& property) {
auto fName = getNodePropertyColumnFName(
directory, property.tableID, property.propertyID, DBFileType::ORIGINAL);
return StorageStructureIDAndFName(StorageStructureID::newStructuredNodePropertyColumnID(
property.tableID, property.propertyID),
return StorageStructureIDAndFName(
StorageStructureID::newNodePropertyColumnID(property.tableID, property.propertyID),
fName);
}

Expand Down
Loading

0 comments on commit 9b478eb

Please sign in to comment.