diff --git a/src/binder/bind/bind_copy.cpp b/src/binder/bind/bind_copy.cpp index f752babbab..6588970262 100644 --- a/src/binder/bind/bind_copy.cpp +++ b/src/binder/bind/bind_copy.cpp @@ -10,7 +10,7 @@ using namespace kuzu::parser; namespace kuzu { namespace binder { -std::unique_ptr Binder::bindCopy(const Statement& statement) { +std::unique_ptr Binder::bindCopyClause(const Statement& statement) { auto& copyCSV = (Copy&)statement; auto catalogContent = catalog.getReadOnlyVersion(); auto tableName = copyCSV.getTableName(); diff --git a/src/binder/bind/bind_ddl.cpp b/src/binder/bind/bind_ddl.cpp index 2d09cf660c..56ce2ee10b 100644 --- a/src/binder/bind/bind_ddl.cpp +++ b/src/binder/bind/bind_ddl.cpp @@ -28,12 +28,10 @@ std::unique_ptr Binder::bindCreateNodeClause(const Statement& st if (catalog.getReadOnlyVersion()->containTable(tableName)) { throw BinderException("Node " + tableName + " already exists."); } - auto boundPropertyNameDataTypes = - bindPropertyNameDataTypes(createNodeClause.getPropertyNameDataTypes()); + auto boundProperties = bindProperties(createNodeClause.getPropertyNameDataTypes()); auto primaryKeyIdx = bindPrimaryKey( createNodeClause.getPKColName(), createNodeClause.getPropertyNameDataTypes()); - return make_unique( - tableName, std::move(boundPropertyNameDataTypes), primaryKeyIdx); + return make_unique(tableName, std::move(boundProperties), primaryKeyIdx); } std::unique_ptr Binder::bindCreateRelClause(const Statement& statement) { @@ -42,15 +40,14 @@ std::unique_ptr Binder::bindCreateRelClause(const Statement& sta if (catalog.getReadOnlyVersion()->containTable(tableName)) { throw BinderException("Rel " + tableName + " already exists."); } - auto propertyNameDataTypes = - bindPropertyNameDataTypes(createRelClause.getPropertyNameDataTypes()); + auto boundProperties = bindProperties(createRelClause.getPropertyNameDataTypes()); auto relMultiplicity = getRelMultiplicityFromString(createRelClause.getRelMultiplicity()); - return make_unique(tableName, std::move(propertyNameDataTypes), - relMultiplicity, bindNodeTableID(createRelClause.getSrcTableName()), + return make_unique(tableName, std::move(boundProperties), relMultiplicity, + bindNodeTableID(createRelClause.getSrcTableName()), bindNodeTableID(createRelClause.getDstTableName())); } -std::unique_ptr Binder::bindDropTable(const Statement& statement) { +std::unique_ptr Binder::bindDropTableClause(const parser::Statement& statement) { auto& dropTable = (DropTable&)statement; auto tableName = dropTable.getTableName(); validateTableExist(catalog, tableName); @@ -62,7 +59,7 @@ std::unique_ptr Binder::bindDropTable(const Statement& statement return make_unique(tableID, tableName); } -std::unique_ptr Binder::bindRenameTable(const Statement& statement) { +std::unique_ptr Binder::bindRenameTableClause(const parser::Statement& statement) { auto renameTable = (RenameTable&)statement; auto tableName = renameTable.getTableName(); auto catalogContent = catalog.getReadOnlyVersion(); @@ -74,7 +71,7 @@ std::unique_ptr Binder::bindRenameTable(const Statement& stateme catalogContent->getTableID(tableName), tableName, renameTable.getNewName()); } -std::unique_ptr Binder::bindAddProperty(const Statement& statement) { +std::unique_ptr Binder::bindAddPropertyClause(const parser::Statement& statement) { auto& addProperty = (AddProperty&)statement; auto tableName = addProperty.getTableName(); validateTableExist(catalog, tableName); @@ -90,7 +87,7 @@ std::unique_ptr Binder::bindAddProperty(const Statement& stateme tableID, addProperty.getPropertyName(), dataType, defaultVal, tableName); } -std::unique_ptr Binder::bindDropProperty(const Statement& statement) { +std::unique_ptr Binder::bindDropPropertyClause(const parser::Statement& statement) { auto& dropProperty = (DropProperty&)statement; auto tableName = dropProperty.getTableName(); validateTableExist(catalog, tableName); @@ -107,7 +104,8 @@ std::unique_ptr Binder::bindDropProperty(const Statement& statem return make_unique(tableID, propertyID, tableName); } -std::unique_ptr Binder::bindRenameProperty(const Statement& statement) { +std::unique_ptr Binder::bindRenamePropertyClause( + const parser::Statement& statement) { auto& renameProperty = (RenameProperty&)statement; auto tableName = renameProperty.getTableName(); validateTableExist(catalog, tableName); @@ -123,9 +121,9 @@ std::unique_ptr Binder::bindRenameProperty(const Statement& stat tableID, tableName, propertyID, renameProperty.getNewName()); } -std::vector Binder::bindPropertyNameDataTypes( +std::vector Binder::bindProperties( std::vector> propertyNameDataTypes) { - std::vector boundPropertyNameDataTypes; + std::vector boundPropertyNameDataTypes; std::unordered_set boundPropertyNames; for (auto& propertyNameDataType : propertyNameDataTypes) { if (boundPropertyNames.contains(propertyNameDataType.first)) { @@ -145,8 +143,8 @@ std::vector Binder::bindPropertyNameDataTypes( return boundPropertyNameDataTypes; } -uint32_t Binder::bindPrimaryKey( - std::string pkColName, std::vector> propertyNameDataTypes) { +uint32_t Binder::bindPrimaryKey(const std::string& pkColName, + std::vector> propertyNameDataTypes) { uint32_t primaryKeyIdx = UINT32_MAX; for (auto i = 0u; i < propertyNameDataTypes.size(); i++) { if (propertyNameDataTypes[i].first == pkColName) { diff --git a/src/binder/binder.cpp b/src/binder/binder.cpp index a47c4e9977..daf2f30a77 100644 --- a/src/binder/binder.cpp +++ b/src/binder/binder.cpp @@ -19,22 +19,22 @@ std::unique_ptr Binder::bind(const Statement& statement) { return bindCreateRelClause(statement); } case StatementType::COPY: { - return bindCopy(statement); + return bindCopyClause(statement); } case StatementType::DROP_TABLE: { - return bindDropTable(statement); + return bindDropTableClause(statement); } case StatementType::RENAME_TABLE: { - return bindRenameTable(statement); + return bindRenameTableClause(statement); } case StatementType::ADD_PROPERTY: { - return bindAddProperty(statement); + return bindAddPropertyClause(statement); } case StatementType::DROP_PROPERTY: { - return bindDropProperty(statement); + return bindDropPropertyClause(statement); } case StatementType::RENAME_PROPERTY: { - return bindRenameProperty(statement); + return bindRenamePropertyClause(statement); } case StatementType::QUERY: { return bindQuery((const RegularQuery&)statement); diff --git a/src/catalog/catalog.cpp b/src/catalog/catalog.cpp index 41e52cb405..41755bacee 100644 --- a/src/catalog/catalog.cpp +++ b/src/catalog/catalog.cpp @@ -189,13 +189,12 @@ CatalogContent::CatalogContent(const CatalogContent& other) { nextTableID = other.nextTableID; } -table_id_t CatalogContent::addNodeTableSchema(std::string tableName, property_id_t primaryKeyId, - std::vector propertyDefinitions) { +table_id_t CatalogContent::addNodeTableSchema( + std::string tableName, property_id_t primaryKeyId, std::vector properties) { table_id_t tableID = assignNextTableID(); - std::vector properties; - for (auto i = 0u; i < propertyDefinitions.size(); ++i) { - auto& propertyDefinition = propertyDefinitions[i]; - properties.push_back(Property::constructNodeProperty(propertyDefinition, i, tableID)); + for (auto i = 0u; i < properties.size(); ++i) { + properties[i].propertyID = i; + properties[i].tableID = tableID; } auto nodeTableSchema = std::make_unique( std::move(tableName), tableID, primaryKeyId, std::move(properties)); @@ -205,19 +204,15 @@ table_id_t CatalogContent::addNodeTableSchema(std::string tableName, property_id } table_id_t CatalogContent::addRelTableSchema(std::string tableName, RelMultiplicity relMultiplicity, - const std::vector& propertyDefinitions, table_id_t srcTableID, - table_id_t dstTableID) { + std::vector properties, table_id_t srcTableID, table_id_t dstTableID) { table_id_t tableID = assignNextTableID(); nodeTableSchemas[srcTableID]->addFwdRelTableID(tableID); nodeTableSchemas[dstTableID]->addBwdRelTableID(tableID); - std::vector properties; - auto propertyID = 0; - auto propertyNameDataType = PropertyNameDataType(INTERNAL_ID_SUFFIX, INTERNAL_ID); - properties.push_back( - Property::constructRelProperty(propertyNameDataType, propertyID++, tableID)); - for (auto& propertyDefinition : propertyDefinitions) { - properties.push_back( - Property::constructRelProperty(propertyDefinition, propertyID++, tableID)); + auto relInternalIDProperty = Property(INTERNAL_ID_SUFFIX, DataType{INTERNAL_ID}); + properties.insert(properties.begin(), relInternalIDProperty); + for (auto i = 0u; i < properties.size(); ++i) { + properties[i].propertyID = i; + properties[i].tableID = tableID; } auto relTableSchema = std::make_unique(std::move(tableName), tableID, relMultiplicity, std::move(properties), srcTableID, dstTableID); @@ -385,8 +380,8 @@ ExpressionType Catalog::getFunctionType(const std::string& name) const { } } -table_id_t Catalog::addNodeTableSchema(std::string tableName, property_id_t primaryKeyId, - std::vector propertyDefinitions) { +table_id_t Catalog::addNodeTableSchema( + std::string tableName, property_id_t primaryKeyId, std::vector propertyDefinitions) { initCatalogContentForWriteTrxIfNecessary(); auto tableID = catalogContentForWriteTrx->addNodeTableSchema( std::move(tableName), primaryKeyId, std::move(propertyDefinitions)); @@ -395,7 +390,7 @@ table_id_t Catalog::addNodeTableSchema(std::string tableName, property_id_t prim } table_id_t Catalog::addRelTableSchema(std::string tableName, RelMultiplicity relMultiplicity, - const std::vector& propertyDefinitions, table_id_t srcTableID, + const std::vector& propertyDefinitions, table_id_t srcTableID, table_id_t dstTableID) { initCatalogContentForWriteTrxIfNecessary(); auto tableID = catalogContentForWriteTrx->addRelTableSchema( @@ -412,7 +407,7 @@ void Catalog::dropTableSchema(table_id_t tableID) { void Catalog::renameTable(table_id_t tableID, std::string newName) { initCatalogContentForWriteTrxIfNecessary(); - catalogContentForWriteTrx->renameTable(tableID, newName); + catalogContentForWriteTrx->renameTable(tableID, std::move(newName)); } void Catalog::addProperty(table_id_t tableID, std::string propertyName, DataType dataType) { @@ -429,13 +424,14 @@ void Catalog::dropProperty(table_id_t tableID, property_id_t propertyID) { wal->logDropPropertyRecord(tableID, propertyID); } -void Catalog::renameProperty(table_id_t tableID, property_id_t propertyID, std::string newName) { +void Catalog::renameProperty( + table_id_t tableID, property_id_t propertyID, const std::string& newName) { initCatalogContentForWriteTrxIfNecessary(); catalogContentForWriteTrx->getTableSchema(tableID)->renameProperty(propertyID, newName); } std::unordered_set Catalog::getAllRelTableSchemasContainBoundTable( - table_id_t boundTableID) { + table_id_t boundTableID) const { std::unordered_set relTableSchemas; auto nodeTableSchema = getReadOnlyVersion()->getNodeTableSchema(boundTableID); for (auto& fwdRelTableID : nodeTableSchema->fwdRelTableIDSet) { diff --git a/src/include/binder/binder.h b/src/include/binder/binder.h index ce08f0ad25..bcb63e71d4 100644 --- a/src/include/binder/binder.h +++ b/src/include/binder/binder.h @@ -41,22 +41,22 @@ class Binder { /*** bind DDL ***/ std::unique_ptr bindCreateNodeClause(const parser::Statement& statement); std::unique_ptr bindCreateRelClause(const parser::Statement& statement); - std::unique_ptr bindDropTable(const parser::Statement& statement); - std::unique_ptr bindRenameTable(const parser::Statement& statement); - std::unique_ptr bindAddProperty(const parser::Statement& statement); - std::unique_ptr bindDropProperty(const parser::Statement& statement); - std::unique_ptr bindRenameProperty(const parser::Statement& statement); + std::unique_ptr bindDropTableClause(const parser::Statement& statement); + std::unique_ptr bindRenameTableClause(const parser::Statement& statement); + std::unique_ptr bindAddPropertyClause(const parser::Statement& statement); + std::unique_ptr bindDropPropertyClause(const parser::Statement& statement); + std::unique_ptr bindRenamePropertyClause(const parser::Statement& statement); - std::vector bindPropertyNameDataTypes( + std::vector bindProperties( std::vector> propertyNameDataTypes); - uint32_t bindPrimaryKey(std::string pkColName, + uint32_t bindPrimaryKey(const std::string& pkColName, std::vector> propertyNameDataTypes); common::property_id_t bindPropertyName( catalog::NodeTableSchema::TableSchema* tableSchema, const std::string& propertyName); common::DataType bindDataType(const std::string& dataType); /*** bind copy csv ***/ - std::unique_ptr bindCopy(const parser::Statement& statement); + std::unique_ptr bindCopyClause(const parser::Statement& statement); std::vector bindFilePaths(const std::vector& filePaths); diff --git a/src/include/binder/ddl/bound_create_node_clause.h b/src/include/binder/ddl/bound_create_node_clause.h index 471bee65a3..627bf13117 100644 --- a/src/include/binder/ddl/bound_create_node_clause.h +++ b/src/include/binder/ddl/bound_create_node_clause.h @@ -7,10 +7,10 @@ namespace binder { class BoundCreateNodeClause : public BoundCreateTable { public: - explicit BoundCreateNodeClause(std::string tableName, - std::vector propertyNameDataTypes, uint32_t primaryKeyIdx) + explicit BoundCreateNodeClause( + std::string tableName, std::vector properties, uint32_t primaryKeyIdx) : BoundCreateTable{common::StatementType::CREATE_NODE_CLAUSE, std::move(tableName), - std::move(propertyNameDataTypes)}, + std::move(properties)}, primaryKeyIdx{primaryKeyIdx} {} inline uint32_t getPrimaryKeyIdx() const { return primaryKeyIdx; } diff --git a/src/include/binder/ddl/bound_create_rel_clause.h b/src/include/binder/ddl/bound_create_rel_clause.h index a7c3895b1b..1c6c19949a 100644 --- a/src/include/binder/ddl/bound_create_rel_clause.h +++ b/src/include/binder/ddl/bound_create_rel_clause.h @@ -7,12 +7,11 @@ namespace binder { class BoundCreateRelClause : public BoundCreateTable { public: - BoundCreateRelClause(std::string tableName, - std::vector propertyNameDataTypes, + BoundCreateRelClause(std::string tableName, std::vector properties, catalog::RelMultiplicity relMultiplicity, common::table_id_t srcTableID, common::table_id_t dstTableID) : BoundCreateTable{common::StatementType::CREATE_REL_CLAUSE, std::move(tableName), - std::move(propertyNameDataTypes)}, + std::move(properties)}, relMultiplicity{relMultiplicity}, srcTableID{srcTableID}, dstTableID{dstTableID} {} inline catalog::RelMultiplicity getRelMultiplicity() const { return relMultiplicity; } diff --git a/src/include/binder/ddl/bound_create_table.h b/src/include/binder/ddl/bound_create_table.h index 673f0545f6..fba5e0fe05 100644 --- a/src/include/binder/ddl/bound_create_table.h +++ b/src/include/binder/ddl/bound_create_table.h @@ -10,16 +10,13 @@ class BoundCreateTable : public BoundDDL { public: explicit BoundCreateTable(common::StatementType statementType, std::string tableName, - std::vector propertyNameDataTypes) - : BoundDDL{statementType, std::move(tableName)}, propertyNameDataTypes{ - std::move(propertyNameDataTypes)} {} + std::vector properties) + : BoundDDL{statementType, std::move(tableName)}, properties{std::move(properties)} {} - inline std::vector getPropertyNameDataTypes() const { - return propertyNameDataTypes; - } + inline std::vector getProperties() const { return properties; } private: - std::vector propertyNameDataTypes; + std::vector properties; }; } // namespace binder diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index fa8fd2812a..9c2ef44ed3 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -36,10 +36,10 @@ class CatalogContent { * Node and Rel table functions. */ common::table_id_t addNodeTableSchema(std::string tableName, common::property_id_t primaryKeyId, - std::vector propertyDefinitions); + std::vector properties); common::table_id_t addRelTableSchema(std::string tableName, RelMultiplicity relMultiplicity, - const std::vector& propertyDefinitions, common::table_id_t srcTableID, + std::vector properties, common::table_id_t srcTableID, common::table_id_t dstTableID); inline bool containNodeTable(common::table_id_t tableID) const { @@ -193,10 +193,10 @@ class Catalog { common::ExpressionType getFunctionType(const std::string& name) const; common::table_id_t addNodeTableSchema(std::string tableName, common::property_id_t primaryKeyId, - std::vector propertyDefinitions); + std::vector propertyDefinitions); common::table_id_t addRelTableSchema(std::string tableName, RelMultiplicity relMultiplicity, - const std::vector& propertyDefinitions, common::table_id_t srcTableID, + const std::vector& propertyDefinitions, common::table_id_t srcTableID, common::table_id_t dstTableID); void dropTableSchema(common::table_id_t tableID); @@ -209,10 +209,10 @@ class Catalog { void dropProperty(common::table_id_t tableID, common::property_id_t propertyID); void renameProperty( - common::table_id_t tableID, common::property_id_t propertyID, std::string newName); + common::table_id_t tableID, common::property_id_t propertyID, const std::string& newName); std::unordered_set getAllRelTableSchemasContainBoundTable( - common::table_id_t boundTableID); + common::table_id_t boundTableID) const; protected: std::unique_ptr builtInVectorOperations; diff --git a/src/include/catalog/catalog_structs.h b/src/include/catalog/catalog_structs.h index f0de97aac5..d55d4be269 100644 --- a/src/include/catalog/catalog_structs.h +++ b/src/include/catalog/catalog_structs.h @@ -15,42 +15,20 @@ enum RelMultiplicity : uint8_t { MANY_MANY, MANY_ONE, ONE_MANY, ONE_ONE }; RelMultiplicity getRelMultiplicityFromString(const std::string& relMultiplicityString); std::string getRelMultiplicityAsString(RelMultiplicity relMultiplicity); -// A PropertyNameDataType consists of its name, id, and dataType. -struct PropertyNameDataType { - // This constructor is needed for ser/deser functions - PropertyNameDataType(){}; - PropertyNameDataType(std::string name, common::DataTypeID dataTypeID) - : PropertyNameDataType{std::move(name), common::DataType(dataTypeID)} { - assert(dataTypeID != common::VAR_LIST); - } - PropertyNameDataType(std::string name, common::DataType dataType) - : name{std::move(name)}, dataType{std::move(dataType)} {}; - virtual ~PropertyNameDataType() = default; - - std::string name; - common::DataType dataType; -}; - -struct Property : PropertyNameDataType { +struct Property { public: // This constructor is needed for ser/deser functions - Property() = default; - + Property() : Property{"", common::DataType{}} {}; + Property(std::string name, common::DataType dataType) + : Property{std::move(name), std::move(dataType), common::INVALID_PROPERTY_ID, + common::INVALID_TABLE_ID} {} Property(std::string name, common::DataType dataType, common::property_id_t propertyID, common::table_id_t tableID) - : PropertyNameDataType{std::move(name), std::move(dataType)}, + : name{std::move(name)}, dataType{std::move(dataType)}, propertyID{propertyID}, tableID{tableID} {} - static Property constructNodeProperty(const PropertyNameDataType& nameDataType, - common::property_id_t propertyID, common::table_id_t tableID) { - return {nameDataType.name, nameDataType.dataType, propertyID, tableID}; - } - - static inline Property constructRelProperty(const PropertyNameDataType& nameDataType, - common::property_id_t propertyID, common::table_id_t tableID) { - return {nameDataType.name, nameDataType.dataType, propertyID, tableID}; - } - + std::string name; + common::DataType dataType; common::property_id_t propertyID; common::table_id_t tableID; }; diff --git a/src/include/planner/logical_plan/logical_operator/logical_create_node_table.h b/src/include/planner/logical_plan/logical_operator/logical_create_node_table.h index 2b01bbf34f..68823317bb 100644 --- a/src/include/planner/logical_plan/logical_operator/logical_create_node_table.h +++ b/src/include/planner/logical_plan/logical_operator/logical_create_node_table.h @@ -7,18 +7,17 @@ namespace planner { class LogicalCreateNodeTable : public LogicalCreateTable { public: - LogicalCreateNodeTable(std::string tableName, - std::vector propertyNameDataTypes, uint32_t primaryKeyIdx, - std::shared_ptr outputExpression) + LogicalCreateNodeTable(std::string tableName, std::vector properties, + uint32_t primaryKeyIdx, std::shared_ptr outputExpression) : LogicalCreateTable{LogicalOperatorType::CREATE_NODE_TABLE, std::move(tableName), - std::move(propertyNameDataTypes), std::move(outputExpression)}, + std::move(properties), std::move(outputExpression)}, primaryKeyIdx{primaryKeyIdx} {} inline uint32_t getPrimaryKeyIdx() const { return primaryKeyIdx; } inline std::unique_ptr copy() override { return make_unique( - tableName, propertyNameDataTypes, primaryKeyIdx, outputExpression); + tableName, properties, primaryKeyIdx, outputExpression); } private: diff --git a/src/include/planner/logical_plan/logical_operator/logical_create_rel_table.h b/src/include/planner/logical_plan/logical_operator/logical_create_rel_table.h index 1028a87f00..1b72dd6426 100644 --- a/src/include/planner/logical_plan/logical_operator/logical_create_rel_table.h +++ b/src/include/planner/logical_plan/logical_operator/logical_create_rel_table.h @@ -8,12 +8,11 @@ namespace planner { class LogicalCreateRelTable : public LogicalCreateTable { public: - LogicalCreateRelTable(std::string tableName, - std::vector propertyNameDataTypes, + LogicalCreateRelTable(std::string tableName, std::vector properties, catalog::RelMultiplicity relMultiplicity, common::table_id_t srcTableID, common::table_id_t dstTableID, std::shared_ptr outputExpression) : LogicalCreateTable{LogicalOperatorType::CREATE_REL_TABLE, std::move(tableName), - std::move(propertyNameDataTypes), std::move(outputExpression)}, + std::move(properties), std::move(outputExpression)}, relMultiplicity{relMultiplicity}, srcTableID{srcTableID}, dstTableID{dstTableID} {} inline catalog::RelMultiplicity getRelMultiplicity() const { return relMultiplicity; } @@ -23,8 +22,8 @@ class LogicalCreateRelTable : public LogicalCreateTable { inline common::table_id_t getDstTableID() const { return dstTableID; } inline std::unique_ptr copy() override { - return make_unique(tableName, propertyNameDataTypes, relMultiplicity, - srcTableID, dstTableID, outputExpression); + return make_unique( + tableName, properties, relMultiplicity, srcTableID, dstTableID, outputExpression); } private: diff --git a/src/include/planner/logical_plan/logical_operator/logical_create_table.h b/src/include/planner/logical_plan/logical_operator/logical_create_table.h index 42cb253324..ebf60ee875 100644 --- a/src/include/planner/logical_plan/logical_operator/logical_create_table.h +++ b/src/include/planner/logical_plan/logical_operator/logical_create_table.h @@ -8,17 +8,15 @@ namespace planner { class LogicalCreateTable : public LogicalDDL { public: LogicalCreateTable(LogicalOperatorType operatorType, std::string tableName, - std::vector propertyNameDataTypes, + std::vector properties, std::shared_ptr outputExpression) : LogicalDDL{operatorType, std::move(tableName), std::move(outputExpression)}, - propertyNameDataTypes{std::move(propertyNameDataTypes)} {} + properties{std::move(properties)} {} - inline std::vector getPropertyNameDataTypes() const { - return propertyNameDataTypes; - } + inline std::vector getPropertyNameDataTypes() const { return properties; } protected: - std::vector propertyNameDataTypes; + std::vector properties; }; } // namespace planner diff --git a/src/include/processor/operator/ddl/create_node_table.h b/src/include/processor/operator/ddl/create_node_table.h index a65dd95c2b..ab152749c0 100644 --- a/src/include/processor/operator/ddl/create_node_table.h +++ b/src/include/processor/operator/ddl/create_node_table.h @@ -9,11 +9,11 @@ namespace processor { class CreateNodeTable : public CreateTable { public: CreateNodeTable(catalog::Catalog* catalog, std::string tableName, - std::vector propertyNameDataTypes, uint32_t primaryKeyIdx, - const DataPos& outputPos, uint32_t id, const std::string& paramsString, + std::vector properties, uint32_t primaryKeyIdx, const DataPos& outputPos, + uint32_t id, const std::string& paramsString, storage::NodesStatisticsAndDeletedIDs* nodesStatistics) : CreateTable{PhysicalOperatorType::CREATE_NODE_TABLE, catalog, std::move(tableName), - std::move(propertyNameDataTypes), outputPos, id, paramsString}, + std::move(properties), outputPos, id, paramsString}, primaryKeyIdx{primaryKeyIdx}, nodesStatistics{nodesStatistics} {} void executeDDLInternal() override; @@ -21,8 +21,8 @@ class CreateNodeTable : public CreateTable { std::string getOutputMsg() override; std::unique_ptr clone() override { - return std::make_unique(catalog, tableName, propertyNameDataTypes, - primaryKeyIdx, outputPos, id, paramsString, nodesStatistics); + return std::make_unique(catalog, tableName, properties, primaryKeyIdx, + outputPos, id, paramsString, nodesStatistics); } private: diff --git a/src/include/processor/operator/ddl/create_rel_table.h b/src/include/processor/operator/ddl/create_rel_table.h index f46f636cab..8605b345d9 100644 --- a/src/include/processor/operator/ddl/create_rel_table.h +++ b/src/include/processor/operator/ddl/create_rel_table.h @@ -9,12 +9,11 @@ namespace processor { class CreateRelTable : public CreateTable { public: CreateRelTable(catalog::Catalog* catalog, std::string tableName, - std::vector propertyNameDataTypes, - catalog::RelMultiplicity relMultiplicity, common::table_id_t srcTableID, - common::table_id_t dstTableID, const DataPos& outputPos, uint32_t id, - const std::string& paramsString, storage::RelsStatistics* relsStatistics) + std::vector properties, catalog::RelMultiplicity relMultiplicity, + common::table_id_t srcTableID, common::table_id_t dstTableID, const DataPos& outputPos, + uint32_t id, const std::string& paramsString, storage::RelsStatistics* relsStatistics) : CreateTable{PhysicalOperatorType::CREATE_REL_TABLE, catalog, std::move(tableName), - std::move(propertyNameDataTypes), outputPos, id, paramsString}, + std::move(properties), outputPos, id, paramsString}, relMultiplicity{relMultiplicity}, srcTableID{srcTableID}, dstTableID{dstTableID}, relsStatistics{relsStatistics} {} @@ -23,8 +22,8 @@ class CreateRelTable : public CreateTable { std::string getOutputMsg() override; std::unique_ptr clone() override { - return make_unique(catalog, tableName, propertyNameDataTypes, - relMultiplicity, srcTableID, dstTableID, outputPos, id, paramsString, relsStatistics); + return make_unique(catalog, tableName, properties, relMultiplicity, + srcTableID, dstTableID, outputPos, id, paramsString, relsStatistics); } private: diff --git a/src/include/processor/operator/ddl/create_table.h b/src/include/processor/operator/ddl/create_table.h index 5aae4bd046..8935c987a1 100644 --- a/src/include/processor/operator/ddl/create_table.h +++ b/src/include/processor/operator/ddl/create_table.h @@ -8,15 +8,15 @@ namespace processor { class CreateTable : public DDL { public: CreateTable(PhysicalOperatorType operatorType, catalog::Catalog* catalog, std::string tableName, - std::vector propertyNameDataTypes, const DataPos& outputPos, - uint32_t id, const std::string& paramsString) + std::vector properties, const DataPos& outputPos, uint32_t id, + const std::string& paramsString) : DDL{operatorType, catalog, outputPos, id, paramsString}, tableName{std::move(tableName)}, - propertyNameDataTypes{std::move(propertyNameDataTypes)} {} + properties{std::move(properties)} {} ~CreateTable() override = default; protected: std::string tableName; - std::vector propertyNameDataTypes; + std::vector properties; }; } // namespace processor diff --git a/src/include/processor/operator/order_by/order_by.h b/src/include/processor/operator/order_by/order_by.h index 7d6000de4c..0081cfee9a 100644 --- a/src/include/processor/operator/order_by/order_by.h +++ b/src/include/processor/operator/order_by/order_by.h @@ -35,7 +35,7 @@ class SharedFactorizedTablesAndSortedKeyBlocks { if (factorizedTableIdx >= factorizedTables.size()) { factorizedTables.resize(factorizedTableIdx + 1); } - factorizedTables[factorizedTableIdx] = move(factorizedTable); + factorizedTables[factorizedTableIdx] = std::move(factorizedTable); } void appendSortedKeyBlock(std::shared_ptr mergedDataBlocks) { diff --git a/src/include/storage/index/hash_index.h b/src/include/storage/index/hash_index.h index d5347c1c5f..0b526d90fc 100644 --- a/src/include/storage/index/hash_index.h +++ b/src/include/storage/index/hash_index.h @@ -146,9 +146,6 @@ class HashIndex : public BaseHashIndex { class PrimaryKeyIndex { - friend class HashIndexInt64Test; - friend class HashIndexStringTest; - public: PrimaryKeyIndex(const StorageStructureIDAndFName& storageStructureIDAndFName, const common::DataType& keyDataType, BufferManager& bufferManager, WAL* wal) diff --git a/src/planner/planner.cpp b/src/planner/planner.cpp index 46774dd8f8..d87795ee55 100644 --- a/src/planner/planner.cpp +++ b/src/planner/planner.cpp @@ -82,7 +82,7 @@ std::unique_ptr Planner::planCreateNodeTable(const BoundStatement& auto& createNodeClause = (BoundCreateNodeClause&)statement; auto plan = std::make_unique(); auto createNodeTable = make_shared(createNodeClause.getTableName(), - createNodeClause.getPropertyNameDataTypes(), createNodeClause.getPrimaryKeyIdx(), + createNodeClause.getProperties(), createNodeClause.getPrimaryKeyIdx(), statement.getStatementResult()->getSingleExpressionToCollect()); plan->setLastOperator(std::move(createNodeTable)); return plan; @@ -92,7 +92,7 @@ std::unique_ptr Planner::planCreateRelTable(const BoundStatement& s auto& createRelClause = (BoundCreateRelClause&)statement; auto plan = std::make_unique(); auto createRelTable = make_shared(createRelClause.getTableName(), - createRelClause.getPropertyNameDataTypes(), createRelClause.getRelMultiplicity(), + createRelClause.getProperties(), createRelClause.getRelMultiplicity(), createRelClause.getSrcTableID(), createRelClause.getDstTableID(), statement.getStatementResult()->getSingleExpressionToCollect()); plan->setLastOperator(std::move(createRelTable)); diff --git a/src/processor/operator/ddl/create_node_table.cpp b/src/processor/operator/ddl/create_node_table.cpp index ca613591dd..d4a9837309 100644 --- a/src/processor/operator/ddl/create_node_table.cpp +++ b/src/processor/operator/ddl/create_node_table.cpp @@ -8,7 +8,7 @@ namespace kuzu { namespace processor { void CreateNodeTable::executeDDLInternal() { - auto newTableID = catalog->addNodeTableSchema(tableName, primaryKeyIdx, propertyNameDataTypes); + auto newTableID = catalog->addNodeTableSchema(tableName, primaryKeyIdx, properties); nodesStatistics->addNodeStatisticsAndDeletedIDs( catalog->getWriteVersion()->getNodeTableSchema(newTableID)); } diff --git a/src/processor/operator/ddl/create_rel_table.cpp b/src/processor/operator/ddl/create_rel_table.cpp index da96cd8f74..6e869301e4 100644 --- a/src/processor/operator/ddl/create_rel_table.cpp +++ b/src/processor/operator/ddl/create_rel_table.cpp @@ -8,8 +8,8 @@ namespace kuzu { namespace processor { void CreateRelTable::executeDDLInternal() { - auto newRelTableID = catalog->addRelTableSchema( - tableName, relMultiplicity, propertyNameDataTypes, srcTableID, dstTableID); + auto newRelTableID = + catalog->addRelTableSchema(tableName, relMultiplicity, properties, srcTableID, dstTableID); relsStatistics->addTableStatistic(catalog->getWriteVersion()->getRelTableSchema(newRelTableID)); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d2cd06223a..63590a5131 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,7 +15,6 @@ add_subdirectory(test_helper) add_subdirectory(graph_test) add_subdirectory(binder) add_subdirectory(c_api) -add_subdirectory(catalog) add_subdirectory(common) add_subdirectory(copy) add_subdirectory(demo_db) diff --git a/test/catalog/CMakeLists.txt b/test/catalog/CMakeLists.txt deleted file mode 100644 index fb4325fe4a..0000000000 --- a/test/catalog/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_kuzu_test(catalog_test catalog_test.cpp) diff --git a/test/catalog/catalog_test.cpp b/test/catalog/catalog_test.cpp deleted file mode 100644 index 960d6fcf5e..0000000000 --- a/test/catalog/catalog_test.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "catalog/catalog.h" -#include "graph_test/graph_test.h" - -using namespace kuzu::catalog; -using namespace kuzu::common; - -class CatalogTest : public testing::Test { -public: - const std::string CATALOG_TEMP_DIRECTORY = - kuzu::testing::TestHelper::appendKuzuRootPath("test/catalog_temp"); - - void SetUp() override { - FileUtils::createDir(CATALOG_TEMP_DIRECTORY); - LoggerUtils::createLogger(LoggerConstants::LoggerEnum::CATALOG); - catalog = std::make_unique(); - setupCatalog(); - } - - void TearDown() override { - FileUtils::removeDir(CATALOG_TEMP_DIRECTORY); - LoggerUtils::dropLogger(LoggerConstants::LoggerEnum::CATALOG); - } - - void setupCatalog() { - std::vector personProperties; - personProperties.emplace_back("ID", INT64); - personProperties.emplace_back("fName", STRING); - personProperties.emplace_back("gender", INT64); - personProperties.emplace_back("isStudent", BOOL); - personProperties.emplace_back("isWorker", BOOL); - personProperties.emplace_back("age", INT64); - personProperties.emplace_back("eyeSight", DOUBLE); - personProperties.emplace_back("birthdate", DATE); - personProperties.emplace_back("registerTime", TIMESTAMP); - personProperties.emplace_back("lastJobDuration", INTERVAL); - personProperties.emplace_back( - "workedHours", DataType(VAR_LIST, std::make_unique(INT64))); - personProperties.emplace_back( - "usedNames", DataType(VAR_LIST, std::make_unique(STRING))); - personProperties.emplace_back("courseScoresPerTerm", - DataType( - VAR_LIST, std::make_unique(VAR_LIST, std::make_unique(INT64)))); - PERSON_TABLE_ID = catalog->getReadOnlyVersion()->addNodeTableSchema( - "person", 0 /* primaryKeyIdx */, std::move(personProperties)); - - std::vector knowsProperties; - knowsProperties.emplace_back("START_ID_TABLE", STRING); - knowsProperties.emplace_back("START_ID", INT64); - knowsProperties.emplace_back("END_ID_TABLE", STRING); - knowsProperties.emplace_back("END_ID", INT64); - knowsProperties.emplace_back("date", DATE); - knowsProperties.emplace_back("meetTime", TIMESTAMP); - knowsProperties.emplace_back("validInterval", INTERVAL); - KNOWS_TABLE_ID = catalog->getReadOnlyVersion()->addRelTableSchema( - "knows", MANY_MANY, knowsProperties, 0 /* srcTableID */, 0 /* dstTableID */); - } - -public: - std::unique_ptr catalog; - table_id_t PERSON_TABLE_ID; - table_id_t KNOWS_TABLE_ID; -}; - -TEST_F(CatalogTest, AddTablesTest) { - // Test getting table id from string - ASSERT_TRUE(catalog->getReadOnlyVersion()->containNodeTable("person")); - ASSERT_FALSE(catalog->getReadOnlyVersion()->containNodeTable("organisation")); - ASSERT_TRUE(catalog->getReadOnlyVersion()->containRelTable("knows")); - ASSERT_FALSE(catalog->getReadOnlyVersion()->containRelTable("likes")); - ASSERT_EQ(catalog->getReadOnlyVersion()->getTableID("person"), PERSON_TABLE_ID); - ASSERT_EQ(catalog->getReadOnlyVersion()->getTableID("knows"), KNOWS_TABLE_ID); - ASSERT_NE(PERSON_TABLE_ID, KNOWS_TABLE_ID); - // Test rel single relMultiplicity - ASSERT_FALSE( - catalog->getReadOnlyVersion()->isSingleMultiplicityInDirection(KNOWS_TABLE_ID, FWD)); - // Test property definition - // primary key of person table is a column name ID, which is at idx 0 in the predefined - // properties - ASSERT_EQ(0 /* pkpropertyID */, - ((NodeTableSchema*)catalog->getReadOnlyVersion()->getTableSchema(PERSON_TABLE_ID)) - ->primaryKeyPropertyID); - - ASSERT_EQ(catalog->getReadOnlyVersion()->getNodeProperty(PERSON_TABLE_ID, "age").propertyID, 5); - ASSERT_EQ( - catalog->getReadOnlyVersion()->getNodeProperty(PERSON_TABLE_ID, "age").dataType.typeID, - INT64); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "birthdate") - .dataType.typeID, - DATE); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "registerTime") - .dataType.typeID, - TIMESTAMP); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "lastJobDuration") - .dataType.typeID, - INTERVAL); - - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "workedHours") - .dataType.typeID, - VAR_LIST); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "workedHours") - .dataType.getChildType() - ->typeID, - INT64); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "usedNames") - .dataType.typeID, - VAR_LIST); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "usedNames") - .dataType.getChildType() - ->typeID, - STRING); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "courseScoresPerTerm") - .dataType.typeID, - VAR_LIST); - - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "courseScoresPerTerm") - .dataType.getChildType() - ->typeID, - VAR_LIST); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getNodeProperty(PERSON_TABLE_ID, "courseScoresPerTerm") - .dataType.getChildType() - ->getChildType() - ->typeID, - INT64); - ASSERT_EQ(catalog->getReadOnlyVersion()->getRelProperty(KNOWS_TABLE_ID, "date").dataType.typeID, - DATE); - ASSERT_EQ( - catalog->getReadOnlyVersion()->getRelProperty(KNOWS_TABLE_ID, "meetTime").dataType.typeID, - TIMESTAMP); - ASSERT_EQ(catalog->getReadOnlyVersion() - ->getRelProperty(KNOWS_TABLE_ID, "validInterval") - .dataType.typeID, - INTERVAL); -} - -TEST_F(CatalogTest, SaveAndReadTest) { - catalog->getReadOnlyVersion()->saveToFile(CATALOG_TEMP_DIRECTORY, DBFileType::ORIGINAL); - auto newCatalog = std::make_unique(); - newCatalog->getReadOnlyVersion()->readFromFile(CATALOG_TEMP_DIRECTORY, DBFileType::ORIGINAL); - /* primary key of person table is a column name ID, which is at idx 0 in the predefined - * properties */ - ASSERT_EQ(0 /* pkpropertyID */, - ((NodeTableSchema*)newCatalog->getReadOnlyVersion()->getTableSchema(PERSON_TABLE_ID)) - ->primaryKeyPropertyID); - // Test getting table id from string - ASSERT_TRUE(catalog->getReadOnlyVersion()->containNodeTable("person")); - ASSERT_FALSE(catalog->getReadOnlyVersion()->containNodeTable("organisation")); - ASSERT_TRUE(catalog->getReadOnlyVersion()->containRelTable("knows")); - ASSERT_FALSE(catalog->getReadOnlyVersion()->containRelTable("likes")); -}