Skip to content

Commit 03db40f

Browse files
committed
wip
1 parent 3d9720d commit 03db40f

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

src/function/table/arrow.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,19 @@
1414
#include "duckdb/parser/tableref/table_function_ref.hpp"
1515
#include "utf8proc_wrapper.hpp"
1616
#include "duckdb/common/arrow/schema_metadata.hpp"
17-
#include <iostream>
1817

1918
namespace duckdb {
2019

2120
void ArrowTableFunction::PopulateArrowTableType(DBConfig &config, ArrowTableType &arrow_table,
2221
const ArrowSchemaWrapper &schema_p, vector<string> &names,
2322
vector<LogicalType> &return_types) {
2423
for (idx_t col_idx = 0; col_idx < static_cast<idx_t>(schema_p.arrow_schema.n_children); col_idx++) {
25-
std::cout << "DEBUG: processing column index " << col_idx << std::endl;
2624
if (schema_p.arrow_schema.children[col_idx] == nullptr) {
2725
throw InvalidInputException("arrow_scan: null schema pointer for column %d", col_idx);
2826
}
2927

3028
auto &schema = *schema_p.arrow_schema.children[col_idx];
31-
std::cout << "DEBUG: column name: '" << schema.name << "'" << std::endl;
3229
if (!schema.release) {
33-
std::cout << "DEBUG: released schema passed" << std::endl;
3430
throw InvalidInputException("arrow_scan: released schema passed");
3531
}
3632
auto arrow_type = ArrowType::GetArrowLogicalType(config, schema);
@@ -75,18 +71,14 @@ unique_ptr<FunctionData> ArrowTableFunction::ArrowScanBind(ClientContext &contex
7571
auto res = make_uniq<ArrowScanFunctionData>(stream_factory_produce, stream_factory_ptr, std::move(dependency));
7672

7773
auto &data = *res;
78-
std::cout << "DEBUG: retrieving arrow schema from stream factory" << std::endl;
7974
stream_factory_get_schema(reinterpret_cast<ArrowArrayStream *>(stream_factory_ptr), data.schema_root.arrow_schema);
80-
std::cout << "DEBUG: populating arrow table type from schema" << std::endl;
8175
PopulateArrowTableType(DBConfig::GetConfig(context), res->arrow_table, data.schema_root, names, return_types);
82-
std::cout << "DEBUG: deduplicating column names" << std::endl;
8376
QueryResult::DeduplicateColumns(names);
8477
res->all_types = return_types;
8578
if (return_types.empty()) {
8679
throw InvalidInputException("Provided table/dataframe must have at least one column");
8780
}
8881

89-
std::cout << "DEBUG: completed arrow scan bind" << std::endl;
9082
return std::move(res);
9183
}
9284

@@ -183,7 +175,6 @@ unique_ptr<LocalTableFunctionState> ArrowTableFunction::ArrowScanInitLocal(Execu
183175
}
184176

185177
void ArrowTableFunction::ArrowScanFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
186-
std::cout << "DEBUG: starting arrow scan function" << std::endl;
187178
if (!data_p.local_state) {
188179
return;
189180
}

src/main/capi/arrow-c.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
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

87
using duckdb::ArrowConverter;
98
using duckdb::ArrowResultWrapper;
@@ -248,7 +247,13 @@ const char *GetLastError(struct ArrowArrayStream *stream) {
248247

249248
void 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

258263
duckdb_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

Comments
 (0)