Skip to content

Commit 3b01aee

Browse files
authored
Add support for DuckDB 1.1.0 (#4)
This fixes a number of errors due to changes in DuckDB and ruby-duckdb between 0.5.0 and 1.1.0.
1 parent 13cb5ce commit 3b01aee

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

ext/arrow-duckdb/arrow-duckdb-registration.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,11 @@ namespace {
163163
}
164164

165165
arrow::compute::Expression
166-
convert_filters(std::unordered_map<
167-
idx_t,
168-
std::unique_ptr<duckdb::TableFilter>
169-
> &filters,
166+
convert_filters(duckdb::TableFilterSet *filter_set,
170167
std::unordered_map<idx_t, std::string> &column_names)
171168
{
172169
std::vector<arrow::compute::Expression> expressions;
173-
for (auto it = filters.begin(); it != filters.end(); ++it) {
170+
for (auto it = filter_set->filters.begin(); it != filter_set->filters.end(); ++it) {
174171
expressions.emplace_back(
175172
std::move(convert_filter(it->second.get(), column_names[it->first])));
176173
}
@@ -192,7 +189,7 @@ namespace {
192189
if (have_filter) {
193190
ARROW_RETURN_NOT_OK(
194191
scanner_builder->Filter(
195-
convert_filters(parameters.filters->filters,
192+
convert_filters(parameters.filters,
196193
parameters.projected_columns.projection_map)));
197194
}
198195
if (!parameters.projected_columns.columns.empty()) {
@@ -202,7 +199,7 @@ namespace {
202199
}
203200
ARROW_ASSIGN_OR_RAISE(auto scanner, scanner_builder->Finish());
204201
ARROW_ASSIGN_OR_RAISE(auto reader, scanner->ToRecordBatchReader());
205-
auto stream_wrapper = duckdb::make_unique<duckdb::ArrowArrayStreamWrapper>();
202+
auto stream_wrapper = duckdb::make_uniq<duckdb::ArrowArrayStreamWrapper>();
206203
ARROW_RETURN_NOT_OK(
207204
arrow::ExportRecordBatchReader(reader,
208205
&(stream_wrapper->arrow_array_stream)));
@@ -227,8 +224,13 @@ namespace {
227224
{
228225
auto garrow_table = GARROW_TABLE(reinterpret_cast<gpointer>(data));
229226
auto arrow_table = garrow_table_get_raw(garrow_table);
230-
arrow::ExportSchema(*(arrow_table->schema()),
231-
reinterpret_cast<ArrowSchema *>(&schema));
227+
auto export_schema_status = arrow::ExportSchema(*(arrow_table->schema()),
228+
reinterpret_cast<ArrowSchema *>(&schema));
229+
if (!export_schema_status.ok()) {
230+
throw std::runtime_error(
231+
std::string("[arrow][get_schema] failed to export schema: ") +
232+
export_schema_status.ToString());
233+
}
232234
}
233235
}
234236

ext/arrow-duckdb/arrow-duckdb.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
#include <rbgobject.h>
2222

23+
extern "C" {
2324
#include <ruby-duckdb.h>
25+
}
2426

2527
#include "arrow-duckdb-registration.hpp"
2628

@@ -99,7 +101,7 @@ namespace {
99101
result_ensure_gschema(Result *result)
100102
{
101103
ArrowSchema c_abi_schema;
102-
duckdb_arrow_schema schema = &c_abi_schema;
104+
auto schema = reinterpret_cast<duckdb_arrow_schema>(&c_abi_schema);
103105
auto state = duckdb_query_arrow_schema(result->arrow, &schema);
104106
if (state == DuckDBError) {
105107
free(result->error_message);
@@ -121,7 +123,7 @@ namespace {
121123
result_fetch_internal(VALUE self, Result *result)
122124
{
123125
ArrowArray c_abi_array = {};
124-
duckdb_arrow_array array = &c_abi_array;
126+
auto array = reinterpret_cast<duckdb_arrow_array>(&c_abi_array);
125127
auto state = duckdb_query_arrow_array(result->arrow, &array);
126128
if (state == DuckDBError) {
127129
free(result->error_message);
@@ -219,8 +221,7 @@ namespace {
219221
VALUE
220222
query_sql_arrow(VALUE self, VALUE sql)
221223
{
222-
rubyDuckDBConnection *ctx;
223-
Data_Get_Struct(self, rubyDuckDBConnection, ctx);
224+
auto ctx = get_struct_connection(self);
224225

225226
if (!(ctx->con)) {
226227
rb_raise(eDuckDBError, "Database connection closed");
@@ -253,8 +254,7 @@ namespace {
253254
VALUE
254255
query_unregister_arrow(VALUE self, VALUE name)
255256
{
256-
rubyDuckDBConnection *ctx;
257-
Data_Get_Struct(self, rubyDuckDBConnection, ctx);
257+
auto ctx = get_struct_connection(self);
258258

259259
if (!(ctx->con)) {
260260
rb_raise(eDuckDBError, "Database connection closed");
@@ -293,8 +293,7 @@ namespace {
293293
VALUE
294294
query_register_arrow(VALUE self, VALUE name, VALUE arrow_table)
295295
{
296-
rubyDuckDBConnection *ctx;
297-
Data_Get_Struct(self, rubyDuckDBConnection, ctx);
296+
auto ctx = get_struct_connection(self);
298297

299298
if (!(ctx->con)) {
300299
rb_raise(eDuckDBError, "Database connection closed");
@@ -329,8 +328,7 @@ namespace {
329328
VALUE
330329
prepared_statement_execute_arrow(VALUE self)
331330
{
332-
rubyDuckDBPreparedStatement *ctx;
333-
Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
331+
auto ctx = get_struct_prepared_statement(self);
334332

335333
ID id_new;
336334
CONST_ID(id_new, "new");

test/test-connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setup
3535
result = @connection.query("SELECT * FROM users WHERE name = ?",
3636
'alice',
3737
output: :arrow)
38-
assert_equal([Arrow::RecordBatch.new("string" => ["alice"])],
38+
assert_equal([Arrow::RecordBatch.new("name" => ["alice"])],
3939
result.to_a)
4040
end
4141
end

test/test-prepared-statement.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setup
2828

2929
test("#execute_arrow") do
3030
@prepared_statement.bind(1, "alice")
31-
assert_equal([Arrow::RecordBatch.new("string" => ["alice"])],
31+
assert_equal([Arrow::RecordBatch.new("name" => ["alice"])],
3232
@prepared_statement.execute_arrow.to_a)
3333
end
3434
end

0 commit comments

Comments
 (0)