Skip to content

Commit

Permalink
try to get rid of dummy transaction when creating foreign table
Browse files Browse the repository at this point in the history
  • Loading branch information
ray6080 committed Sep 11, 2024
1 parent 60cc1af commit 6db4d1d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions extension/duckdb/src/duckdb_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DuckDBCatalog::DuckDBCatalog(std::string dbPath, std::string catalogName,
}
}

void DuckDBCatalog::init() {
void DuckDBCatalog::init(main::ClientContext* clientContext) {
auto query = common::stringFormat(
"select table_name from information_schema.tables where table_catalog = '{}' and "
"table_schema = '{}';",
Expand All @@ -50,7 +50,7 @@ void DuckDBCatalog::init() {
conversionFunc(resultChunk->data[0], tableNamesVector, resultChunk->size());
for (auto i = 0u; i < resultChunk->size(); i++) {
auto tableName = tableNamesVector.getValue<common::ku_string_t>(i).getAsString();
createForeignTable(tableName);
createForeignTable(tableName, clientContext);
}
}

Expand All @@ -60,7 +60,8 @@ static std::string getQuery(const binder::BoundCreateTableInfo& info) {
extraInfo->schemaName, info.tableName);
}

void DuckDBCatalog::createForeignTable(const std::string& tableName) {
void DuckDBCatalog::createForeignTable(const std::string& tableName,
main::ClientContext* clientContext) {
auto info = bindCreateTableInfo(tableName);
if (info == nullptr) {
return;
Expand All @@ -80,7 +81,7 @@ void DuckDBCatalog::createForeignTable(const std::string& tableName) {
for (auto& definition : extraInfo->propertyDefinitions) {
tableEntry->addProperty(definition);
}
tables->createEntry(&transaction::DUMMY_TRANSACTION, std::move(tableEntry));
tables->createEntry(clientContext->getTx(), std::move(tableEntry));
}

static bool getTableInfo(const DuckDBConnector& connector, const std::string& tableName,
Expand Down
2 changes: 1 addition & 1 deletion extension/duckdb/src/duckdb_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::unique_ptr<main::AttachedDatabase> attachDuckDB(std::string dbName, std::st
connector->connect(dbPath, catalogName, clientContext);
auto duckdbCatalog = std::make_unique<DuckDBCatalog>(std::move(dbPath), std::move(catalogName),
DuckDBStorageExtension::DEFAULT_SCHEMA_NAME, clientContext, *connector, attachOption);
duckdbCatalog->init();
duckdbCatalog->init(clientContext);
return std::make_unique<AttachedDuckDBDatabase>(dbName, DuckDBStorageExtension::DB_TYPE,
std::move(duckdbCatalog), std::move(connector));
}
Expand Down
4 changes: 2 additions & 2 deletions extension/duckdb/src/include/duckdb_catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DuckDBCatalog : public extension::CatalogExtension {
main::ClientContext* context, const DuckDBConnector& connector,
const binder::AttachOption& attachOption);

void init() override;
void init(main::ClientContext* clientContext) override;

protected:
bool bindPropertyDefinitions(const std::string& tableName,
Expand All @@ -46,7 +46,7 @@ class DuckDBCatalog : public extension::CatalogExtension {
const std::string& tableName);

private:
void createForeignTable(const std::string& tableName);
void createForeignTable(const std::string& tableName, main::ClientContext* clientContext);

protected:
std::string dbPath;
Expand Down
2 changes: 1 addition & 1 deletion extension/postgres/src/postgres_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::unique_ptr<main::AttachedDatabase> attachPostgres(std::string dbName, std::
connector->connect(dbPath, catalogName, clientContext);
auto catalog = std::make_unique<duckdb_extension::DuckDBCatalog>(dbPath, catalogName,
PostgresStorageExtension::DEFAULT_SCHEMA_NAME, clientContext, *connector, attachOption);
catalog->init();
catalog->init(clientContext);
return std::make_unique<duckdb_extension::AttachedDuckDBDatabase>(dbName,
PostgresStorageExtension::DB_TYPE, std::move(catalog), std::move(connector));
}
Expand Down
2 changes: 1 addition & 1 deletion extension/sqlite/src/sqlite_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::unique_ptr<main::AttachedDatabase> attachSqlite(std::string dbName, std::st
connector->connect(dbPath, catalogName, clientContext);
auto catalog = std::make_unique<duckdb_extension::DuckDBCatalog>(dbPath, catalogName,
SqliteStorageExtension::DEFAULT_SCHEMA_NAME, clientContext, *connector, attachOption);
catalog->init();
catalog->init(clientContext);
return std::make_unique<duckdb_extension::AttachedDuckDBDatabase>(dbName,
SqliteStorageExtension::DB_TYPE, std::move(catalog), std::move(connector));
}
Expand Down
2 changes: 1 addition & 1 deletion src/extension/catalog_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace extension {

void CatalogExtension::invalidateCache() {
tables = std::make_unique<catalog::CatalogSet>();
init();
init(nullptr);

Check warning on line 8 in src/extension/catalog_extension.cpp

View check run for this annotation

Codecov / codecov/patch

src/extension/catalog_extension.cpp#L8

Added line #L8 was not covered by tests
}

} // namespace extension
Expand Down
2 changes: 1 addition & 1 deletion src/include/extension/catalog_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class KUZU_API CatalogExtension : public catalog::Catalog {
public:
CatalogExtension() : Catalog() {}

virtual void init() = 0;
virtual void init(main::ClientContext* clientContext) = 0;

void invalidateCache();
};
Expand Down

0 comments on commit 6db4d1d

Please sign in to comment.