Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PropertyNameDataType #1488

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace kuzu::parser;
namespace kuzu {
namespace binder {

std::unique_ptr<BoundStatement> Binder::bindCopy(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindCopyClause(const Statement& statement) {
auto& copyCSV = (Copy&)statement;
auto catalogContent = catalog.getReadOnlyVersion();
auto tableName = copyCSV.getTableName();
Expand Down
32 changes: 15 additions & 17 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ std::unique_ptr<BoundStatement> 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<BoundCreateNodeClause>(
tableName, std::move(boundPropertyNameDataTypes), primaryKeyIdx);
return make_unique<BoundCreateNodeClause>(tableName, std::move(boundProperties), primaryKeyIdx);
}

std::unique_ptr<BoundStatement> Binder::bindCreateRelClause(const Statement& statement) {
Expand All @@ -42,15 +40,14 @@ std::unique_ptr<BoundStatement> 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<BoundCreateRelClause>(tableName, std::move(propertyNameDataTypes),
relMultiplicity, bindNodeTableID(createRelClause.getSrcTableName()),
return make_unique<BoundCreateRelClause>(tableName, std::move(boundProperties), relMultiplicity,
bindNodeTableID(createRelClause.getSrcTableName()),
bindNodeTableID(createRelClause.getDstTableName()));
}

std::unique_ptr<BoundStatement> Binder::bindDropTable(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindDropTableClause(const parser::Statement& statement) {
auto& dropTable = (DropTable&)statement;
auto tableName = dropTable.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -62,7 +59,7 @@ std::unique_ptr<BoundStatement> Binder::bindDropTable(const Statement& statement
return make_unique<BoundDropTable>(tableID, tableName);
}

std::unique_ptr<BoundStatement> Binder::bindRenameTable(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindRenameTableClause(const parser::Statement& statement) {
auto renameTable = (RenameTable&)statement;
auto tableName = renameTable.getTableName();
auto catalogContent = catalog.getReadOnlyVersion();
Expand All @@ -74,7 +71,7 @@ std::unique_ptr<BoundStatement> Binder::bindRenameTable(const Statement& stateme
catalogContent->getTableID(tableName), tableName, renameTable.getNewName());
}

std::unique_ptr<BoundStatement> Binder::bindAddProperty(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindAddPropertyClause(const parser::Statement& statement) {
auto& addProperty = (AddProperty&)statement;
auto tableName = addProperty.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -90,7 +87,7 @@ std::unique_ptr<BoundStatement> Binder::bindAddProperty(const Statement& stateme
tableID, addProperty.getPropertyName(), dataType, defaultVal, tableName);
}

std::unique_ptr<BoundStatement> Binder::bindDropProperty(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindDropPropertyClause(const parser::Statement& statement) {
auto& dropProperty = (DropProperty&)statement;
auto tableName = dropProperty.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -107,7 +104,8 @@ std::unique_ptr<BoundStatement> Binder::bindDropProperty(const Statement& statem
return make_unique<BoundDropProperty>(tableID, propertyID, tableName);
}

std::unique_ptr<BoundStatement> Binder::bindRenameProperty(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindRenamePropertyClause(
const parser::Statement& statement) {
auto& renameProperty = (RenameProperty&)statement;
auto tableName = renameProperty.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -123,9 +121,9 @@ std::unique_ptr<BoundStatement> Binder::bindRenameProperty(const Statement& stat
tableID, tableName, propertyID, renameProperty.getNewName());
}

std::vector<PropertyNameDataType> Binder::bindPropertyNameDataTypes(
std::vector<Property> Binder::bindProperties(
std::vector<std::pair<std::string, std::string>> propertyNameDataTypes) {
std::vector<PropertyNameDataType> boundPropertyNameDataTypes;
std::vector<Property> boundPropertyNameDataTypes;
std::unordered_set<std::string> boundPropertyNames;
for (auto& propertyNameDataType : propertyNameDataTypes) {
if (boundPropertyNames.contains(propertyNameDataType.first)) {
Expand All @@ -145,8 +143,8 @@ std::vector<PropertyNameDataType> Binder::bindPropertyNameDataTypes(
return boundPropertyNameDataTypes;
}

uint32_t Binder::bindPrimaryKey(
std::string pkColName, std::vector<std::pair<std::string, std::string>> propertyNameDataTypes) {
uint32_t Binder::bindPrimaryKey(const std::string& pkColName,
std::vector<std::pair<std::string, std::string>> propertyNameDataTypes) {
uint32_t primaryKeyIdx = UINT32_MAX;
for (auto i = 0u; i < propertyNameDataTypes.size(); i++) {
if (propertyNameDataTypes[i].first == pkColName) {
Expand Down
12 changes: 6 additions & 6 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ std::unique_ptr<BoundStatement> 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);
Expand Down
40 changes: 18 additions & 22 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropertyNameDataType> propertyDefinitions) {
table_id_t CatalogContent::addNodeTableSchema(
std::string tableName, property_id_t primaryKeyId, std::vector<Property> properties) {
table_id_t tableID = assignNextTableID();
std::vector<Property> 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<NodeTableSchema>(
std::move(tableName), tableID, primaryKeyId, std::move(properties));
Expand All @@ -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<PropertyNameDataType>& propertyDefinitions, table_id_t srcTableID,
table_id_t dstTableID) {
std::vector<Property> properties, table_id_t srcTableID, table_id_t dstTableID) {
table_id_t tableID = assignNextTableID();
nodeTableSchemas[srcTableID]->addFwdRelTableID(tableID);
nodeTableSchemas[dstTableID]->addBwdRelTableID(tableID);
std::vector<Property> 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<RelTableSchema>(std::move(tableName), tableID,
relMultiplicity, std::move(properties), srcTableID, dstTableID);
Expand Down Expand Up @@ -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<PropertyNameDataType> propertyDefinitions) {
table_id_t Catalog::addNodeTableSchema(
std::string tableName, property_id_t primaryKeyId, std::vector<Property> propertyDefinitions) {
initCatalogContentForWriteTrxIfNecessary();
auto tableID = catalogContentForWriteTrx->addNodeTableSchema(
std::move(tableName), primaryKeyId, std::move(propertyDefinitions));
Expand All @@ -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<PropertyNameDataType>& propertyDefinitions, table_id_t srcTableID,
const std::vector<Property>& propertyDefinitions, table_id_t srcTableID,
table_id_t dstTableID) {
initCatalogContentForWriteTrxIfNecessary();
auto tableID = catalogContentForWriteTrx->addRelTableSchema(
Expand All @@ -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) {
Expand All @@ -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<RelTableSchema*> Catalog::getAllRelTableSchemasContainBoundTable(
table_id_t boundTableID) {
table_id_t boundTableID) const {
std::unordered_set<RelTableSchema*> relTableSchemas;
auto nodeTableSchema = getReadOnlyVersion()->getNodeTableSchema(boundTableID);
for (auto& fwdRelTableID : nodeTableSchema->fwdRelTableIDSet) {
Expand Down
16 changes: 8 additions & 8 deletions src/include/binder/binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ class Binder {
/*** bind DDL ***/
std::unique_ptr<BoundStatement> bindCreateNodeClause(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindCreateRelClause(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindDropTable(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindRenameTable(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindAddProperty(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindDropProperty(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindRenameProperty(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindDropTableClause(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindRenameTableClause(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindAddPropertyClause(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindDropPropertyClause(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindRenamePropertyClause(const parser::Statement& statement);

std::vector<catalog::PropertyNameDataType> bindPropertyNameDataTypes(
std::vector<catalog::Property> bindProperties(
std::vector<std::pair<std::string, std::string>> propertyNameDataTypes);
uint32_t bindPrimaryKey(std::string pkColName,
uint32_t bindPrimaryKey(const std::string& pkColName,
std::vector<std::pair<std::string, std::string>> 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<BoundStatement> bindCopy(const parser::Statement& statement);
std::unique_ptr<BoundStatement> bindCopyClause(const parser::Statement& statement);

std::vector<std::string> bindFilePaths(const std::vector<std::string>& filePaths);

Expand Down
6 changes: 3 additions & 3 deletions src/include/binder/ddl/bound_create_node_clause.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace binder {

class BoundCreateNodeClause : public BoundCreateTable {
public:
explicit BoundCreateNodeClause(std::string tableName,
std::vector<catalog::PropertyNameDataType> propertyNameDataTypes, uint32_t primaryKeyIdx)
explicit BoundCreateNodeClause(
std::string tableName, std::vector<catalog::Property> 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; }
Expand Down
5 changes: 2 additions & 3 deletions src/include/binder/ddl/bound_create_rel_clause.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ namespace binder {

class BoundCreateRelClause : public BoundCreateTable {
public:
BoundCreateRelClause(std::string tableName,
std::vector<catalog::PropertyNameDataType> propertyNameDataTypes,
BoundCreateRelClause(std::string tableName, std::vector<catalog::Property> 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; }
Expand Down
11 changes: 4 additions & 7 deletions src/include/binder/ddl/bound_create_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ class BoundCreateTable : public BoundDDL {

public:
explicit BoundCreateTable(common::StatementType statementType, std::string tableName,
std::vector<catalog::PropertyNameDataType> propertyNameDataTypes)
: BoundDDL{statementType, std::move(tableName)}, propertyNameDataTypes{
std::move(propertyNameDataTypes)} {}
std::vector<catalog::Property> properties)
: BoundDDL{statementType, std::move(tableName)}, properties{std::move(properties)} {}

inline std::vector<catalog::PropertyNameDataType> getPropertyNameDataTypes() const {
return propertyNameDataTypes;
}
inline std::vector<catalog::Property> getProperties() const { return properties; }

private:
std::vector<catalog::PropertyNameDataType> propertyNameDataTypes;
std::vector<catalog::Property> properties;
};

} // namespace binder
Expand Down
12 changes: 6 additions & 6 deletions src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropertyNameDataType> propertyDefinitions);
std::vector<Property> properties);

common::table_id_t addRelTableSchema(std::string tableName, RelMultiplicity relMultiplicity,
const std::vector<PropertyNameDataType>& propertyDefinitions, common::table_id_t srcTableID,
std::vector<Property> properties, common::table_id_t srcTableID,
common::table_id_t dstTableID);

inline bool containNodeTable(common::table_id_t tableID) const {
Expand Down Expand Up @@ -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<PropertyNameDataType> propertyDefinitions);
std::vector<Property> propertyDefinitions);

common::table_id_t addRelTableSchema(std::string tableName, RelMultiplicity relMultiplicity,
const std::vector<PropertyNameDataType>& propertyDefinitions, common::table_id_t srcTableID,
const std::vector<Property>& propertyDefinitions, common::table_id_t srcTableID,
common::table_id_t dstTableID);

void dropTableSchema(common::table_id_t tableID);
Expand All @@ -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<RelTableSchema*> getAllRelTableSchemasContainBoundTable(
common::table_id_t boundTableID);
common::table_id_t boundTableID) const;

protected:
std::unique_ptr<function::BuiltInVectorOperations> builtInVectorOperations;
Expand Down
Loading