Skip to content

Commit 33cc03d

Browse files
peaseemach-kernel
authored andcommitted
Merge pull request #6 from spiceai/peasee-patch-2
fix: Don't nullify release callback for schemas
1 parent 841fa48 commit 33cc03d

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/function/table/arrow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ void ArrowTableFunction::PopulateArrowTableSchema(DBConfig &config, ArrowTableSc
2323
vector<string> names;
2424
// We first gather the column names and deduplicate them
2525
for (idx_t col_idx = 0; col_idx < static_cast<idx_t>(arrow_schema.n_children); col_idx++) {
26+
if (arrow_schema.children[col_idx] == nullptr) {
27+
throw InvalidInputException("arrow_scan: null schema pointer for column %d", col_idx);
28+
}
2629
const auto &schema = *arrow_schema.children[col_idx];
2730
if (!schema.release) {
2831
throw InvalidInputException("arrow_scan: released schema passed");

src/main/capi/arrow-c.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,6 @@ void EmptyStreamRelease(ArrowArrayStream *stream) {
355355

356356
void FactoryGetSchema(ArrowArrayStream *stream, ArrowSchema &schema) {
357357
stream->get_schema(stream, &schema);
358-
359-
// Need to nullify the root schema's release function here, because streams don't allow us to set the release
360-
// function. For the schema's children, we nullify the release functions in `duckdb_arrow_scan`, so we don't need to
361-
// handle them again here. We set this to nullptr and not EmptySchemaRelease to prevent ArrowSchemaWrapper's
362-
// destructor from destroying the schema (it's the caller's responsibility).
363-
schema.release = nullptr;
364358
}
365359

366360
int GetSchema(struct ArrowArrayStream *stream, struct ArrowSchema *out) {
@@ -370,7 +364,6 @@ int GetSchema(struct ArrowArrayStream *stream, struct ArrowSchema *out) {
370364
}
371365

372366
*out = *private_data->schema;
373-
out->release = EmptySchemaRelease;
374367
return DuckDBSuccess;
375368
}
376369

@@ -406,7 +399,13 @@ const char *GetLastError(struct ArrowArrayStream *stream) {
406399

407400
void Release(struct ArrowArrayStream *stream) {
408401
if (stream->private_data != nullptr) {
409-
delete reinterpret_cast<PrivateData *>(stream->private_data);
402+
auto private_data = reinterpret_cast<PrivateData *>(stream->private_data);
403+
if (private_data->schema && private_data->schema->release) {
404+
private_data->schema->release(private_data->schema);
405+
private_data->schema = nullptr;
406+
}
407+
408+
delete private_data;
410409
}
411410

412411
stream->private_data = nullptr;

0 commit comments

Comments
 (0)