33#include " duckdb/function/table/arrow.hpp"
44#include " duckdb/main/capi/capi_internal.hpp"
55#include " duckdb/main/prepared_statement_data.hpp"
6- #include < iostream>
76
87using duckdb::ArrowConverter;
98using duckdb::ArrowResultWrapper;
@@ -248,7 +247,13 @@ const char *GetLastError(struct ArrowArrayStream *stream) {
248247
249248void Release (struct ArrowArrayStream *stream) {
250249 if (stream->private_data != nullptr ) {
251- delete reinterpret_cast <PrivateData *>(stream->private_data );
250+ auto private_data = reinterpret_cast <PrivateData *>(stream->private_data );
251+ if (private_data->schema && private_data->schema ->release ) {
252+ private_data->schema ->release (private_data->schema );
253+ private_data->schema = nullptr ;
254+ }
255+
256+ delete private_data;
252257 }
253258
254259 stream->private_data = nullptr ;
@@ -257,7 +262,6 @@ void Release(struct ArrowArrayStream *stream) {
257262
258263duckdb_state Ingest (duckdb_connection connection, const char *table_name, struct ArrowArrayStream *input) {
259264 try {
260- std::cout << " DEBUG: creating arrow scan table function" << std::endl;
261265 auto cconn = reinterpret_cast <duckdb::Connection *>(connection);
262266 cconn
263267 ->TableFunction (" arrow_scan" , {duckdb::Value::POINTER ((uintptr_t )input),
@@ -286,7 +290,6 @@ duckdb_state duckdb_arrow_scan(duckdb_connection connection, const char *table_n
286290 return DuckDBError;
287291 }
288292
289- std::cout << " DEBUG: ingesting arrow array stream into table '" << table_name << " '" << std::endl;
290293 return arrow_array_stream_wrapper::Ingest (connection, table_name, stream);
291294}
292295
@@ -303,13 +306,11 @@ duckdb_state duckdb_arrow_array_scan(duckdb_connection connection, const char *t
303306 return DuckDBError;
304307 }
305308
306- std::cout << " DEBUG: building private data for arrow array stream" << std::endl;
307309 auto private_data = new arrow_array_stream_wrapper::PrivateData;
308310 private_data->schema = reinterpret_cast <ArrowSchema *>(arrow_schema);
309311 private_data->array = reinterpret_cast <ArrowArray *>(arrow_array);
310312 private_data->done = false ;
311313
312- std::cout << " DEBUG: creating arrow array stream" << std::endl;
313314 ArrowArrayStream *stream = new ArrowArrayStream;
314315 *out_stream = reinterpret_cast <duckdb_arrow_stream>(stream);
315316 stream->get_schema = arrow_array_stream_wrapper::GetSchema;
@@ -318,6 +319,5 @@ duckdb_state duckdb_arrow_array_scan(duckdb_connection connection, const char *t
318319 stream->release = arrow_array_stream_wrapper::Release;
319320 stream->private_data = private_data;
320321
321- std::cout << " DEBUG: ingesting arrow array stream into table '" << table_name << " '" << std::endl;
322322 return duckdb_arrow_scan (connection, table_name, reinterpret_cast <duckdb_arrow_stream>(stream));
323323}
0 commit comments