Skip to content

Commit

Permalink
Fix releasing arrow data
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwinger committed Sep 12, 2023
1 parent 8520fcb commit 2dcc60c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/arrow/arrow_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace kuzu {
namespace common {

static void releaseArrowSchema(ArrowSchema* schema) {
if (!schema || schema->release) {
if (!schema || !schema->release) {
return;
}
schema->release = nullptr;
Expand Down
9 changes: 8 additions & 1 deletion tools/python_api/src_cpp/py_query_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,15 @@ kuzu::pyarrow::Table PyQueryResult::getAsArrow(std::int64_t chunkSize) {

auto typesInfo = queryResult->getColumnTypesInfo();
auto schema = ArrowConverter::toArrowSchema(typesInfo);
auto schemaObj = schemaImportFunc((std::uint64_t)schema.get());
// Prevent arrow from releasing the schema until it gets passed to the table
// It seems like you are expected to pass a new schema for each RecordBatch
auto release = schema->release;
schema->release = [](ArrowSchema*) {};

py::list batches = getArrowChunks(*schema, chunkSize);
auto schemaObj = schemaImportFunc((std::uint64_t)schema.get());

schema->release = release;
return py::cast<kuzu::pyarrow::Table>(fromBatchesFunc(batches, schemaObj));
}

Expand Down

0 comments on commit 2dcc60c

Please sign in to comment.