Skip to content

Commit 085d3a9

Browse files
committed
handle multiple database instantiations for import caching
1 parent 95010b4 commit 085d3a9

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

src_cpp/include/py_database.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "main/kuzu.h"
44
#include "main/storage_driver.h"
5+
#include "cached_import/py_cached_import.h"
56
#include "pybind_include.h" // IWYU pragma: keep (used for py:: namespace)
67
#define PYBIND11_DETAILED_ERROR_MESSAGES
78
using namespace kuzu::main;

src_cpp/kuzu_binding.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "include/cached_import/py_cached_import.h"
12
#include "include/py_connection.h"
23
#include "include/py_database.h"
34
#include "include/py_prepared_statement.h"
@@ -8,6 +9,10 @@ void bind(py::module& m) {
89
PyConnection::initialize(m);
910
PyPreparedStatement::initialize(m);
1011
PyQueryResult::initialize(m);
12+
auto cleanImportCache = []() {
13+
kuzu::importCache.reset();
14+
};
15+
m.add_object("_clean_import_cache", py::capsule(cleanImportCache));
1116
}
1217

1318
PYBIND11_MODULE(_kuzu, m) {

src_cpp/py_database.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ PyDatabase::PyDatabase(const std::string& databasePath, uint64_t bufferPoolSize,
4848
database = std::make_unique<Database>(databasePath, systemConfig);
4949
database->addBuiltInFunction(READ_PANDAS_FUNC_NAME, kuzu::PandasScanFunction::getFunctionSet());
5050
storageDriver = std::make_unique<kuzu::main::StorageDriver>(database.get());
51+
py::gil_scoped_acquire acquire;
52+
if (kuzu::importCache.get() == nullptr) {
53+
kuzu::importCache = std::make_shared<kuzu::PythonCachedImport>();
54+
}
5155
}
5256

57+
PyDatabase::~PyDatabase() {}
58+
5359
template<class T>
5460
void PyDatabase::scanNodeTable(const std::string& tableName, const std::string& propName,
5561
const py::array_t<uint64_t>& indices, py::array_t<T>& result, int numThreads) {

0 commit comments

Comments
 (0)