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

Rework DDL operators #3178

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions extension/duckdb_scanner/src/duckdb_catalog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "duckdb_catalog.h"

#include "common/exception/binder.h"
#include "duckdb_table_catalog_entry.h"
#include "duckdb_type_converter.h"

namespace kuzu {
Expand Down
3 changes: 0 additions & 3 deletions extension/duckdb_scanner/src/duckdb_storage.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include "duckdb_storage.h"

#include "binder/ddl/bound_create_table_info.h"
#include "catalog/catalog_entry/table_catalog_entry.h"
#include "common/exception/binder.h"
#include "duckdb_catalog.h"
#include "duckdb_scan.h"
#include "duckdb_type_converter.h"

namespace kuzu {
namespace duckdb_scanner {
Expand Down
3 changes: 1 addition & 2 deletions extension/duckdb_scanner/src/include/duckdb_catalog.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "binder/ddl/bound_create_table_info.h"
#include "catalog/catalog_content.h"
#include "catalog/catalog_entry/table_catalog_entry.h"
#include "duckdb_scan.h"
#include "duckdb_table_catalog_entry.h"

namespace kuzu {
namespace duckdb_scanner {
Expand Down
2 changes: 2 additions & 0 deletions src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include "binder/query/reading_clause/bound_load_from.h"
#include "binder/query/reading_clause/bound_match_clause.h"
#include "binder/query/reading_clause/bound_unwind_clause.h"
#include "catalog/catalog_entry/table_catalog_entry.h"
#include "common/exception/binder.h"
#include "common/exception/message.h"
#include "common/string_format.h"
#include "common/string_utils.h"
#include "function/built_in_function_utils.h"
#include "function/table/bind_input.h"
#include "main/attached_database.h"
#include "main/database.h"
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind/copy/bind_copy_rdf_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "common/constants.h"
#include "common/copier_config/rdf_reader_config.h"
#include "common/keyword/rdf_keyword.h"
#include "function/built_in_function_utils.h"
#include "function/table/bind_input.h"
#include "main/client_context.h"
#include "parser/copy.h"
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind/ddl/bind_create_rdf_graph.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "binder/binder.h"
#include "binder/ddl/bound_create_table_info.h"
#include "catalog/catalog_entry/rdf_graph_catalog_entry.h"
#include "common/keyword/rdf_keyword.h"
#include "parser/ddl/create_table_info.h"
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind_expression/bind_comparison_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "binder/expression/function_expression.h"
#include "binder/expression_binder.h"
#include "common/exception/binder.h"
#include "function/built_in_function_utils.h"
#include "main/client_context.h"

using namespace kuzu::common;
Expand Down
2 changes: 2 additions & 0 deletions src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include "binder/expression/function_expression.h"
#include "binder/expression/property_expression.h"
#include "binder/expression_binder.h"
#include "catalog/catalog_entry/scalar_macro_catalog_entry.h"
#include "common/exception/binder.h"
#include "function/aggregate/collect.h"
#include "function/arithmetic/vector_arithmetic_functions.h"
#include "function/built_in_function_utils.h"
#include "function/cast/vector_cast_functions.h"
#include "function/path/vector_path_functions.h"
#include "function/rewrite_function.h"
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind_expression/bind_subquery_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "binder/expression_binder.h"
#include "common/types/value/value.h"
#include "function/aggregate/count_star.h"
#include "function/built_in_function_utils.h"
#include "parser/expression/parsed_subquery_expression.h"

using namespace kuzu::parser;
Expand Down
2 changes: 2 additions & 0 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "binder/binder.h"

#include "binder/bound_statement_rewriter.h"
#include "catalog/catalog_entry/table_catalog_entry.h"
#include "common/copier_config/csv_reader_config.h"
#include "common/exception/binder.h"
#include "common/keyword/rdf_keyword.h"
#include "common/string_format.h"
#include "common/string_utils.h"
#include "function/built_in_function_utils.h"
#include "function/table_functions.h"
#include "main/client_context.h"

Expand Down
112 changes: 42 additions & 70 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "catalog/catalog.h"

#include "binder/ddl/bound_alter_info.h"
#include "binder/ddl/bound_create_table_info.h"
#include "catalog/catalog_entry/node_table_catalog_entry.h"
#include "catalog/catalog_entry/rdf_graph_catalog_entry.h"
#include "catalog/catalog_entry/rel_group_catalog_entry.h"
Expand Down Expand Up @@ -118,31 +120,35 @@
}
}

table_id_t Catalog::addNodeTableSchema(const binder::BoundCreateTableInfo& info) {
table_id_t Catalog::createTableSchema(const binder::BoundCreateTableInfo& info) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
return readWriteVersion->createNodeTable(info);
}

table_id_t Catalog::addRelTableSchema(const binder::BoundCreateTableInfo& info) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
return readWriteVersion->createRelTable(info);
}

common::table_id_t Catalog::addRelTableGroupSchema(const binder::BoundCreateTableInfo& info) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
auto tableID = readWriteVersion->createRelGroup(info);
auto tableID = readWriteVersion->createTable(info);
auto tableEntry = readWriteVersion->getTableCatalogEntry(tableID);
switch (info.type) {
case TableType::NODE:
case TableType::REL: {
wal->logCreateTableRecord(tableID, info.type);
} break;
case TableType::REL_GROUP: {
auto newRelGroupEntry = ku_dynamic_cast<CatalogEntry*, RelGroupCatalogEntry*>(tableEntry);
for (auto& relTableID : newRelGroupEntry->getRelTableIDs()) {
wal->logCreateTableRecord(relTableID, TableType::REL);
}
} break;
case TableType::RDF: {
auto rdfGraphEntry = ku_dynamic_cast<CatalogEntry*, RDFGraphCatalogEntry*>(tableEntry);
wal->logCreateRdfGraphRecord(tableID, rdfGraphEntry->getResourceTableID(),
rdfGraphEntry->getLiteralTableID(), rdfGraphEntry->getResourceTripleTableID(),
rdfGraphEntry->getLiteralTripleTableID());
} break;
default: {

Check warning on line 145 in src/catalog/catalog.cpp

View check run for this annotation

Codecov / codecov/patch

src/catalog/catalog.cpp#L145

Added line #L145 was not covered by tests
KU_UNREACHABLE;
}
}
return tableID;
}

table_id_t Catalog::addRdfGraphSchema(const binder::BoundCreateTableInfo& info) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
return readWriteVersion->createRDFGraph(info);
}

