diff --git a/ext/arrow-duckdb/arrow-duckdb-registration.cpp b/ext/arrow-duckdb/arrow-duckdb-registration.cpp index 2e770af..42ad772 100644 --- a/ext/arrow-duckdb/arrow-duckdb-registration.cpp +++ b/ext/arrow-duckdb/arrow-duckdb-registration.cpp @@ -163,14 +163,11 @@ namespace { } arrow::compute::Expression - convert_filters(std::unordered_map< - idx_t, - std::unique_ptr - > &filters, + convert_filters(duckdb::TableFilterSet *filter_set, std::unordered_map &column_names) { std::vector expressions; - for (auto it = filters.begin(); it != filters.end(); ++it) { + for (auto it = filter_set->filters.begin(); it != filter_set->filters.end(); ++it) { expressions.emplace_back( std::move(convert_filter(it->second.get(), column_names[it->first]))); } @@ -192,7 +189,7 @@ namespace { if (have_filter) { ARROW_RETURN_NOT_OK( scanner_builder->Filter( - convert_filters(parameters.filters->filters, + convert_filters(parameters.filters, parameters.projected_columns.projection_map))); } if (!parameters.projected_columns.columns.empty()) { @@ -202,7 +199,7 @@ namespace { } ARROW_ASSIGN_OR_RAISE(auto scanner, scanner_builder->Finish()); ARROW_ASSIGN_OR_RAISE(auto reader, scanner->ToRecordBatchReader()); - auto stream_wrapper = duckdb::make_unique(); + auto stream_wrapper = duckdb::make_uniq(); ARROW_RETURN_NOT_OK( arrow::ExportRecordBatchReader(reader, &(stream_wrapper->arrow_array_stream))); @@ -227,8 +224,13 @@ namespace { { auto garrow_table = GARROW_TABLE(reinterpret_cast(data)); auto arrow_table = garrow_table_get_raw(garrow_table); - arrow::ExportSchema(*(arrow_table->schema()), - reinterpret_cast(&schema)); + auto export_schema_status = arrow::ExportSchema(*(arrow_table->schema()), + reinterpret_cast(&schema)); + if (!export_schema_status.ok()) { + throw std::runtime_error( + std::string("[arrow][get_schema] failed to export schema: ") + + export_schema_status.ToString()); + } } } diff --git a/ext/arrow-duckdb/arrow-duckdb.cpp b/ext/arrow-duckdb/arrow-duckdb.cpp index f3bdc2c..b8b9160 100644 --- a/ext/arrow-duckdb/arrow-duckdb.cpp +++ b/ext/arrow-duckdb/arrow-duckdb.cpp @@ -20,7 +20,9 @@ #include +extern "C" { #include +} #include "arrow-duckdb-registration.hpp" @@ -99,7 +101,7 @@ namespace { result_ensure_gschema(Result *result) { ArrowSchema c_abi_schema; - duckdb_arrow_schema schema = &c_abi_schema; + auto schema = reinterpret_cast(&c_abi_schema); auto state = duckdb_query_arrow_schema(result->arrow, &schema); if (state == DuckDBError) { free(result->error_message); @@ -121,7 +123,7 @@ namespace { result_fetch_internal(VALUE self, Result *result) { ArrowArray c_abi_array = {}; - duckdb_arrow_array array = &c_abi_array; + auto array = reinterpret_cast(&c_abi_array); auto state = duckdb_query_arrow_array(result->arrow, &array); if (state == DuckDBError) { free(result->error_message); @@ -219,8 +221,7 @@ namespace { VALUE query_sql_arrow(VALUE self, VALUE sql) { - rubyDuckDBConnection *ctx; - Data_Get_Struct(self, rubyDuckDBConnection, ctx); + auto ctx = get_struct_connection(self); if (!(ctx->con)) { rb_raise(eDuckDBError, "Database connection closed"); @@ -253,8 +254,7 @@ namespace { VALUE query_unregister_arrow(VALUE self, VALUE name) { - rubyDuckDBConnection *ctx; - Data_Get_Struct(self, rubyDuckDBConnection, ctx); + auto ctx = get_struct_connection(self); if (!(ctx->con)) { rb_raise(eDuckDBError, "Database connection closed"); @@ -293,8 +293,7 @@ namespace { VALUE query_register_arrow(VALUE self, VALUE name, VALUE arrow_table) { - rubyDuckDBConnection *ctx; - Data_Get_Struct(self, rubyDuckDBConnection, ctx); + auto ctx = get_struct_connection(self); if (!(ctx->con)) { rb_raise(eDuckDBError, "Database connection closed"); @@ -329,8 +328,7 @@ namespace { VALUE prepared_statement_execute_arrow(VALUE self) { - rubyDuckDBPreparedStatement *ctx; - Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx); + auto ctx = get_struct_prepared_statement(self); ID id_new; CONST_ID(id_new, "new"); diff --git a/test/test-connection.rb b/test/test-connection.rb index 22d84d4..23b72ec 100644 --- a/test/test-connection.rb +++ b/test/test-connection.rb @@ -35,7 +35,7 @@ def setup result = @connection.query("SELECT * FROM users WHERE name = ?", 'alice', output: :arrow) - assert_equal([Arrow::RecordBatch.new("string" => ["alice"])], + assert_equal([Arrow::RecordBatch.new("name" => ["alice"])], result.to_a) end end diff --git a/test/test-prepared-statement.rb b/test/test-prepared-statement.rb index 43b555e..3b21826 100644 --- a/test/test-prepared-statement.rb +++ b/test/test-prepared-statement.rb @@ -28,7 +28,7 @@ def setup test("#execute_arrow") do @prepared_statement.bind(1, "alice") - assert_equal([Arrow::RecordBatch.new("string" => ["alice"])], + assert_equal([Arrow::RecordBatch.new("name" => ["alice"])], @prepared_statement.execute_arrow.to_a) end end