duckdb 1.4.2.0 → 1.4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/copilot-instructions.md +169 -0
- data/.github/workflows/linter.yml +30 -0
- data/.github/workflows/test_on_macos.yml +7 -2
- data/.github/workflows/test_on_ubuntu.yml +7 -2
- data/.github/workflows/test_on_windows.yml +8 -3
- data/.rubocop.yml +34 -0
- data/CHANGELOG.md +74 -0
- data/Dockerfile +2 -2
- data/Gemfile +12 -0
- data/Gemfile.lock +70 -7
- data/Rakefile +8 -6
- data/bin/console +4 -3
- data/duckdb.gemspec +2 -6
- data/ext/duckdb/bind_info.c +243 -0
- data/ext/duckdb/bind_info.h +13 -0
- data/ext/duckdb/connection.c +60 -2
- data/ext/duckdb/connection.h +1 -0
- data/ext/duckdb/data_chunk.c +137 -0
- data/ext/duckdb/data_chunk.h +13 -0
- data/ext/duckdb/duckdb.c +7 -0
- data/ext/duckdb/function_info.c +65 -0
- data/ext/duckdb/function_info.h +13 -0
- data/ext/duckdb/init_info.c +65 -0
- data/ext/duckdb/init_info.h +13 -0
- data/ext/duckdb/logical_type.c +42 -0
- data/ext/duckdb/memory_helper.c +339 -0
- data/ext/duckdb/memory_helper.h +8 -0
- data/ext/duckdb/result.c +8 -9
- data/ext/duckdb/result.h +1 -0
- data/ext/duckdb/ruby-duckdb.h +7 -0
- data/ext/duckdb/scalar_function.c +336 -1
- data/ext/duckdb/scalar_function.h +2 -0
- data/ext/duckdb/table_function.c +403 -0
- data/ext/duckdb/table_function.h +16 -0
- data/ext/duckdb/vector.c +201 -0
- data/ext/duckdb/vector.h +13 -0
- data/lib/duckdb/appender.rb +21 -11
- data/lib/duckdb/bind_info.rb +32 -0
- data/lib/duckdb/casting.rb +35 -0
- data/lib/duckdb/connection.rb +123 -2
- data/lib/duckdb/converter.rb +32 -47
- data/lib/duckdb/data_chunk.rb +114 -0
- data/lib/duckdb/extracted_statements.rb +1 -1
- data/lib/duckdb/function_info.rb +21 -0
- data/lib/duckdb/init_info.rb +22 -0
- data/lib/duckdb/instance_cache.rb +0 -4
- data/lib/duckdb/interval.rb +1 -1
- data/lib/duckdb/logical_type.rb +46 -5
- data/lib/duckdb/prepared_statement.rb +22 -8
- data/lib/duckdb/result.rb +1 -0
- data/lib/duckdb/scalar_function.rb +119 -0
- data/lib/duckdb/table_function.rb +191 -0
- data/lib/duckdb/vector.rb +20 -0
- data/lib/duckdb/version.rb +1 -1
- data/lib/duckdb.rb +8 -0
- data/sample/async_query.rb +2 -0
- data/sample/async_query_stream.rb +2 -0
- data/sample/issue922.rb +54 -0
- data/sample/issue922_benchmark.rb +169 -0
- data/sample/issue930.rb +49 -0
- data/sample/issue930_benchmark.rb +70 -0
- metadata +30 -57
data/ext/duckdb/logical_type.c
CHANGED
|
@@ -23,6 +23,8 @@ static VALUE duckdb_logical_type_dictionary_size(VALUE self);
|
|
|
23
23
|
static VALUE duckdb_logical_type_dictionary_value_at(VALUE self, VALUE didx);
|
|
24
24
|
static VALUE duckdb_logical_type__get_alias(VALUE self);
|
|
25
25
|
static VALUE duckdb_logical_type__set_alias(VALUE self, VALUE aname);
|
|
26
|
+
static VALUE duckdb_logical_type_s_create_array_type(VALUE klass, VALUE child, VALUE array_size);
|
|
27
|
+
static VALUE duckdb_logical_type_s_create_list_type(VALUE klass, VALUE child);
|
|
26
28
|
static VALUE initialize(VALUE self, VALUE type_id_arg);
|
|
27
29
|
|
|
28
30
|
static const rb_data_type_t logical_type_data_type = {
|
|
@@ -434,6 +436,41 @@ static VALUE duckdb_logical_type__set_alias(VALUE self, VALUE aname) {
|
|
|
434
436
|
return alias;
|
|
435
437
|
}
|
|
436
438
|
|
|
439
|
+
/*
|
|
440
|
+
* call-seq:
|
|
441
|
+
* DuckDB::LogicalType._create_array_type(logical_type, size) -> DuckDB::LogicalType
|
|
442
|
+
*
|
|
443
|
+
* Return an array logical type from the given child logical type and size.
|
|
444
|
+
*/
|
|
445
|
+
static VALUE duckdb_logical_type_s_create_array_type(VALUE klass, VALUE child, VALUE array_size) {
|
|
446
|
+
rubyDuckDBLogicalType *child_ctx = get_struct_logical_type(child);
|
|
447
|
+
idx_t size = NUM2ULL(array_size);
|
|
448
|
+
duckdb_logical_type new_type = duckdb_create_array_type(child_ctx->logical_type, size);
|
|
449
|
+
|
|
450
|
+
if (!new_type) {
|
|
451
|
+
rb_raise(eDuckDBError, "Failed to create array type");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return rbduckdb_create_logical_type(new_type);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/*
|
|
458
|
+
* call-seq:
|
|
459
|
+
* DuckDB::LogicalType._create_list_type(logical_type) -> DuckDB::LogicalType
|
|
460
|
+
*
|
|
461
|
+
* Return a list logical type from the given child logical type.
|
|
462
|
+
*/
|
|
463
|
+
static VALUE duckdb_logical_type_s_create_list_type(VALUE klass, VALUE child) {
|
|
464
|
+
rubyDuckDBLogicalType *child_ctx = get_struct_logical_type(child);
|
|
465
|
+
duckdb_logical_type new_type = duckdb_create_list_type(child_ctx->logical_type);
|
|
466
|
+
|
|
467
|
+
if (!new_type) {
|
|
468
|
+
rb_raise(eDuckDBError, "Failed to create list type");
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return rbduckdb_create_logical_type(new_type);
|
|
472
|
+
}
|
|
473
|
+
|
|
437
474
|
VALUE rbduckdb_create_logical_type(duckdb_logical_type logical_type) {
|
|
438
475
|
VALUE obj;
|
|
439
476
|
rubyDuckDBLogicalType *ctx;
|
|
@@ -472,5 +509,10 @@ void rbduckdb_init_duckdb_logical_type(void) {
|
|
|
472
509
|
rb_define_method(cDuckDBLogicalType, "get_alias", duckdb_logical_type__get_alias, 0);
|
|
473
510
|
rb_define_method(cDuckDBLogicalType, "set_alias", duckdb_logical_type__set_alias, 1);
|
|
474
511
|
|
|
512
|
+
rb_define_private_method(rb_singleton_class(cDuckDBLogicalType), "_create_array_type",
|
|
513
|
+
duckdb_logical_type_s_create_array_type, 2);
|
|
514
|
+
rb_define_private_method(rb_singleton_class(cDuckDBLogicalType), "_create_list_type",
|
|
515
|
+
duckdb_logical_type_s_create_list_type, 1);
|
|
516
|
+
|
|
475
517
|
rb_define_method(cDuckDBLogicalType, "initialize", initialize, 1);
|
|
476
518
|
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/* frozen_string_literal: true */
|
|
2
|
+
|
|
3
|
+
#include "ruby-duckdb.h"
|
|
4
|
+
|
|
5
|
+
static VALUE mDuckDBMemoryHelper;
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* call-seq:
|
|
9
|
+
* DuckDB::MemoryHelper.write_bigint(ptr, index, value) -> nil
|
|
10
|
+
*
|
|
11
|
+
* Writes a 64-bit signed integer (BIGINT) to raw memory.
|
|
12
|
+
*
|
|
13
|
+
* ptr = vector.get_data
|
|
14
|
+
* DuckDB::MemoryHelper.write_bigint(ptr, 0, 42) # Write 42 at index 0
|
|
15
|
+
* DuckDB::MemoryHelper.write_bigint(ptr, 1, 84) # Write 84 at index 1
|
|
16
|
+
*/
|
|
17
|
+
static VALUE rbduckdb_memory_helper_write_bigint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
18
|
+
int64_t *data;
|
|
19
|
+
idx_t idx;
|
|
20
|
+
int64_t val;
|
|
21
|
+
|
|
22
|
+
(void)self;
|
|
23
|
+
|
|
24
|
+
/* Convert Ruby values to C types */
|
|
25
|
+
data = (int64_t *)NUM2ULL(ptr);
|
|
26
|
+
idx = (idx_t)NUM2ULL(index);
|
|
27
|
+
val = (int64_t)NUM2LL(value);
|
|
28
|
+
|
|
29
|
+
/* Write the value */
|
|
30
|
+
data[idx] = val;
|
|
31
|
+
|
|
32
|
+
return Qnil;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
* call-seq:
|
|
37
|
+
* DuckDB::MemoryHelper.write_double(ptr, index, value) -> nil
|
|
38
|
+
*
|
|
39
|
+
* Writes a 64-bit floating point number (DOUBLE) to raw memory.
|
|
40
|
+
*
|
|
41
|
+
* ptr = vector.get_data
|
|
42
|
+
* DuckDB::MemoryHelper.write_double(ptr, 0, 3.14)
|
|
43
|
+
*/
|
|
44
|
+
static VALUE rbduckdb_memory_helper_write_double(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
45
|
+
double *data;
|
|
46
|
+
idx_t idx;
|
|
47
|
+
double val;
|
|
48
|
+
|
|
49
|
+
(void)self;
|
|
50
|
+
|
|
51
|
+
data = (double *)NUM2ULL(ptr);
|
|
52
|
+
idx = (idx_t)NUM2ULL(index);
|
|
53
|
+
val = NUM2DBL(value);
|
|
54
|
+
|
|
55
|
+
data[idx] = val;
|
|
56
|
+
|
|
57
|
+
return Qnil;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* call-seq:
|
|
62
|
+
* DuckDB::MemoryHelper.write_integer(ptr, index, value) -> nil
|
|
63
|
+
*
|
|
64
|
+
* Writes a 32-bit signed integer (INTEGER) to raw memory.
|
|
65
|
+
*
|
|
66
|
+
* ptr = vector.get_data
|
|
67
|
+
* DuckDB::MemoryHelper.write_integer(ptr, 0, 42)
|
|
68
|
+
*/
|
|
69
|
+
static VALUE rbduckdb_memory_helper_write_integer(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
70
|
+
int32_t *data;
|
|
71
|
+
idx_t idx;
|
|
72
|
+
int32_t val;
|
|
73
|
+
|
|
74
|
+
(void)self;
|
|
75
|
+
|
|
76
|
+
data = (int32_t *)NUM2ULL(ptr);
|
|
77
|
+
idx = (idx_t)NUM2ULL(index);
|
|
78
|
+
val = (int32_t)NUM2INT(value);
|
|
79
|
+
|
|
80
|
+
data[idx] = val;
|
|
81
|
+
|
|
82
|
+
return Qnil;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* call-seq:
|
|
87
|
+
* DuckDB::MemoryHelper.write_boolean(ptr, index, value) -> nil
|
|
88
|
+
*
|
|
89
|
+
* Writes a boolean to raw memory.
|
|
90
|
+
*/
|
|
91
|
+
static VALUE rbduckdb_memory_helper_write_boolean(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
92
|
+
bool *data;
|
|
93
|
+
idx_t idx;
|
|
94
|
+
|
|
95
|
+
(void)self;
|
|
96
|
+
|
|
97
|
+
data = (bool *)NUM2ULL(ptr);
|
|
98
|
+
idx = (idx_t)NUM2ULL(index);
|
|
99
|
+
data[idx] = RTEST(value);
|
|
100
|
+
|
|
101
|
+
return Qnil;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
* call-seq:
|
|
106
|
+
* DuckDB::MemoryHelper.write_tinyint(ptr, index, value) -> nil
|
|
107
|
+
*
|
|
108
|
+
* Writes an 8-bit signed integer (TINYINT) to raw memory.
|
|
109
|
+
*/
|
|
110
|
+
static VALUE rbduckdb_memory_helper_write_tinyint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
111
|
+
int8_t *data;
|
|
112
|
+
idx_t idx;
|
|
113
|
+
|
|
114
|
+
(void)self;
|
|
115
|
+
|
|
116
|
+
data = (int8_t *)NUM2ULL(ptr);
|
|
117
|
+
idx = (idx_t)NUM2ULL(index);
|
|
118
|
+
data[idx] = (int8_t)NUM2INT(value);
|
|
119
|
+
|
|
120
|
+
return Qnil;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/*
|
|
124
|
+
* call-seq:
|
|
125
|
+
* DuckDB::MemoryHelper.write_smallint(ptr, index, value) -> nil
|
|
126
|
+
*
|
|
127
|
+
* Writes a 16-bit signed integer (SMALLINT) to raw memory.
|
|
128
|
+
*/
|
|
129
|
+
static VALUE rbduckdb_memory_helper_write_smallint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
130
|
+
int16_t *data;
|
|
131
|
+
idx_t idx;
|
|
132
|
+
|
|
133
|
+
(void)self;
|
|
134
|
+
|
|
135
|
+
data = (int16_t *)NUM2ULL(ptr);
|
|
136
|
+
idx = (idx_t)NUM2ULL(index);
|
|
137
|
+
data[idx] = (int16_t)NUM2INT(value);
|
|
138
|
+
|
|
139
|
+
return Qnil;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/*
|
|
143
|
+
* call-seq:
|
|
144
|
+
* DuckDB::MemoryHelper.write_utinyint(ptr, index, value) -> nil
|
|
145
|
+
*
|
|
146
|
+
* Writes an 8-bit unsigned integer (UTINYINT) to raw memory.
|
|
147
|
+
*/
|
|
148
|
+
static VALUE rbduckdb_memory_helper_write_utinyint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
149
|
+
uint8_t *data;
|
|
150
|
+
idx_t idx;
|
|
151
|
+
|
|
152
|
+
(void)self;
|
|
153
|
+
|
|
154
|
+
data = (uint8_t *)NUM2ULL(ptr);
|
|
155
|
+
idx = (idx_t)NUM2ULL(index);
|
|
156
|
+
data[idx] = (uint8_t)NUM2UINT(value);
|
|
157
|
+
|
|
158
|
+
return Qnil;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/*
|
|
162
|
+
* call-seq:
|
|
163
|
+
* DuckDB::MemoryHelper.write_usmallint(ptr, index, value) -> nil
|
|
164
|
+
*
|
|
165
|
+
* Writes a 16-bit unsigned integer (USMALLINT) to raw memory.
|
|
166
|
+
*/
|
|
167
|
+
static VALUE rbduckdb_memory_helper_write_usmallint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
168
|
+
uint16_t *data;
|
|
169
|
+
idx_t idx;
|
|
170
|
+
|
|
171
|
+
(void)self;
|
|
172
|
+
|
|
173
|
+
data = (uint16_t *)NUM2ULL(ptr);
|
|
174
|
+
idx = (idx_t)NUM2ULL(index);
|
|
175
|
+
data[idx] = (uint16_t)NUM2UINT(value);
|
|
176
|
+
|
|
177
|
+
return Qnil;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/*
|
|
181
|
+
* call-seq:
|
|
182
|
+
* DuckDB::MemoryHelper.write_uinteger(ptr, index, value) -> nil
|
|
183
|
+
*
|
|
184
|
+
* Writes a 32-bit unsigned integer (UINTEGER) to raw memory.
|
|
185
|
+
*/
|
|
186
|
+
static VALUE rbduckdb_memory_helper_write_uinteger(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
187
|
+
uint32_t *data;
|
|
188
|
+
idx_t idx;
|
|
189
|
+
|
|
190
|
+
(void)self;
|
|
191
|
+
|
|
192
|
+
data = (uint32_t *)NUM2ULL(ptr);
|
|
193
|
+
idx = (idx_t)NUM2ULL(index);
|
|
194
|
+
data[idx] = (uint32_t)NUM2ULL(value);
|
|
195
|
+
|
|
196
|
+
return Qnil;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/*
|
|
200
|
+
* call-seq:
|
|
201
|
+
* DuckDB::MemoryHelper.write_ubigint(ptr, index, value) -> nil
|
|
202
|
+
*
|
|
203
|
+
* Writes a 64-bit unsigned integer (UBIGINT) to raw memory.
|
|
204
|
+
*/
|
|
205
|
+
static VALUE rbduckdb_memory_helper_write_ubigint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
206
|
+
uint64_t *data;
|
|
207
|
+
idx_t idx;
|
|
208
|
+
|
|
209
|
+
(void)self;
|
|
210
|
+
|
|
211
|
+
data = (uint64_t *)NUM2ULL(ptr);
|
|
212
|
+
idx = (idx_t)NUM2ULL(index);
|
|
213
|
+
data[idx] = NUM2ULL(value);
|
|
214
|
+
|
|
215
|
+
return Qnil;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/*
|
|
219
|
+
* call-seq:
|
|
220
|
+
* DuckDB::MemoryHelper.write_float(ptr, index, value) -> nil
|
|
221
|
+
*
|
|
222
|
+
* Writes a 32-bit floating point number (FLOAT) to raw memory.
|
|
223
|
+
*/
|
|
224
|
+
static VALUE rbduckdb_memory_helper_write_float(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
225
|
+
float *data;
|
|
226
|
+
idx_t idx;
|
|
227
|
+
|
|
228
|
+
(void)self;
|
|
229
|
+
|
|
230
|
+
data = (float *)NUM2ULL(ptr);
|
|
231
|
+
idx = (idx_t)NUM2ULL(index);
|
|
232
|
+
data[idx] = (float)NUM2DBL(value);
|
|
233
|
+
|
|
234
|
+
return Qnil;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/*
|
|
238
|
+
* call-seq:
|
|
239
|
+
* DuckDB::MemoryHelper.write_timestamp(ptr, index, value) -> nil
|
|
240
|
+
*
|
|
241
|
+
* Writes a DuckDB timestamp to raw memory.
|
|
242
|
+
* +value+ must be a Ruby Time object.
|
|
243
|
+
*
|
|
244
|
+
* ptr = vector.get_data
|
|
245
|
+
* DuckDB::MemoryHelper.write_timestamp(ptr, 0, Time.new(2024, 3, 15, 10, 30, 45))
|
|
246
|
+
*/
|
|
247
|
+
static VALUE rbduckdb_memory_helper_write_timestamp(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
248
|
+
duckdb_timestamp *data;
|
|
249
|
+
idx_t idx;
|
|
250
|
+
|
|
251
|
+
(void)self;
|
|
252
|
+
|
|
253
|
+
if (!rb_obj_is_kind_of(value, rb_cTime)) {
|
|
254
|
+
rb_raise(rb_eTypeError, "Expected Time object for TIMESTAMP");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
data = (duckdb_timestamp *)NUM2ULL(ptr);
|
|
258
|
+
idx = (idx_t)NUM2ULL(index);
|
|
259
|
+
|
|
260
|
+
VALUE local_time = rb_funcall(value, rb_intern("getlocal"), 0);
|
|
261
|
+
data[idx] = rbduckdb_to_duckdb_timestamp_from_value(
|
|
262
|
+
rb_funcall(local_time, rb_intern("year"), 0),
|
|
263
|
+
rb_funcall(local_time, rb_intern("month"), 0),
|
|
264
|
+
rb_funcall(local_time, rb_intern("day"), 0),
|
|
265
|
+
rb_funcall(local_time, rb_intern("hour"), 0),
|
|
266
|
+
rb_funcall(local_time, rb_intern("min"), 0),
|
|
267
|
+
rb_funcall(local_time, rb_intern("sec"), 0),
|
|
268
|
+
rb_funcall(local_time, rb_intern("usec"), 0)
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
return Qnil;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/*
|
|
275
|
+
* call-seq:
|
|
276
|
+
* DuckDB::MemoryHelper.write_timestamp_tz(ptr, index, value) -> nil
|
|
277
|
+
*
|
|
278
|
+
* Writes a DuckDB TIMESTAMP_TZ to raw memory as microseconds since Unix epoch (UTC).
|
|
279
|
+
* +value+ must be a Ruby Time object.
|
|
280
|
+
*
|
|
281
|
+
* ptr = vector.get_data
|
|
282
|
+
* DuckDB::MemoryHelper.write_timestamp_tz(ptr, 0, Time.new(2024, 3, 15, 10, 30, 45, '+00:00'))
|
|
283
|
+
*/
|
|
284
|
+
static VALUE rbduckdb_memory_helper_write_timestamp_tz(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
285
|
+
duckdb_time_tz *data;
|
|
286
|
+
idx_t idx;
|
|
287
|
+
int64_t secs;
|
|
288
|
+
int32_t usecs;
|
|
289
|
+
|
|
290
|
+
(void)self;
|
|
291
|
+
|
|
292
|
+
if (!rb_obj_is_kind_of(value, rb_cTime)) {
|
|
293
|
+
rb_raise(rb_eTypeError, "Expected Time object for TIMESTAMP_TZ");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
data = (duckdb_time_tz *)NUM2ULL(ptr);
|
|
297
|
+
idx = (idx_t)NUM2ULL(index);
|
|
298
|
+
|
|
299
|
+
secs = NUM2LL(rb_funcall(value, rb_intern("to_i"), 0));
|
|
300
|
+
usecs = NUM2INT(rb_funcall(value, rb_intern("usec"), 0));
|
|
301
|
+
data[idx].bits = (uint64_t)(secs * 1000000LL + usecs);
|
|
302
|
+
|
|
303
|
+
return Qnil;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
static VALUE rbduckdb_memory_helper_write_date(VALUE self, VALUE ptr, VALUE index, VALUE value) {
|
|
307
|
+
duckdb_date *data;
|
|
308
|
+
idx_t idx;
|
|
309
|
+
|
|
310
|
+
data = (duckdb_date *)NUM2ULL(ptr);
|
|
311
|
+
idx = (idx_t)NUM2ULL(index);
|
|
312
|
+
|
|
313
|
+
data[idx] = rbduckdb_to_duckdb_date_from_value(
|
|
314
|
+
rb_funcall(value, rb_intern("year"), 0),
|
|
315
|
+
rb_funcall(value, rb_intern("month"), 0),
|
|
316
|
+
rb_funcall(value, rb_intern("day"), 0)
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
return Qnil;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
void rbduckdb_init_memory_helper(void) {
|
|
323
|
+
mDuckDBMemoryHelper = rb_define_module_under(mDuckDB, "MemoryHelper");
|
|
324
|
+
|
|
325
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_bigint", rbduckdb_memory_helper_write_bigint, 3);
|
|
326
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_double", rbduckdb_memory_helper_write_double, 3);
|
|
327
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_integer", rbduckdb_memory_helper_write_integer, 3);
|
|
328
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_boolean", rbduckdb_memory_helper_write_boolean, 3);
|
|
329
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_tinyint", rbduckdb_memory_helper_write_tinyint, 3);
|
|
330
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_smallint", rbduckdb_memory_helper_write_smallint, 3);
|
|
331
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_utinyint", rbduckdb_memory_helper_write_utinyint, 3);
|
|
332
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_usmallint", rbduckdb_memory_helper_write_usmallint, 3);
|
|
333
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_uinteger", rbduckdb_memory_helper_write_uinteger, 3);
|
|
334
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_ubigint", rbduckdb_memory_helper_write_ubigint, 3);
|
|
335
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_float", rbduckdb_memory_helper_write_float, 3);
|
|
336
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_timestamp", rbduckdb_memory_helper_write_timestamp, 3);
|
|
337
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_timestamp_tz", rbduckdb_memory_helper_write_timestamp_tz, 3);
|
|
338
|
+
rb_define_singleton_method(mDuckDBMemoryHelper, "write_date", rbduckdb_memory_helper_write_date, 3);
|
|
339
|
+
}
|
data/ext/duckdb/result.c
CHANGED
|
@@ -57,7 +57,6 @@ static VALUE vector_timestamp_ms(void* vector_data, idx_t row_idx);
|
|
|
57
57
|
static VALUE vector_timestamp_ns(void* vector_data, idx_t row_idx);
|
|
58
58
|
static VALUE vector_enum(duckdb_logical_type ty, void* vector_data, idx_t row_idx);
|
|
59
59
|
static VALUE vector_array(duckdb_logical_type ty, duckdb_vector vector, idx_t row_idx);
|
|
60
|
-
static VALUE vector_value_at(duckdb_vector vector, duckdb_logical_type element_type, idx_t index);
|
|
61
60
|
static VALUE vector_list(duckdb_logical_type ty, duckdb_vector vector, void* vector_data, idx_t row_idx);
|
|
62
61
|
static VALUE vector_map(duckdb_logical_type ty, duckdb_vector vector, void* vector_data, idx_t row_idx);
|
|
63
62
|
static VALUE vector_struct(duckdb_logical_type ty, duckdb_vector vector, idx_t row_idx);
|
|
@@ -528,7 +527,7 @@ static VALUE vector_array(duckdb_logical_type ty, duckdb_vector vector, idx_t ro
|
|
|
528
527
|
|
|
529
528
|
ary = rb_ary_new2(size);
|
|
530
529
|
for (idx_t i = bgn; i < end; ++i) {
|
|
531
|
-
value =
|
|
530
|
+
value = rbduckdb_vector_value_at(child, child_logical_type, i);
|
|
532
531
|
rb_ary_store(ary, i - bgn, value);
|
|
533
532
|
}
|
|
534
533
|
|
|
@@ -536,7 +535,7 @@ static VALUE vector_array(duckdb_logical_type ty, duckdb_vector vector, idx_t ro
|
|
|
536
535
|
return ary;
|
|
537
536
|
}
|
|
538
537
|
|
|
539
|
-
|
|
538
|
+
VALUE rbduckdb_vector_value_at(duckdb_vector vector, duckdb_logical_type element_type, idx_t index) {
|
|
540
539
|
uint64_t *validity;
|
|
541
540
|
duckdb_type type_id;
|
|
542
541
|
void* vector_data;
|
|
@@ -676,7 +675,7 @@ static VALUE vector_list(duckdb_logical_type ty, duckdb_vector vector, void * ve
|
|
|
676
675
|
duckdb_vector child = duckdb_list_vector_get_child(vector);
|
|
677
676
|
|
|
678
677
|
for (i = bgn; i < end; ++i) {
|
|
679
|
-
value =
|
|
678
|
+
value = rbduckdb_vector_value_at(child, child_logical_type, i);
|
|
680
679
|
rb_ary_store(ary, i - bgn, value);
|
|
681
680
|
}
|
|
682
681
|
duckdb_destroy_logical_type(&child_logical_type);
|
|
@@ -701,8 +700,8 @@ static VALUE vector_map(duckdb_logical_type ty, duckdb_vector vector, void* vect
|
|
|
701
700
|
duckdb_vector value_vector = duckdb_struct_vector_get_child(child, 1);
|
|
702
701
|
|
|
703
702
|
for (idx_t i = bgn; i < end; ++i) {
|
|
704
|
-
key =
|
|
705
|
-
value =
|
|
703
|
+
key = rbduckdb_vector_value_at(key_vector, key_logical_type, i);
|
|
704
|
+
value = rbduckdb_vector_value_at(value_vector, value_logical_type, i);
|
|
706
705
|
rb_hash_aset(hash, key, value);
|
|
707
706
|
}
|
|
708
707
|
|
|
@@ -727,7 +726,7 @@ static VALUE vector_struct(duckdb_logical_type ty, duckdb_vector vector, idx_t r
|
|
|
727
726
|
key = ID2SYM(rb_intern_const(p));
|
|
728
727
|
child = duckdb_struct_vector_get_child(vector, i);
|
|
729
728
|
child_type = duckdb_struct_type_child_type(ty, i);
|
|
730
|
-
value =
|
|
729
|
+
value = rbduckdb_vector_value_at(child, child_type, row_idx);
|
|
731
730
|
rb_hash_aset(hash, key, value);
|
|
732
731
|
duckdb_destroy_logical_type(&child_type);
|
|
733
732
|
duckdb_free(p);
|
|
@@ -746,7 +745,7 @@ static VALUE vector_union(duckdb_logical_type ty, duckdb_vector vector, void* ve
|
|
|
746
745
|
duckdb_logical_type child_type = duckdb_union_type_member_type(ty, index);
|
|
747
746
|
|
|
748
747
|
duckdb_vector vector_value = duckdb_struct_vector_get_child(vector, index + 1);
|
|
749
|
-
value =
|
|
748
|
+
value = rbduckdb_vector_value_at(vector_value, child_type, row_idx);
|
|
750
749
|
duckdb_destroy_logical_type(&child_type);
|
|
751
750
|
return value;
|
|
752
751
|
}
|
|
@@ -830,7 +829,7 @@ static VALUE vector_value(duckdb_vector vector, idx_t row_idx) {
|
|
|
830
829
|
|
|
831
830
|
ty = duckdb_vector_get_column_type(vector);
|
|
832
831
|
|
|
833
|
-
obj =
|
|
832
|
+
obj = rbduckdb_vector_value_at(vector, ty, row_idx);
|
|
834
833
|
|
|
835
834
|
duckdb_destroy_logical_type(&ty);
|
|
836
835
|
return obj;
|
data/ext/duckdb/result.h
CHANGED
|
@@ -10,6 +10,7 @@ typedef struct _rubyDuckDBResult rubyDuckDBResult;
|
|
|
10
10
|
rubyDuckDBResult *get_struct_result(VALUE obj);
|
|
11
11
|
void rbduckdb_init_duckdb_result(void);
|
|
12
12
|
VALUE rbduckdb_create_result(void);
|
|
13
|
+
VALUE rbduckdb_vector_value_at(duckdb_vector vector, duckdb_logical_type element_type, idx_t index);
|
|
13
14
|
|
|
14
15
|
#endif
|
|
15
16
|
|
data/ext/duckdb/ruby-duckdb.h
CHANGED
|
@@ -30,6 +30,13 @@
|
|
|
30
30
|
#include "./instance_cache.h"
|
|
31
31
|
#include "./value_impl.h"
|
|
32
32
|
#include "./scalar_function.h"
|
|
33
|
+
#include "./bind_info.h"
|
|
34
|
+
#include "./init_info.h"
|
|
35
|
+
#include "./function_info.h"
|
|
36
|
+
#include "./vector.h"
|
|
37
|
+
#include "./data_chunk.h"
|
|
38
|
+
#include "./memory_helper.h"
|
|
39
|
+
#include "./table_function.h"
|
|
33
40
|
|
|
34
41
|
extern VALUE mDuckDB;
|
|
35
42
|
extern VALUE cDuckDBDatabase;
|