void Catalog::dropTableSchema(table_id_t tableID) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
Expand Down Expand Up @@ -181,64 +187,30 @@
}
}

void Catalog::renameTable(table_id_t tableID, const std::string& newName) {
void Catalog::alterTableSchema(const binder::BoundAlterInfo& info) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
auto tableEntry = readWriteVersion->getTableCatalogEntry(tableID);
switch (tableEntry->getType()) {
case CatalogEntryType::RDF_GRAPH_ENTRY: {
auto rdfGraphSchema = ku_dynamic_cast<CatalogEntry*, RDFGraphCatalogEntry*>(tableEntry);
readWriteVersion->renameTable(rdfGraphSchema->getResourceTableID(),
RDFGraphCatalogEntry::getResourceTableName(newName));
readWriteVersion->renameTable(rdfGraphSchema->getLiteralTableID(),
RDFGraphCatalogEntry::getLiteralTableName(newName));
readWriteVersion->renameTable(rdfGraphSchema->getResourceTripleTableID(),
RDFGraphCatalogEntry::getResourceTripleTableName(newName));
readWriteVersion->renameTable(rdfGraphSchema->getLiteralTripleTableID(),
RDFGraphCatalogEntry::getLiteralTripleTableName(newName));
readWriteVersion->renameTable(tableID, newName);
readWriteVersion->alterTable(info);
auto tableSchema = ku_dynamic_cast<CatalogEntry*, TableCatalogEntry*>(
ray6080 marked this conversation as resolved.
Show resolved Hide resolved
readWriteVersion->getTableCatalogEntry(info.tableID));
switch (info.alterType) {
case AlterType::ADD_PROPERTY: {
auto& addPropInfo = ku_dynamic_cast<const binder::BoundExtraAlterInfo&,
const binder::BoundExtraAddPropertyInfo&>(*info.extraInfo);
wal->logAddPropertyRecord(
info.tableID, tableSchema->getPropertyID(addPropInfo.propertyName));
} break;
case AlterType::DROP_PROPERTY: {
auto& dropPropInfo = ku_dynamic_cast<const binder::BoundExtraAlterInfo&,
const binder::BoundExtraDropPropertyInfo&>(*info.extraInfo);
wal->logDropPropertyRecord(info.tableID, dropPropInfo.propertyID);
} break;
default: {
readWriteVersion->renameTable(tableID, newName);
// DO NOTHING.
}
}
}

void Catalog::addNodeProperty(
table_id_t tableID, const std::string& propertyName, std::unique_ptr<LogicalType> dataType) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
auto tableEntry = readWriteVersion->getTableCatalogEntry(tableID);
ku_dynamic_cast<CatalogEntry*, TableCatalogEntry*>(tableEntry)
->addProperty(propertyName, std::move(dataType));
}

void Catalog::addRelProperty(
table_id_t tableID, const std::string& propertyName, std::unique_ptr<LogicalType> dataType) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
auto tableEntry = readWriteVersion->getTableCatalogEntry(tableID);
ku_dynamic_cast<CatalogEntry*, TableCatalogEntry*>(tableEntry)
->addProperty(propertyName, std::move(dataType));
}

void Catalog::dropProperty(table_id_t tableID, property_id_t propertyID) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
auto tableEntry = readWriteVersion->getTableCatalogEntry(tableID);
ku_dynamic_cast<CatalogEntry*, TableCatalogEntry*>(tableEntry)->dropProperty(propertyID);
wal->logDropPropertyRecord(tableID, propertyID);
}

void Catalog::renameProperty(
table_id_t tableID, property_id_t propertyID, const std::string& newName) {
KU_ASSERT(readWriteVersion != nullptr);
setToUpdated();
auto tableEntry = readWriteVersion->getTableCatalogEntry(tableID);
ku_dynamic_cast<CatalogEntry*, TableCatalogEntry*>(tableEntry)
->renameProperty(propertyID, newName);
}

void Catalog::addFunction(std::string name, function::function_set functionSet) {
initCatalogContentForWriteTrxIfNecessary();
KU_ASSERT(readWriteVersion != nullptr);
Expand Down
Loading
Loading