From 0fea38c7a8f8bf2ad625ceba7bc5dbacf82e4a3d Mon Sep 17 00:00:00 2001 From: xiyang Date: Wed, 3 Jan 2024 15:53:13 +0800 Subject: [PATCH] Table schema refactor --- src/binder/CMakeLists.txt | 1 - src/binder/bind/bind_copy.cpp | 6 +- src/binder/bind/bind_ddl.cpp | 92 +++++++++++-------- src/binder/bind/bind_graph_pattern.cpp | 8 +- src/binder/bind/bind_updating_clause.cpp | 8 +- src/binder/bind/ddl/bind_create_rdf_graph.cpp | 20 ++-- src/binder/ddl/CMakeLists.txt | 8 -- src/binder/ddl/bound_create_table_info.cpp | 17 ---- src/catalog/catalog_content.cpp | 44 +++------ src/catalog/node_table_schema.cpp | 10 +- src/catalog/property.cpp | 13 +-- src/catalog/table_schema.cpp | 62 +++++-------- .../table_functions/call_functions.cpp | 2 +- src/include/binder/binder.h | 2 +- src/include/binder/copy/bound_copy_from.h | 4 +- src/include/binder/copy/index_look_up_info.h | 9 -- .../binder/ddl/bound_create_table_info.h | 39 +++++--- src/include/catalog/node_table_schema.h | 22 ++--- src/include/catalog/property.h | 11 +-- src/include/catalog/rdf_graph_schema.h | 3 +- src/include/catalog/rel_table_group_schema.h | 3 +- src/include/catalog/rel_table_schema.h | 7 +- src/include/catalog/table_schema.h | 19 ++-- src/include/common/copy_constructors.h | 17 +++- .../operator/scan/logical_index_scan.h | 3 +- src/include/storage/store/node_table_data.h | 2 +- src/planner/plan/plan_copy.cpp | 2 +- src/processor/map/map_copy_from.cpp | 14 +-- src/storage/stats/node_table_statistics.cpp | 4 +- src/storage/stats/rel_table_statistics.cpp | 6 +- src/storage/stats/table_statistics.cpp | 4 +- src/storage/store/node_table.cpp | 2 +- src/storage/store/node_table_data.cpp | 10 +- src/storage/store/rel_table_data.cpp | 11 +-- 34 files changed, 209 insertions(+), 276 deletions(-) delete mode 100644 src/binder/ddl/CMakeLists.txt delete mode 100644 src/binder/ddl/bound_create_table_info.cpp diff --git a/src/binder/CMakeLists.txt b/src/binder/CMakeLists.txt index a75b009f87..5cc5bd577e 100644 --- a/src/binder/CMakeLists.txt +++ b/src/binder/CMakeLists.txt @@ -1,6 +1,5 @@ add_subdirectory(bind) add_subdirectory(bind_expression) -add_subdirectory(ddl) add_subdirectory(expression) add_subdirectory(query) add_subdirectory(rewriter) diff --git a/src/binder/bind/bind_copy.cpp b/src/binder/bind/bind_copy.cpp index 00a3c14c1b..e945231b85 100644 --- a/src/binder/bind/bind_copy.cpp +++ b/src/binder/bind/bind_copy.cpp @@ -216,11 +216,11 @@ static void bindExpectedColumns(TableSchema* tableSchema, } else { // No column specified. Fall back to schema columns. for (auto& property : tableSchema->properties) { - if (skipPropertyInFile(*property)) { + if (skipPropertyInFile(property)) { continue; } - columnNames.push_back(property->getName()); - columnTypes.push_back(property->getDataType()->copy()); + columnNames.push_back(property.getName()); + columnTypes.push_back(property.getDataType()->copy()); } } } diff --git a/src/binder/bind/bind_ddl.cpp b/src/binder/bind/bind_ddl.cpp index f6abb7d76d..506890e172 100644 --- a/src/binder/bind/bind_ddl.cpp +++ b/src/binder/bind/bind_ddl.cpp @@ -7,7 +7,6 @@ #include "catalog/rel_table_schema.h" #include "common/exception/binder.h" #include "common/string_format.h" -#include "common/string_utils.h" #include "main/client_context.h" #include "parser/ddl/alter.h" #include "parser/ddl/create_table.h" @@ -20,34 +19,44 @@ using namespace kuzu::catalog; namespace kuzu { namespace binder { -std::vector Binder::bindProperties( - const std::vector>& propertyNameDataTypes) { - std::vector boundPropertyNameDataTypes; - std::unordered_set boundPropertyNames; - boundPropertyNames.reserve(propertyNameDataTypes.size()); - boundPropertyNameDataTypes.reserve(propertyNameDataTypes.size()); - for (auto& propertyNameDataType : propertyNameDataTypes) { - if (boundPropertyNames.contains(propertyNameDataType.first)) { +static void validateUniquePropertyName(const std::vector& infos) { + std::unordered_set nameSet; + for (auto& info : infos) { + if (nameSet.contains(info.name)) { throw BinderException( - stringFormat("Duplicated column name: {}, column name must be unique.", - propertyNameDataType.first)); - } else if (TableSchema::isReservedPropertyName(propertyNameDataType.first)) { + stringFormat("Duplicated column name: {}, column name must be unique.", info.name)); + } + nameSet.insert(info.name); + } +} + +static void validateReservedPropertyName(const std::vector& infos) { + for (auto& info : infos) { + if (TableSchema::isReservedPropertyName(info.name)) { throw BinderException( - stringFormat("PropertyName: {} is an internal reserved propertyName.", - propertyNameDataType.first)); + stringFormat("PropertyName: {} is an internal reserved propertyName.", info.name)); } - boundPropertyNameDataTypes.emplace_back( - propertyNameDataType.first, bindDataType(propertyNameDataType.second)); - boundPropertyNames.emplace(propertyNameDataType.first); } - return boundPropertyNameDataTypes; } -static uint32_t bindPrimaryKey(const std::string& pkColName, - std::vector> propertyNameDataTypes) { +std::vector Binder::bindPropertyInfo( + const std::vector>& propertyNameDataTypes) { + std::vector propertyInfos; + propertyInfos.reserve(propertyNameDataTypes.size()); + for (auto& propertyNameDataType : propertyNameDataTypes) { + propertyInfos.emplace_back( + propertyNameDataType.first, *bindDataType(propertyNameDataType.second)); + } + validateUniquePropertyName(propertyInfos); + validateReservedPropertyName(propertyInfos); + return propertyInfos; +} + +static uint32_t bindPrimaryKey( + const std::string& pkColName, const std::vector& infos) { uint32_t primaryKeyIdx = UINT32_MAX; - for (auto i = 0u; i < propertyNameDataTypes.size(); i++) { - if (propertyNameDataTypes[i].first == pkColName) { + for (auto i = 0u; i < infos.size(); i++) { + if (infos[i].name == pkColName) { primaryKeyIdx = i; } } @@ -55,17 +64,16 @@ static uint32_t bindPrimaryKey(const std::string& pkColName, throw BinderException( "Primary key " + pkColName + " does not match any of the predefined node properties."); } - auto primaryKey = propertyNameDataTypes[primaryKeyIdx]; - StringUtils::toUpper(primaryKey.second); + auto pkType = infos[primaryKeyIdx].type; // We only support INT64, STRING and SERIAL column as the primary key. - switch (LogicalTypeUtils::dataTypeFromString(primaryKey.second).getLogicalTypeID()) { + switch (pkType.getLogicalTypeID()) { case LogicalTypeID::INT64: case LogicalTypeID::STRING: case LogicalTypeID::SERIAL: break; default: throw BinderException( - "Invalid primary key type: " + primaryKey.second + ". Expected STRING or INT64."); + "Invalid primary key type: " + pkType.toString() + ". Expected STRING or INT64."); } return primaryKeyIdx; } @@ -91,27 +99,31 @@ BoundCreateTableInfo Binder::bindCreateTableInfo(const parser::CreateTableInfo* } BoundCreateTableInfo Binder::bindCreateNodeTableInfo(const CreateTableInfo* info) { - auto boundProperties = bindProperties(info->propertyNameDataTypes); - auto extraInfo = (ExtraCreateNodeTableInfo*)info->extraInfo.get(); - auto primaryKeyIdx = bindPrimaryKey(extraInfo->pKName, info->propertyNameDataTypes); - for (auto i = 0u; i < boundProperties.size(); ++i) { - if (boundProperties[i].getDataType()->getLogicalTypeID() == LogicalTypeID::SERIAL && - primaryKeyIdx != i) { + auto propertyInfos = bindPropertyInfo(info->propertyNameDataTypes); + auto extraInfo = ku_dynamic_cast( + info->extraInfo.get()); + auto primaryKeyIdx = bindPrimaryKey(extraInfo->pKName, propertyInfos); + for (auto i = 0u; i < propertyInfos.size(); ++i) { + if (propertyInfos[i].type == *LogicalType::SERIAL() && primaryKeyIdx != i) { throw BinderException("Serial property in node table must be the primary key."); } } auto boundExtraInfo = - std::make_unique(primaryKeyIdx, std::move(boundProperties)); + std::make_unique(primaryKeyIdx, std::move(propertyInfos)); return BoundCreateTableInfo(TableType::NODE, info->tableName, std::move(boundExtraInfo)); } BoundCreateTableInfo Binder::bindCreateRelTableInfo(const CreateTableInfo* info) { - auto boundProperties = bindProperties(info->propertyNameDataTypes); - for (auto& boundProperty : boundProperties) { - if (boundProperty.getDataType()->getLogicalTypeID() == LogicalTypeID::SERIAL || - boundProperty.getDataType()->getLogicalTypeID() == LogicalTypeID::MAP) { - throw BinderException(stringFormat("{} property is not supported in rel table.", - boundProperty.getDataType()->toString())); + std::vector propertyInfos; + propertyInfos.emplace_back(InternalKeyword::ID, *LogicalType::INTERNAL_ID()); + for (auto& propertyInfo : bindPropertyInfo(info->propertyNameDataTypes)) { + propertyInfos.push_back(propertyInfo.copy()); + } + for (auto& propertyInfo : propertyInfos) { + if (propertyInfo.type == *LogicalType::SERIAL() || + propertyInfo.type.getLogicalTypeID() == LogicalTypeID::MAP) { + throw BinderException(stringFormat( + "{} property is not supported in rel table.", propertyInfo.type.toString())); } } auto extraInfo = (ExtraCreateRelTableInfo*)info->extraInfo.get(); @@ -122,7 +134,7 @@ BoundCreateTableInfo Binder::bindCreateRelTableInfo(const CreateTableInfo* info) auto dstTableID = bindTableID(extraInfo->dstTableName); validateTableType(dstTableID, TableType::NODE); auto boundExtraInfo = std::make_unique( - srcMultiplicity, dstMultiplicity, srcTableID, dstTableID, std::move(boundProperties)); + srcMultiplicity, dstMultiplicity, srcTableID, dstTableID, std::move(propertyInfos)); return BoundCreateTableInfo(TableType::REL, info->tableName, std::move(boundExtraInfo)); } diff --git a/src/binder/bind/bind_graph_pattern.cpp b/src/binder/bind/bind_graph_pattern.cpp index d570bdf436..e31880a2a5 100644 --- a/src/binder/bind/bind_graph_pattern.cpp +++ b/src/binder/bind/bind_graph_pattern.cpp @@ -130,11 +130,11 @@ static std::vector getPropertyNames(const std::vector std::unordered_set propertyNamesSet; for (auto& tableSchema : tableSchemas) { for (auto& property : tableSchema->properties) { - if (propertyNamesSet.contains(property->getName())) { + if (propertyNamesSet.contains(property.getName())) { continue; } - propertyNamesSet.insert(property->getName()); - result.push_back(property->getName()); + propertyNamesSet.insert(property.getName()); + result.push_back(property.getName()); } } return result; @@ -150,7 +150,7 @@ static std::unique_ptr createPropertyExpression(const std::string& p nodeTableSchema->getPropertyID(propertyName); } std::unordered_map tableIDToPropertyID; - std::vector propertyDataTypes; + std::vector propertyDataTypes; for (auto& tableSchema : tableSchemas) { if (!tableSchema->containProperty(propertyName)) { continue; diff --git a/src/binder/bind/bind_updating_clause.cpp b/src/binder/bind/bind_updating_clause.cpp index fa9b27d2ff..50cd77cabb 100644 --- a/src/binder/bind/bind_updating_clause.cpp +++ b/src/binder/bind/bind_updating_clause.cpp @@ -177,13 +177,13 @@ BoundInsertInfo Binder::bindInsertRelInfo( std::vector Binder::bindSetItems(const PropertyKeyValCollection& collection, TableSchema* tableSchema, const std::shared_ptr& nodeOrRel) { std::vector setItems; - for (auto& property : tableSchema->getProperties()) { - if (collection.hasKeyVal(nodeOrRel, property->getName())) { // input specifies rhs. - setItems.emplace_back(collection.getKeyVal(nodeOrRel, property->getName())); + for (auto& property : tableSchema->getPropertiesRef()) { + if (collection.hasKeyVal(nodeOrRel, property.getName())) { // input specifies rhs. + setItems.emplace_back(collection.getKeyVal(nodeOrRel, property.getName())); continue; } auto propertyExpression = - expressionBinder.bindNodeOrRelPropertyExpression(*nodeOrRel, property->getName()); + expressionBinder.bindNodeOrRelPropertyExpression(*nodeOrRel, property.getName()); auto nullExpression = expressionBinder.createNullLiteralExpression(); nullExpression = ExpressionBinder::implicitCastIfNecessary(nullExpression, propertyExpression->dataType); diff --git a/src/binder/bind/ddl/bind_create_rdf_graph.cpp b/src/binder/bind/ddl/bind_create_rdf_graph.cpp index 17a28130f9..ff97cbb22a 100644 --- a/src/binder/bind/ddl/bind_create_rdf_graph.cpp +++ b/src/binder/bind/ddl/bind_create_rdf_graph.cpp @@ -29,29 +29,27 @@ static std::string getRdfLiteralTripleTableName(const std::string& rdfName) { BoundCreateTableInfo Binder::bindCreateRdfGraphInfo(const CreateTableInfo* info) { auto rdfGraphName = info->tableName; - auto stringType = LogicalType(LogicalTypeID::STRING); - auto serialType = LogicalType(LogicalTypeID::SERIAL); // Resource table. auto resourceTableName = getRdfResourceTableName(rdfGraphName); - std::vector resourceProperties; - resourceProperties.emplace_back(std::string(rdf::IRI), stringType.copy()); + std::vector resourceProperties; + resourceProperties.emplace_back(std::string(rdf::IRI), *LogicalType::STRING()); auto resourceExtraInfo = std::make_unique( 0 /* primaryKeyIdx */, std::move(resourceProperties)); auto resourceCreateInfo = BoundCreateTableInfo(TableType::NODE, resourceTableName, std::move(resourceExtraInfo)); // Literal table. auto literalTableName = getRdfLiteralTableName(rdfGraphName); - std::vector literalProperties; - literalProperties.emplace_back(std::string(rdf::ID), serialType.copy()); - literalProperties.emplace_back(std::string(rdf::VAL), RdfVariantType::getType()); + std::vector literalProperties; + literalProperties.emplace_back(std::string(rdf::ID), *LogicalType::SERIAL()); + literalProperties.emplace_back(std::string(rdf::VAL), *RdfVariantType::getType()); auto literalExtraInfo = std::make_unique( 0 /* primaryKeyIdx */, std::move(literalProperties)); auto literalCreateInfo = BoundCreateTableInfo(TableType::NODE, literalTableName, std::move(literalExtraInfo)); // Resource triple table. auto resourceTripleTableName = getRdfResourceTripleTableName(rdfGraphName); - std::vector resourceTripleProperties; - resourceTripleProperties.emplace_back(std::string(rdf::PID), LogicalType::INTERNAL_ID()); + std::vector resourceTripleProperties; + resourceTripleProperties.emplace_back(std::string(rdf::PID), *LogicalType::INTERNAL_ID()); auto boundResourceTripleExtraInfo = std::make_unique(RelMultiplicity::MANY, RelMultiplicity::MANY, INVALID_TABLE_ID, INVALID_TABLE_ID, std::move(resourceTripleProperties)); @@ -59,8 +57,8 @@ BoundCreateTableInfo Binder::bindCreateRdfGraphInfo(const CreateTableInfo* info) TableType::REL, resourceTripleTableName, std::move(boundResourceTripleExtraInfo)); // Literal triple table. auto literalTripleTableName = getRdfLiteralTripleTableName(rdfGraphName); - std::vector literalTripleProperties; - literalTripleProperties.emplace_back(std::string(rdf::PID), LogicalType::INTERNAL_ID()); + std::vector literalTripleProperties; + literalTripleProperties.emplace_back(std::string(rdf::PID), *LogicalType::INTERNAL_ID()); auto boundLiteralTripleExtraInfo = std::make_unique(RelMultiplicity::MANY, RelMultiplicity::MANY, INVALID_TABLE_ID, INVALID_TABLE_ID, std::move(literalTripleProperties)); diff --git a/src/binder/ddl/CMakeLists.txt b/src/binder/ddl/CMakeLists.txt deleted file mode 100644 index cada05513f..0000000000 --- a/src/binder/ddl/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -add_library( - kuzu_binder_ddl - OBJECT - bound_create_table_info.cpp) - -set(ALL_OBJECT_FILES - ${ALL_OBJECT_FILES} $ - PARENT_SCOPE) \ No newline at end of file diff --git a/src/binder/ddl/bound_create_table_info.cpp b/src/binder/ddl/bound_create_table_info.cpp deleted file mode 100644 index 7db9d79142..0000000000 --- a/src/binder/ddl/bound_create_table_info.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "binder/ddl/bound_create_table_info.h" - -namespace kuzu { -namespace binder { - -std::vector BoundCreateTableInfo::copy( - const std::vector& infos) { - std::vector result; - result.reserve(infos.size()); - for (auto& info : infos) { - result.push_back(info.copy()); - } - return result; -} - -} // namespace binder -} // namespace kuzu diff --git a/src/catalog/catalog_content.cpp b/src/catalog/catalog_content.cpp index 575ed90f7a..f76c985681 100644 --- a/src/catalog/catalog_content.cpp +++ b/src/catalog/catalog_content.cpp @@ -2,6 +2,7 @@ #include +#include "binder/ddl/bound_create_table_info.h" #include "catalog/node_table_schema.h" #include "catalog/rdf_graph_schema.h" #include "catalog/rel_table_group_schema.h" @@ -34,57 +35,36 @@ CatalogContent::CatalogContent(const std::string& directory, VirtualFileSystem* registerBuiltInFunctions(); } -static void assignPropertyIDAndTableID(std::vector& properties, table_id_t tableID) { - for (auto i = 0u; i < properties.size(); ++i) { - properties[i].setPropertyID(i); - properties[i].setTableID(tableID); - } -} - -static std::vector> getPropertiesUniquePtr( - const std::vector& properties) { - std::vector> result; - for (auto& property : properties) { - result.push_back(std::make_unique(property.copy())); - } - return result; -} - table_id_t CatalogContent::addNodeTableSchema(const BoundCreateTableInfo& info) { table_id_t tableID = assignNextTableID(); auto extraInfo = ku_dynamic_cast( info.extraInfo.get()); - auto properties = Property::copy(extraInfo->properties); - assignPropertyIDAndTableID(properties, tableID); - auto nodeTableSchema = std::make_unique( - info.tableName, tableID, extraInfo->primaryKeyIdx, getPropertiesUniquePtr(properties)); + auto nodeTableSchema = + std::make_unique(info.tableName, tableID, extraInfo->primaryKeyIdx); + for (auto& propertyInfo : extraInfo->propertyInfos) { + nodeTableSchema->addProperty(propertyInfo.name, propertyInfo.type.copy()); + } tableNameToIDMap.emplace(nodeTableSchema->tableName, tableID); tableSchemas.emplace(tableID, std::move(nodeTableSchema)); return tableID; } -// TODO(Xiyang): move this to binding stage -static void addRelInternalIDProperty(std::vector& properties) { - auto relInternalIDProperty = Property(InternalKeyword::ID, LogicalType::INTERNAL_ID()); - properties.insert(properties.begin(), std::move(relInternalIDProperty)); -} - table_id_t CatalogContent::addRelTableSchema(const BoundCreateTableInfo& info) { table_id_t tableID = assignNextTableID(); auto extraInfo = ku_dynamic_cast( info.extraInfo.get()); - auto properties = Property::copy(extraInfo->properties); - addRelInternalIDProperty(properties); - assignPropertyIDAndTableID(properties, tableID); auto srcNodeTableSchema = ku_dynamic_cast(getTableSchema(extraInfo->srcTableID)); auto dstNodeTableSchema = ku_dynamic_cast(getTableSchema(extraInfo->dstTableID)); srcNodeTableSchema->addFwdRelTableID(tableID); dstNodeTableSchema->addBwdRelTableID(tableID); - auto relTableSchema = std::make_unique(info.tableName, tableID, - getPropertiesUniquePtr(properties), extraInfo->srcMultiplicity, extraInfo->dstMultiplicity, - extraInfo->srcTableID, extraInfo->dstTableID); + auto relTableSchema = + std::make_unique(info.tableName, tableID, extraInfo->srcMultiplicity, + extraInfo->dstMultiplicity, extraInfo->srcTableID, extraInfo->dstTableID); + for (auto& propertyInfo : extraInfo->propertyInfos) { + relTableSchema->addProperty(propertyInfo.name, propertyInfo.type.copy()); + } tableNameToIDMap.emplace(relTableSchema->tableName, tableID); tableSchemas.emplace(tableID, std::move(relTableSchema)); return tableID; diff --git a/src/catalog/node_table_schema.cpp b/src/catalog/node_table_schema.cpp index 2a76203f44..988117c724 100644 --- a/src/catalog/node_table_schema.cpp +++ b/src/catalog/node_table_schema.cpp @@ -9,26 +9,26 @@ namespace kuzu { namespace catalog { NodeTableSchema::NodeTableSchema(const NodeTableSchema& other) : TableSchema{other} { - primaryKeyPropertyID = other.primaryKeyPropertyID; + primaryKeyPID = other.primaryKeyPID; fwdRelTableIDSet = other.fwdRelTableIDSet; bwdRelTableIDSet = other.bwdRelTableIDSet; } void NodeTableSchema::serializeInternal(Serializer& serializer) { - serializer.serializeValue(primaryKeyPropertyID); + serializer.serializeValue(primaryKeyPID); serializer.serializeUnorderedSet(fwdRelTableIDSet); serializer.serializeUnorderedSet(bwdRelTableIDSet); } std::unique_ptr NodeTableSchema::deserialize(Deserializer& deserializer) { - property_id_t primaryKeyPropertyID; + property_id_t primaryKeyPID; std::unordered_set fwdRelTableIDSet; std::unordered_set bwdRelTableIDSet; - deserializer.deserializeValue(primaryKeyPropertyID); + deserializer.deserializeValue(primaryKeyPID); deserializer.deserializeUnorderedSet(fwdRelTableIDSet); deserializer.deserializeUnorderedSet(bwdRelTableIDSet); auto schema = std::make_unique(); - schema->primaryKeyPropertyID = primaryKeyPropertyID; + schema->primaryKeyPID = primaryKeyPID; schema->fwdRelTableIDSet = std::move(fwdRelTableIDSet); schema->bwdRelTableIDSet = std::move(bwdRelTableIDSet); return schema; diff --git a/src/catalog/property.cpp b/src/catalog/property.cpp index 3af0ea8033..7807c6ef4b 100644 --- a/src/catalog/property.cpp +++ b/src/catalog/property.cpp @@ -15,7 +15,7 @@ void Property::serialize(Serializer& serializer) const { serializer.serializeValue(tableID); } -std::unique_ptr Property::deserialize(Deserializer& deserializer) { +Property Property::deserialize(Deserializer& deserializer) { std::string name; property_id_t propertyID; table_id_t tableID; @@ -23,16 +23,7 @@ std::unique_ptr Property::deserialize(Deserializer& deserializer) { auto dataType = LogicalType::deserialize(deserializer); deserializer.deserializeValue(propertyID); deserializer.deserializeValue(tableID); - return std::make_unique(name, std::move(dataType), propertyID, tableID); -} - -std::vector Property::copy(const std::vector& properties) { - std::vector result; - result.reserve(properties.size()); - for (auto& property : properties) { - result.push_back(property.copy()); - } - return result; + return Property(name, std::move(dataType), propertyID, tableID); } } // namespace catalog diff --git a/src/catalog/table_schema.cpp b/src/catalog/table_schema.cpp index 7bad16e714..abc0d21bac 100644 --- a/src/catalog/table_schema.cpp +++ b/src/catalog/table_schema.cpp @@ -21,58 +21,44 @@ TableSchema::TableSchema(const TableSchema& other) { tableType = other.tableType; tableName = other.tableName; tableID = other.tableID; - for (auto& property : other.properties) { - properties.push_back(std::make_unique(property->copy())); - } + properties = copyVector(other.properties); comment = other.comment; - nextPropertyID = other.nextPropertyID; + nextPID = other.nextPID; } bool TableSchema::isReservedPropertyName(const std::string& propertyName) { return StringUtils::getUpper(propertyName) == InternalKeyword::ID; } -std::vector TableSchema::getProperties() const { - std::vector propertiesToReturn; - propertiesToReturn.reserve(properties.size()); - for (auto& property : properties) { - propertiesToReturn.push_back(property.get()); - } - return propertiesToReturn; -} - bool TableSchema::containProperty(const std::string& propertyName) const { return std::any_of(properties.begin(), properties.end(), - [&propertyName](const std::unique_ptr& property) { - return property->getName() == propertyName; - }); + [&propertyName](const Property& property) { return property.getName() == propertyName; }); } bool TableSchema::containPropertyType(const common::LogicalType& logicalType) const { - return std::any_of(properties.begin(), properties.end(), - [&logicalType](const std::unique_ptr& property) { - return *property->getDataType() == logicalType; + return std::any_of( + properties.begin(), properties.end(), [&logicalType](const Property& property) { + return *property.getDataType() == logicalType; }); } void TableSchema::addProperty( std::string propertyName, std::unique_ptr dataType) { - properties.push_back(std::make_unique( - std::move(propertyName), std::move(dataType), nextPropertyID++, tableID)); + properties.emplace_back(std::move(propertyName), std::move(dataType), nextPID++, tableID); } void TableSchema::dropProperty(common::property_id_t propertyID) { properties.erase(std::remove_if(properties.begin(), properties.end(), - [propertyID](const std::unique_ptr& property) { - return property->getPropertyID() == propertyID; + [propertyID](const Property& property) { + return property.getPropertyID() == propertyID; }), properties.end()); } property_id_t TableSchema::getPropertyID(const std::string& propertyName) const { for (auto& property : properties) { - if (property->getName() == propertyName) { - return property->getPropertyID(); + if (property.getName() == propertyName) { + return property.getPropertyID(); } } // LCOV_EXCL_START @@ -84,17 +70,17 @@ property_id_t TableSchema::getPropertyID(const std::string& propertyName) const // TODO(Guodong): Instead of looping over properties, cache a map between propertyID and columnID. column_id_t TableSchema::getColumnID(const property_id_t propertyID) const { for (auto i = 0u; i < properties.size(); i++) { - if (properties[i]->getPropertyID() == propertyID) { + if (properties[i].getPropertyID() == propertyID) { return i; } } return INVALID_COLUMN_ID; } -Property* TableSchema::getProperty(property_id_t propertyID) const { +const Property* TableSchema::getProperty(property_id_t propertyID) const { for (auto& property : properties) { - if (property->getPropertyID() == propertyID) { - return property.get(); + if (property.getPropertyID() == propertyID) { + return &property; } } // LCOV_EXCL_START @@ -105,8 +91,8 @@ Property* TableSchema::getProperty(property_id_t propertyID) const { void TableSchema::renameProperty(property_id_t propertyID, const std::string& newName) { for (auto& property : properties) { - if (property->getPropertyID() == propertyID) { - property->rename(newName); + if (property.getPropertyID() == propertyID) { + property.rename(newName); return; } } @@ -119,9 +105,9 @@ void TableSchema::serialize(Serializer& serializer) { serializer.serializeValue(tableName); serializer.serializeValue(tableID); serializer.serializeValue(tableType); - serializer.serializeVectorOfPtrs(properties); + serializer.serializeVector(properties); serializer.serializeValue(comment); - serializer.serializeValue(nextPropertyID); + serializer.serializeValue(nextPID); serializeInternal(serializer); } @@ -129,15 +115,15 @@ std::unique_ptr TableSchema::deserialize(Deserializer& deserializer std::string tableName; table_id_t tableID; TableType tableType; - std::vector> properties; + std::vector properties; std::string comment; - property_id_t nextPropertyID; + property_id_t nextPID; deserializer.deserializeValue(tableName); deserializer.deserializeValue(tableID); deserializer.deserializeValue(tableType); - deserializer.deserializeVectorOfPtrs(properties); + deserializer.deserializeVector(properties); deserializer.deserializeValue(comment); - deserializer.deserializeValue(nextPropertyID); + deserializer.deserializeValue(nextPID); std::unique_ptr result; switch (tableType) { case TableType::NODE: { @@ -161,7 +147,7 @@ std::unique_ptr TableSchema::deserialize(Deserializer& deserializer result->tableType = tableType; result->properties = std::move(properties); result->comment = std::move(comment); - result->nextPropertyID = nextPropertyID; + result->nextPID = nextPID; return result; } diff --git a/src/function/table_functions/call_functions.cpp b/src/function/table_functions/call_functions.cpp index 34b8de0120..e74979d3c8 100644 --- a/src/function/table_functions/call_functions.cpp +++ b/src/function/table_functions/call_functions.cpp @@ -173,7 +173,7 @@ void TableInfoFunction::tableFunc(TableFunctionInput& input, DataChunk& outputCh auto numPropertiesToOutput = morsel.endOffset - morsel.startOffset; auto outVectorPos = 0; for (auto i = 0u; i < numPropertiesToOutput; i++) { - auto property = tableSchema->properties[morsel.startOffset + i].get(); + auto property = &tableSchema->properties[morsel.startOffset + i]; if (tableSchema->getTableType() == TableType::REL && property->getName() == InternalKeyword::ID) { continue; diff --git a/src/include/binder/binder.h b/src/include/binder/binder.h index 8178c75187..afe4f039ed 100644 --- a/src/include/binder/binder.h +++ b/src/include/binder/binder.h @@ -116,7 +116,7 @@ class Binder { std::unique_ptr bindDropProperty(const parser::Statement& statement); std::unique_ptr bindRenameProperty(const parser::Statement& statement); - std::vector bindProperties( + std::vector bindPropertyInfo( const std::vector>& propertyNameDataTypes); /*** bind copy ***/ diff --git a/src/include/binder/copy/bound_copy_from.h b/src/include/binder/copy/bound_copy_from.h index 05dedb76c6..e39806b83c 100644 --- a/src/include/binder/copy/bound_copy_from.h +++ b/src/include/binder/copy/bound_copy_from.h @@ -46,8 +46,8 @@ struct ExtraBoundCopyRelInfo final : public ExtraBoundCopyFromInfo { ExtraBoundCopyRelInfo() = default; ExtraBoundCopyRelInfo(const ExtraBoundCopyRelInfo& other) - : infos{IndexLookupInfo::copy(other.infos)}, fromOffset{other.fromOffset}, - toOffset{other.toOffset}, propertyColumns{other.propertyColumns} {} + : infos{copyVector(other.infos)}, fromOffset{other.fromOffset}, toOffset{other.toOffset}, + propertyColumns{other.propertyColumns} {} inline std::unique_ptr copy() const override { return std::make_unique(*this); diff --git a/src/include/binder/copy/index_look_up_info.h b/src/include/binder/copy/index_look_up_info.h index ce8dc2067c..6078d8a77a 100644 --- a/src/include/binder/copy/index_look_up_info.h +++ b/src/include/binder/copy/index_look_up_info.h @@ -19,15 +19,6 @@ struct IndexLookupInfo { indexType{std::move(indexType)} {} EXPLICIT_COPY_DEFAULT_MOVE(IndexLookupInfo); - static std::vector copy(const std::vector& infos) { - std::vector result; - result.reserve(infos.size()); - for (auto& info : infos) { - result.push_back(info.copy()); - } - return result; - } - private: IndexLookupInfo(const IndexLookupInfo& other) : nodeTableID{other.nodeTableID}, offset{other.offset}, key{other.key}, diff --git a/src/include/binder/ddl/bound_create_table_info.h b/src/include/binder/ddl/bound_create_table_info.h index d7c342a1ba..1b6fe9204a 100644 --- a/src/include/binder/ddl/bound_create_table_info.h +++ b/src/include/binder/ddl/bound_create_table_info.h @@ -1,7 +1,8 @@ #pragma once -#include "catalog/property.h" +#include "common/copy_constructors.h" #include "common/enums/table_type.h" +#include "common/types/types.h" namespace kuzu { namespace catalog { @@ -24,23 +25,32 @@ struct BoundCreateTableInfo { : type{type}, tableName{std::move(tableName)}, extraInfo{std::move(extraInfo)} {} EXPLICIT_COPY_DEFAULT_MOVE(BoundCreateTableInfo); - static std::vector copy(const std::vector& infos); - private: BoundCreateTableInfo(const BoundCreateTableInfo& other) : type{other.type}, tableName{other.tableName}, extraInfo{other.extraInfo->copy()} {} }; +struct PropertyInfo { + std::string name; + common::LogicalType type; + + PropertyInfo(std::string name, common::LogicalType type) + : name{std::move(name)}, type{std::move(type)} {} + EXPLICIT_COPY_DEFAULT_MOVE(PropertyInfo); + +private: + PropertyInfo(const PropertyInfo& other) : name{other.name}, type{other.type} {} +}; + struct BoundExtraCreateNodeTableInfo : public BoundExtraCreateTableInfo { common::property_id_t primaryKeyIdx; - std::vector properties; + std::vector propertyInfos; BoundExtraCreateNodeTableInfo( - common::property_id_t primaryKeyIdx, std::vector properties) - : primaryKeyIdx{primaryKeyIdx}, properties{std::move(properties)} {} + common::property_id_t primaryKeyIdx, std::vector propertyInfos) + : primaryKeyIdx{primaryKeyIdx}, propertyInfos{std::move(propertyInfos)} {} BoundExtraCreateNodeTableInfo(const BoundExtraCreateNodeTableInfo& other) - : primaryKeyIdx{other.primaryKeyIdx}, properties{ - catalog::Property::copy(other.properties)} {} + : primaryKeyIdx{other.primaryKeyIdx}, propertyInfos{copyVector(other.propertyInfos)} {} inline std::unique_ptr copy() const final { return std::make_unique(*this); @@ -52,18 +62,17 @@ struct BoundExtraCreateRelTableInfo : public BoundExtraCreateTableInfo { catalog::RelMultiplicity dstMultiplicity; common::table_id_t srcTableID; common::table_id_t dstTableID; - std::vector properties; + std::vector propertyInfos; BoundExtraCreateRelTableInfo(catalog::RelMultiplicity srcMultiplicity, catalog::RelMultiplicity dstMultiplicity, common::table_id_t srcTableID, - common::table_id_t dstTableID, std::vector properties) + common::table_id_t dstTableID, std::vector propertyInfos) : srcMultiplicity{srcMultiplicity}, dstMultiplicity{dstMultiplicity}, - srcTableID{srcTableID}, dstTableID{dstTableID}, properties{std::move(properties)} {} + srcTableID{srcTableID}, dstTableID{dstTableID}, propertyInfos{std::move(propertyInfos)} {} BoundExtraCreateRelTableInfo(const BoundExtraCreateRelTableInfo& other) : srcMultiplicity{other.srcMultiplicity}, dstMultiplicity{other.dstMultiplicity}, - srcTableID{other.srcTableID}, dstTableID{other.dstTableID}, properties{ - catalog::Property::copy( - other.properties)} {} + srcTableID{other.srcTableID}, dstTableID{other.dstTableID}, propertyInfos{copyVector( + other.propertyInfos)} {} inline std::unique_ptr copy() const final { return std::make_unique(*this); @@ -76,7 +85,7 @@ struct BoundExtraCreateRelTableGroupInfo : public BoundExtraCreateTableInfo { explicit BoundExtraCreateRelTableGroupInfo(std::vector infos) : infos{std::move(infos)} {} BoundExtraCreateRelTableGroupInfo(const BoundExtraCreateRelTableGroupInfo& other) - : infos{BoundCreateTableInfo::copy(other.infos)} {} + : infos{copyVector(other.infos)} {} inline std::unique_ptr copy() const final { return std::make_unique(*this); diff --git a/src/include/catalog/node_table_schema.h b/src/include/catalog/node_table_schema.h index 4c7ada2c79..23c47591fa 100644 --- a/src/include/catalog/node_table_schema.h +++ b/src/include/catalog/node_table_schema.h @@ -5,22 +5,18 @@ namespace kuzu { namespace catalog { -class NodeTableSchema : public TableSchema { +class NodeTableSchema final : public TableSchema { public: NodeTableSchema() : TableSchema{common::TableType::NODE} {} - NodeTableSchema(std::string tableName, common::table_id_t tableID, - common::property_id_t primaryPropertyId, std::vector> properties) - : TableSchema{std::move(tableName), tableID, common::TableType::NODE, - std::move(properties)}, - primaryKeyPropertyID{primaryPropertyId} {} + NodeTableSchema( + std::string tableName, common::table_id_t tableID, common::property_id_t primaryKeyPID) + : TableSchema{common::TableType::NODE, std::move(tableName), tableID}, primaryKeyPID{ + primaryKeyPID} {} NodeTableSchema(const NodeTableSchema& other); - // TODO(Xiyang): this seems in correct; - inline Property* getPrimaryKey() const { return properties[primaryKeyPropertyID].get(); } + inline const Property* getPrimaryKey() const { return &properties[primaryKeyPID]; } - static std::unique_ptr deserialize(common::Deserializer& deserializer); - - inline common::property_id_t getPrimaryKeyPropertyID() const { return primaryKeyPropertyID; } + inline common::property_id_t getPrimaryKeyPropertyID() const { return primaryKeyPID; } inline void addFwdRelTableID(common::table_id_t tableID) { fwdRelTableIDSet.insert(tableID); } inline void addBwdRelTableID(common::table_id_t tableID) { bwdRelTableIDSet.insert(tableID); } @@ -31,6 +27,8 @@ class NodeTableSchema : public TableSchema { return std::make_unique(*this); } + static std::unique_ptr deserialize(common::Deserializer& deserializer); + private: void serializeInternal(common::Serializer& serializer) final; @@ -39,7 +37,7 @@ class NodeTableSchema : public 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. - common::property_id_t primaryKeyPropertyID; + common::property_id_t primaryKeyPID; common::table_id_set_t fwdRelTableIDSet; // srcNode->rel common::table_id_set_t bwdRelTableIDSet; // dstNode->rel }; diff --git a/src/include/catalog/property.h b/src/include/catalog/property.h index 08b0717c76..80fff35319 100644 --- a/src/include/catalog/property.h +++ b/src/include/catalog/property.h @@ -12,6 +12,7 @@ namespace catalog { class Property { public: + Property() = default; Property(std::string name, std::unique_ptr dataType) : Property{std::move(name), std::move(dataType), common::INVALID_PROPERTY_ID, common::INVALID_TABLE_ID} {} @@ -23,22 +24,16 @@ class Property { inline std::string getName() const { return name; } - inline common::LogicalType* getDataType() const { return dataType.get(); } + inline const common::LogicalType* getDataType() const { return dataType.get(); } inline common::property_id_t getPropertyID() const { return propertyID; } inline common::table_id_t getTableID() const { return tableID; } - inline void setPropertyID(common::property_id_t propertyID_) { this->propertyID = propertyID_; } - - inline void setTableID(common::table_id_t tableID_) { this->tableID = tableID_; } - inline void rename(std::string newName) { name = std::move(newName); } void serialize(common::Serializer& serializer) const; - static std::unique_ptr deserialize(common::Deserializer& deserializer); - - static std::vector copy(const std::vector& properties); + static Property deserialize(common::Deserializer& deserializer); private: Property(const Property& other) diff --git a/src/include/catalog/rdf_graph_schema.h b/src/include/catalog/rdf_graph_schema.h index dcc02af92a..3984ec89c8 100644 --- a/src/include/catalog/rdf_graph_schema.h +++ b/src/include/catalog/rdf_graph_schema.h @@ -11,8 +11,7 @@ class RdfGraphSchema : public TableSchema { RdfGraphSchema(std::string tableName, common::table_id_t rdfID, common::table_id_t resourceTableID, common::table_id_t literalTabelID, common::table_id_t resourceTripleTableID, common::table_id_t literalTripleTableID) - : TableSchema{std::move(tableName), rdfID, common::TableType::RDF, - std::vector>{}}, + : TableSchema{common::TableType::RDF, std::move(tableName), rdfID}, resourceTableID{resourceTableID}, literalTableID{literalTabelID}, resourceTripleTableID{resourceTripleTableID}, literalTripleTableID{literalTripleTableID} { } diff --git a/src/include/catalog/rel_table_group_schema.h b/src/include/catalog/rel_table_group_schema.h index 925301d2e3..d54794f823 100644 --- a/src/include/catalog/rel_table_group_schema.h +++ b/src/include/catalog/rel_table_group_schema.h @@ -10,8 +10,7 @@ class RelTableGroupSchema : public TableSchema { RelTableGroupSchema() : TableSchema{common::TableType::REL_GROUP} {} RelTableGroupSchema(std::string tableName, common::table_id_t tableID, std::vector relTableIDs) - : TableSchema{std::move(tableName), tableID, common::TableType::REL_GROUP, - std::vector>{}}, + : TableSchema{common::TableType::REL_GROUP, std::move(tableName), tableID}, relTableIDs{std::move(relTableIDs)} {} RelTableGroupSchema(const RelTableGroupSchema& other); diff --git a/src/include/catalog/rel_table_schema.h b/src/include/catalog/rel_table_schema.h index 43280e1834..68752c5811 100644 --- a/src/include/catalog/rel_table_schema.h +++ b/src/include/catalog/rel_table_schema.h @@ -16,10 +16,9 @@ class RelTableSchema : public TableSchema { public: RelTableSchema() : TableSchema(common::TableType::REL) {} RelTableSchema(std::string tableName, common::table_id_t tableID, - std::vector> properties, RelMultiplicity srcMultiplicity, - RelMultiplicity dstMultiplicity, common::table_id_t srcTableID, - common::table_id_t dstTableID) - : TableSchema{std::move(tableName), tableID, common::TableType::REL, std::move(properties)}, + RelMultiplicity srcMultiplicity, RelMultiplicity dstMultiplicity, + common::table_id_t srcTableID, common::table_id_t dstTableID) + : TableSchema{common::TableType::REL, std::move(tableName), tableID}, srcMultiplicity{srcMultiplicity}, dstMultiplicity{dstMultiplicity}, srcTableID{srcTableID}, dstTableID{dstTableID} {} RelTableSchema(const RelTableSchema& other); diff --git a/src/include/catalog/table_schema.h b/src/include/catalog/table_schema.h index 44988ed6f7..bea4133312 100644 --- a/src/include/catalog/table_schema.h +++ b/src/include/catalog/table_schema.h @@ -13,13 +13,10 @@ namespace catalog { class TableSchema { public: explicit TableSchema(common::TableType tableType) - : tableType{tableType}, tableName{}, tableID{common::INVALID_TABLE_ID}, comment{}, - nextPropertyID{0} {} - TableSchema(std::string tableName, common::table_id_t tableID, common::TableType tableType, - std::vector> properties) - : tableType{tableType}, tableName{std::move(tableName)}, tableID{tableID}, - properties{std::move(properties)}, comment{}, - nextPropertyID{(common::property_id_t)this->properties.size()} {} + : TableSchema(tableType, "", common::INVALID_TABLE_ID) {} + TableSchema(common::TableType tableType, std::string tableName, common::table_id_t tableID) + : tableType{tableType}, tableName{std::move(tableName)}, tableID{tableID}, comment{}, + nextPID{0} {} TableSchema(const TableSchema& other); virtual ~TableSchema() = default; @@ -35,11 +32,11 @@ class TableSchema { static bool isReservedPropertyName(const std::string& propertyName); inline uint32_t getNumProperties() const { return properties.size(); } - std::vector getProperties() const; + inline const std::vector& getPropertiesRef() const { return properties; } bool containProperty(const std::string& propertyName) const; bool containPropertyType(const common::LogicalType& logicalType) const; common::property_id_t getPropertyID(const std::string& propertyName) const; - Property* getProperty(common::property_id_t propertyID) const; + const Property* getProperty(common::property_id_t propertyID) const; common::column_id_t getColumnID(common::property_id_t propertyID) const; @@ -59,9 +56,9 @@ class TableSchema { common::TableType tableType; std::string tableName; common::table_id_t tableID; - std::vector> properties; + std::vector properties; std::string comment; - common::property_id_t nextPropertyID; + common::property_id_t nextPID; }; } // namespace catalog diff --git a/src/include/common/copy_constructors.h b/src/include/common/copy_constructors.h index 4123a32772..cbeebf544b 100644 --- a/src/include/common/copy_constructors.h +++ b/src/include/common/copy_constructors.h @@ -1,15 +1,15 @@ #pragma once +#include // This file defines many macros for controlling copy constructors and move constructors on classes. // NOLINTBEGIN(bugprone-macro-parentheses): Although this is a good check in general, here, we // cannot add parantheses around the arguments, for it would be invalid syntax. #define DELETE_COPY_CONSTRUCT(Object) Object(const Object& other) = delete #define DELETE_COPY_ASSN(Object) Object& operator=(const Object& other) = delete -// NOLINTBEGIN + #define DELETE_MOVE_CONSTRUCT(Object) Object(Object&& other) = delete #define DELETE_MOVE_ASSN(Object) Object& operator=(Object&& other) = delete -// NOLINTEND #define DELETE_BOTH_COPY(Object) \ DELETE_COPY_CONSTRUCT(Object); \ @@ -19,10 +19,8 @@ DELETE_MOVE_CONSTRUCT(Object); \ DELETE_MOVE_ASSN(Object) -// NOLINTBEGIN #define DEFAULT_MOVE_CONSTRUCT(Object) Object(Object&& other) = default #define DEFAULT_MOVE_ASSN(Object) Object& operator=(Object&& other) = default -// NOLINTEND #define DEFAULT_BOTH_MOVE(Object) \ DEFAULT_MOVE_CONSTRUCT(Object); \ @@ -62,5 +60,14 @@ #define DELETE_COPY_AND_MOVE(Object) \ DELETE_BOTH_COPY(Object); \ DELETE_BOTH_MOVE(Object) +// NOLINTEND(bugprone-macro-parentheses): -// NOLINTEND(bugprone-macro-parentheses) +template +static std::vector copyVector(const std::vector& objects) { + std::vector result; + result.reserve(objects.size()); + for (auto& object : objects) { + result.push_back(object.copy()); + } + return result; +} diff --git a/src/include/planner/operator/scan/logical_index_scan.h b/src/include/planner/operator/scan/logical_index_scan.h index 42f9ce7b36..87a84bbe82 100644 --- a/src/include/planner/operator/scan/logical_index_scan.h +++ b/src/include/planner/operator/scan/logical_index_scan.h @@ -22,8 +22,7 @@ class LogicalIndexScanNode : public LogicalOperator { inline const binder::IndexLookupInfo* getInfo(uint32_t idx) const { return &infos[idx]; } std::unique_ptr copy() override { - return make_unique( - binder::IndexLookupInfo::copy(infos), children[0]->copy()); + return make_unique(copyVector(infos), children[0]->copy()); } private: diff --git a/src/include/storage/store/node_table_data.h b/src/include/storage/store/node_table_data.h index d2282d4dcd..9139fd2f63 100644 --- a/src/include/storage/store/node_table_data.h +++ b/src/include/storage/store/node_table_data.h @@ -10,7 +10,7 @@ class LocalTableData; class NodeTableData final : public TableData { public: NodeTableData(BMFileHandle* dataFH, BMFileHandle* metadataFH, common::table_id_t tableID, - BufferManager* bufferManager, WAL* wal, const std::vector& properties, + BufferManager* bufferManager, WAL* wal, const std::vector& properties, TablesStatistics* tablesStatistics, bool enableCompression); // This interface is node table specific, as rel table requires also relDataDirection. diff --git a/src/planner/plan/plan_copy.cpp b/src/planner/plan/plan_copy.cpp index e46a750bdf..9bf5821d15 100644 --- a/src/planner/plan/plan_copy.cpp +++ b/src/planner/plan/plan_copy.cpp @@ -106,7 +106,7 @@ std::unique_ptr Planner::planCopyRelFrom( QueryPlanner::appendScanFile(*info.fileScanInfo, *plan); auto extraInfo = ku_dynamic_cast(info.extraInfo.get()); - appendIndexScan(IndexLookupInfo::copy(extraInfo->infos), *plan); + appendIndexScan(copyVector(extraInfo->infos), *plan); appendPartitioner(info, *plan); appendCopyFrom(info, results, *plan); return plan; diff --git a/src/processor/map/map_copy_from.cpp b/src/processor/map/map_copy_from.cpp index 9d96758095..596aa074f0 100644 --- a/src/processor/map/map_copy_from.cpp +++ b/src/processor/map/map_copy_from.cpp @@ -50,9 +50,9 @@ std::unique_ptr PlanMapper::mapCopyFrom(LogicalOperator* logic static void getNodeColumnsInCopyOrder( TableSchema* tableSchema, std::vector& columnNames, logical_types_t& columnTypes) { - for (auto& property : tableSchema->getProperties()) { - columnNames.push_back(property->getName()); - columnTypes.push_back(property->getDataType()->copy()); + for (auto& property : tableSchema->getPropertiesRef()) { + columnNames.push_back(property.getName()); + columnTypes.push_back(property.getDataType()->copy()); } } @@ -64,10 +64,10 @@ static void getRelColumnNamesInCopyOrder( columnTypes.emplace_back(std::make_unique(LogicalTypeID::INT64)); columnTypes.emplace_back(std::make_unique(LogicalTypeID::INT64)); columnTypes.emplace_back(std::make_unique(LogicalTypeID::INT64)); - auto properties = tableSchema->getProperties(); + auto& properties = tableSchema->getPropertiesRef(); for (auto i = 1u; i < properties.size(); ++i) { // skip internal ID - columnNames.push_back(properties[i]->getName()); - columnTypes.push_back(properties[i]->getDataType()->copy()); + columnNames.push_back(properties[i].getName()); + columnTypes.push_back(properties[i].getDataType()->copy()); } } @@ -207,7 +207,7 @@ physical_op_vector_t PlanMapper::mapCopyRelFrom(LogicalOperator* logicalOperator std::vector> columnTypes; columnTypes.push_back(LogicalType::INTERNAL_ID()); // ADJ COLUMN. for (auto& property : tableSchema->properties) { - columnTypes.push_back(property->getDataType()->copy()); + columnTypes.push_back(property.getDataType()->copy()); } auto copyRelSharedState = std::make_shared(tableSchema->tableID, storageManager.getRelTable(tableSchema->tableID), std::move(columnTypes), diff --git a/src/storage/stats/node_table_statistics.cpp b/src/storage/stats/node_table_statistics.cpp index 7e7c177d63..b74973c0a9 100644 --- a/src/storage/stats/node_table_statistics.cpp +++ b/src/storage/stats/node_table_statistics.cpp @@ -16,9 +16,9 @@ NodeTableStatsAndDeletedIDs::NodeTableStatsAndDeletedIDs(BMFileHandle* metadataF : TableStatistics{schema}, tableID{schema.tableID} { metadataDAHInfos.clear(); metadataDAHInfos.reserve(schema.getNumProperties()); - for (auto property : schema.getProperties()) { + for (auto& property : schema.getPropertiesRef()) { metadataDAHInfos.push_back(TablesStatistics::createMetadataDAHInfo( - *property->getDataType(), *metadataFH, bufferManager, wal)); + *property.getDataType(), *metadataFH, bufferManager, wal)); } } diff --git a/src/storage/stats/rel_table_statistics.cpp b/src/storage/stats/rel_table_statistics.cpp index fcd81a27ee..4900466530 100644 --- a/src/storage/stats/rel_table_statistics.cpp +++ b/src/storage/stats/rel_table_statistics.cpp @@ -36,11 +36,11 @@ RelTableStats::RelTableStats( bwdPropertyMetadataDAHInfos.clear(); fwdPropertyMetadataDAHInfos.reserve(schema.getNumProperties()); bwdPropertyMetadataDAHInfos.reserve(schema.getNumProperties()); - for (auto property : schema.getProperties()) { + for (auto& property : schema.getPropertiesRef()) { fwdPropertyMetadataDAHInfos.push_back(TablesStatistics::createMetadataDAHInfo( - *property->getDataType(), *metadataFH, bufferManager, wal)); + *property.getDataType(), *metadataFH, bufferManager, wal)); bwdPropertyMetadataDAHInfos.push_back(TablesStatistics::createMetadataDAHInfo( - *property->getDataType(), *metadataFH, bufferManager, wal)); + *property.getDataType(), *metadataFH, bufferManager, wal)); } } diff --git a/src/storage/stats/table_statistics.cpp b/src/storage/stats/table_statistics.cpp index e1b3c9aeff..992bc6b4a3 100644 --- a/src/storage/stats/table_statistics.cpp +++ b/src/storage/stats/table_statistics.cpp @@ -13,8 +13,8 @@ namespace storage { TableStatistics::TableStatistics(const catalog::TableSchema& schema) : tableType{schema.tableType}, numTuples{0}, tableID{schema.tableID} { - for (auto property : schema.getProperties()) { - propertyStatistics[property->getPropertyID()] = std::make_unique(); + for (auto& property : schema.getPropertiesRef()) { + propertyStatistics[property.getPropertyID()] = std::make_unique(); } } diff --git a/src/storage/store/node_table.cpp b/src/storage/store/node_table.cpp index 5904cd27d8..5b5c67355e 100644 --- a/src/storage/store/node_table.cpp +++ b/src/storage/store/node_table.cpp @@ -20,7 +20,7 @@ NodeTable::NodeTable(BMFileHandle* dataFH, BMFileHandle* metadataFH, : Table{nodeTableSchema, nodesStatisticsAndDeletedIDs, memoryManager, wal}, pkColumnID{nodeTableSchema->getColumnID(nodeTableSchema->getPrimaryKeyPropertyID())} { tableData = std::make_unique(dataFH, metadataFH, tableID, bufferManager, wal, - nodeTableSchema->getProperties(), nodesStatisticsAndDeletedIDs, enableCompression); + nodeTableSchema->getPropertiesRef(), nodesStatisticsAndDeletedIDs, enableCompression); initializePKIndex(nodeTableSchema, readOnly, vfs); } diff --git a/src/storage/store/node_table_data.cpp b/src/storage/store/node_table_data.cpp index 60a91e3a16..8233093f85 100644 --- a/src/storage/store/node_table_data.cpp +++ b/src/storage/store/node_table_data.cpp @@ -13,20 +13,20 @@ namespace kuzu { namespace storage { NodeTableData::NodeTableData(BMFileHandle* dataFH, BMFileHandle* metadataFH, table_id_t tableID, - BufferManager* bufferManager, WAL* wal, const std::vector& properties, + BufferManager* bufferManager, WAL* wal, const std::vector& properties, TablesStatistics* tablesStatistics, bool enableCompression) : TableData{dataFH, metadataFH, tableID, bufferManager, wal, enableCompression, ColumnDataFormat::REGULAR} { columns.reserve(properties.size()); for (auto i = 0u; i < properties.size(); i++) { - auto property = properties[i]; + auto& property = properties[i]; auto metadataDAHInfo = dynamic_cast(tablesStatistics) ->getMetadataDAHInfo(&DUMMY_WRITE_TRANSACTION, tableID, i); auto columnName = - StorageUtils::getColumnName(property->getName(), StorageUtils::ColumnType::DEFAULT, ""); - columns.push_back(ColumnFactory::createColumn(columnName, property->getDataType()->copy(), + StorageUtils::getColumnName(property.getName(), StorageUtils::ColumnType::DEFAULT, ""); + columns.push_back(ColumnFactory::createColumn(columnName, property.getDataType()->copy(), *metadataDAHInfo, dataFH, metadataFH, bufferManager, wal, &DUMMY_WRITE_TRANSACTION, - RWPropertyStats(tablesStatistics, tableID, property->getPropertyID()), + RWPropertyStats(tablesStatistics, tableID, property.getPropertyID()), enableCompression)); } } diff --git a/src/storage/store/rel_table_data.cpp b/src/storage/store/rel_table_data.cpp index d8d082d9bd..7542b93c66 100644 --- a/src/storage/store/rel_table_data.cpp +++ b/src/storage/store/rel_table_data.cpp @@ -91,19 +91,18 @@ RelTableData::RelTableData(BMFileHandle* dataFH, BMFileHandle* metadataFH, adjColumn = ColumnFactory::createColumn(adjColName, LogicalType::INTERNAL_ID(), *adjMetadataDAHInfo, dataFH, metadataFH, bufferManager, wal, &DUMMY_READ_TRANSACTION, RWPropertyStats::empty(), enableCompression); - auto properties = tableSchema->getProperties(); + auto& properties = tableSchema->getPropertiesRef(); columns.reserve(properties.size()); for (auto i = 0u; i < properties.size(); i++) { - auto property = properties[i]; + auto& property = properties[i]; auto metadataDAHInfo = relsStoreStats->getPropertyMetadataDAHInfo( &DUMMY_WRITE_TRANSACTION, tableID, i, direction); auto colName = - StorageUtils::getColumnName(property->getName(), StorageUtils::ColumnType::DEFAULT, + StorageUtils::getColumnName(property.getName(), StorageUtils::ColumnType::DEFAULT, RelDataDirectionUtils::relDirectionToString(direction)); - columns.push_back(ColumnFactory::createColumn(colName, property->getDataType()->copy(), + columns.push_back(ColumnFactory::createColumn(colName, property.getDataType()->copy(), *metadataDAHInfo, dataFH, metadataFH, bufferManager, wal, &DUMMY_READ_TRANSACTION, - RWPropertyStats(relsStoreStats, tableID, property->getPropertyID()), - enableCompression)); + RWPropertyStats(relsStoreStats, tableID, property.getPropertyID()), enableCompression)); } // Set common tableID for adjColumn and relIDColumn. dynamic_cast(adjColumn.get())