@@ -417,47 +417,37 @@ void ArrowConverter::ToArrowSchema(ArrowSchema *out_schema, const vector<Logical
417417 const vector<string> &names, ClientProperties &options) {
418418 D_ASSERT (out_schema);
419419 D_ASSERT (types.size () == names.size ());
420- D_ASSERT (options.client_context );
421- auto get_schema_func = [&types, &out_schema, &names, &options]() {
422- const idx_t column_count = types.size ();
423- // Allocate as unique_ptr first to clean-up properly on error
424- auto root_holder = make_uniq<DuckDBArrowSchemaHolder>();
420+ const idx_t column_count = types.size ();
421+ // Allocate as unique_ptr first to clean-up properly on error
422+ auto root_holder = make_uniq<DuckDBArrowSchemaHolder>();
425423
426- // Allocate the children
427- root_holder->children .resize (column_count);
428- root_holder->children_ptrs .resize (column_count, nullptr );
429- for (size_t i = 0 ; i < column_count; ++i) {
430- root_holder->children_ptrs [i] = &root_holder->children [i];
431- }
432- out_schema->children = root_holder->children_ptrs .data ();
433- out_schema->n_children = NumericCast<int64_t >(column_count);
424+ // Allocate the children
425+ root_holder->children .resize (column_count);
426+ root_holder->children_ptrs .resize (column_count, nullptr );
427+ for (size_t i = 0 ; i < column_count; ++i) {
428+ root_holder->children_ptrs [i] = &root_holder->children [i];
429+ }
430+ out_schema->children = root_holder->children_ptrs .data ();
431+ out_schema->n_children = NumericCast<int64_t >(column_count);
434432
435- // Store the schema
436- out_schema->format = " +s" ; // struct apparently
437- out_schema->flags = 0 ;
438- out_schema->metadata = nullptr ;
439- out_schema->name = " duckdb_query_result" ;
440- out_schema->dictionary = nullptr ;
433+ // Store the schema
434+ out_schema->format = " +s" ; // struct apparently
435+ out_schema->flags = 0 ;
436+ out_schema->metadata = nullptr ;
437+ out_schema->name = " duckdb_query_result" ;
438+ out_schema->dictionary = nullptr ;
441439
442- // Configure all child schemas
443- for (idx_t col_idx = 0 ; col_idx < column_count; col_idx++) {
444- root_holder->owned_column_names .push_back (AddName (names[col_idx]));
445- auto &child = root_holder->children [col_idx];
446- InitializeChild (child, *root_holder, names[col_idx]);
447- SetArrowFormat (*root_holder, child, types[col_idx], options, *options.client_context );
448- }
449-
450- // Release ownership to caller
451- out_schema->private_data = root_holder.release ();
452- out_schema->release = ReleaseDuckDBArrowSchema;
453- };
454- auto &context = *options.client_context ;
455- if (context.transaction .HasActiveTransaction ()) {
456- get_schema_func ();
457- } else {
458- // We need to run this in a transaction. The arrow schema callback might use the catalog to do lookups.
459- options.client_context ->RunFunctionInTransaction (get_schema_func);
440+ // Configure all child schemas
441+ for (idx_t col_idx = 0 ; col_idx < column_count; col_idx++) {
442+ root_holder->owned_column_names .push_back (AddName (names[col_idx]));
443+ auto &child = root_holder->children [col_idx];
444+ InitializeChild (child, *root_holder, names[col_idx]);
445+ SetArrowFormat (*root_holder, child, types[col_idx], options, *options.client_context );
460446 }
447+
448+ // Release ownership to caller
449+ out_schema->private_data = root_holder.release ();
450+ out_schema->release = ReleaseDuckDBArrowSchema;
461451}
462452
463453} // namespace duckdb
0 commit comments