duckdb 1.5.2.0 → 1.5.3.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/duckdb.gemspec +37 -0
  4. data/ext/duckdb/aggregate_function.c +62 -100
  5. data/ext/duckdb/aggregate_function.h +2 -2
  6. data/ext/duckdb/aggregate_function_set.c +86 -0
  7. data/ext/duckdb/aggregate_function_set.h +14 -0
  8. data/ext/duckdb/appender.c +121 -39
  9. data/ext/duckdb/appender.h +1 -1
  10. data/ext/duckdb/client_context.c +5 -5
  11. data/ext/duckdb/client_context.h +2 -2
  12. data/ext/duckdb/column.c +13 -13
  13. data/ext/duckdb/column.h +1 -1
  14. data/ext/duckdb/connection.c +63 -41
  15. data/ext/duckdb/connection.h +2 -2
  16. data/ext/duckdb/converter.h +1 -7
  17. data/ext/duckdb/conveter.c +6 -6
  18. data/ext/duckdb/data_chunk.c +22 -22
  19. data/ext/duckdb/data_chunk.h +2 -2
  20. data/ext/duckdb/database.c +10 -10
  21. data/ext/duckdb/database.h +1 -1
  22. data/ext/duckdb/duckdb.c +18 -17
  23. data/ext/duckdb/expression.c +8 -8
  24. data/ext/duckdb/expression.h +1 -1
  25. data/ext/duckdb/extconf.rb +32 -16
  26. data/ext/duckdb/extracted_statements.c +15 -15
  27. data/ext/duckdb/extracted_statements.h +1 -1
  28. data/ext/duckdb/instance_cache.c +10 -10
  29. data/ext/duckdb/instance_cache.h +1 -1
  30. data/ext/duckdb/logical_type.c +94 -133
  31. data/ext/duckdb/logical_type.h +2 -2
  32. data/ext/duckdb/memory_helper.c +28 -28
  33. data/ext/duckdb/pending_result.c +27 -27
  34. data/ext/duckdb/pending_result.h +2 -2
  35. data/ext/duckdb/prepared_statement.c +120 -103
  36. data/ext/duckdb/prepared_statement.h +2 -2
  37. data/ext/duckdb/result.c +24 -74
  38. data/ext/duckdb/result.h +2 -3
  39. data/ext/duckdb/ruby-duckdb.h +5 -0
  40. data/ext/duckdb/scalar_function.c +3 -3
  41. data/ext/duckdb/table_description.c +1 -1
  42. data/ext/duckdb/table_function.c +3 -3
  43. data/ext/duckdb/table_function_bind_info.c +1 -1
  44. data/ext/duckdb/value.c +62 -50
  45. data/ext/duckdb/value.h +2 -2
  46. data/ext/duckdb/vector.c +20 -20
  47. data/ext/duckdb/vector.h +2 -2
  48. data/lib/duckdb/aggregate_function.rb +208 -3
  49. data/lib/duckdb/aggregate_function_set.rb +29 -0
  50. data/lib/duckdb/appender.rb +148 -0
  51. data/lib/duckdb/connection.rb +86 -25
  52. data/lib/duckdb/converter.rb +5 -0
  53. data/lib/duckdb/logical_type.rb +1 -3
  54. data/lib/duckdb/prepared_statement.rb +19 -1
  55. data/lib/duckdb/result.rb +39 -2
  56. data/lib/duckdb/scalar_function.rb +9 -4
  57. data/lib/duckdb/scalar_function_set.rb +0 -1
  58. data/lib/duckdb/table_description.rb +7 -0
  59. data/lib/duckdb/table_function.rb +0 -1
  60. data/lib/duckdb/table_name_parser.rb +58 -0
  61. data/lib/duckdb/value.rb +19 -0
  62. data/lib/duckdb/version.rb +1 -1
  63. data/lib/duckdb.rb +2 -0
  64. metadata +7 -3
  65. data/lib/duckdb/duckdb_native.so +0 -0
data/ext/duckdb/result.c CHANGED
@@ -10,19 +10,16 @@ static VALUE cDuckDBResult;
10
10
  static void deallocate(void *ctx);
11
11
  static VALUE allocate(VALUE klass);
12
12
  static size_t memsize(const void *p);
13
- static VALUE duckdb_result_column_count(VALUE oDuckDBResult);
14
- static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult);
15
- static VALUE duckdb_result_columns(VALUE oDuckDBResult);
13
+ static VALUE result_column_count(VALUE oDuckDBResult);
14
+ static VALUE result_rows_changed(VALUE oDuckDBResult);
15
+ static VALUE result_columns(VALUE oDuckDBResult);
16
16
  static VALUE destroy_data_chunk(VALUE arg);
17
17
 
18
- static VALUE duckdb_result__chunk_stream(VALUE oDuckDBResult);
18
+ static VALUE result__chunk_stream(VALUE oDuckDBResult);
19
19
  static VALUE yield_rows(VALUE arg);
20
- static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx);
21
- static VALUE duckdb_result__return_type(VALUE oDuckDBResult);
22
- static VALUE duckdb_result__statement_type(VALUE oDuckDBResult);
23
- static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx);
24
- static VALUE duckdb_result__enum_dictionary_size(VALUE oDuckDBResult, VALUE col_idx);
25
- static VALUE duckdb_result__enum_dictionary_value(VALUE oDuckDBResult, VALUE col_idx, VALUE idx);
20
+ static VALUE result__return_type(VALUE oDuckDBResult);
21
+ static VALUE result__statement_type(VALUE oDuckDBResult);
22
+ static VALUE result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx);
26
23
 
27
24
  static VALUE vector_date(void *vector_data, idx_t row_idx);
28
25
  static VALUE vector_timestamp(void* vector_data, idx_t row_idx);
@@ -72,7 +69,7 @@ static size_t memsize(const void *p) {
72
69
  return sizeof(rubyDuckDBResult);
73
70
  }
74
71
 
75
- rubyDuckDBResult *get_struct_result(VALUE obj) {
72
+ rubyDuckDBResult *rbduckdb_get_struct_result(VALUE obj) {
76
73
  rubyDuckDBResult *ctx;
77
74
  TypedData_Get_Struct(obj, rubyDuckDBResult, &result_data_type, ctx);
78
75
  return ctx;
@@ -100,7 +97,7 @@ rubyDuckDBResult *get_struct_result(VALUE obj) {
100
97
  * end
101
98
  *
102
99
  */
103
- static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult) {
100
+ static VALUE result_rows_changed(VALUE oDuckDBResult) {
104
101
  rubyDuckDBResult *ctx;
105
102
  TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
106
103
  return LL2NUM(duckdb_rows_changed(&(ctx->result)));
@@ -124,7 +121,7 @@ static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult) {
124
121
  * end
125
122
  *
126
123
  */
127
- static VALUE duckdb_result_column_count(VALUE oDuckDBResult) {
124
+ static VALUE result_column_count(VALUE oDuckDBResult) {
128
125
  rubyDuckDBResult *ctx;
129
126
  TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
130
127
  return LL2NUM(duckdb_column_count(&(ctx->result)));
@@ -137,7 +134,7 @@ static VALUE duckdb_result_column_count(VALUE oDuckDBResult) {
137
134
  * Returns the column class Lists.
138
135
  *
139
136
  */
140
- static VALUE duckdb_result_columns(VALUE oDuckDBResult) {
137
+ static VALUE result_columns(VALUE oDuckDBResult) {
141
138
  rubyDuckDBResult *ctx;
142
139
  TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
143
140
 
@@ -159,7 +156,7 @@ static VALUE destroy_data_chunk(VALUE arg) {
159
156
  }
160
157
 
161
158
  /* :nodoc: */
162
- static VALUE duckdb_result__chunk_stream(VALUE oDuckDBResult) {
159
+ static VALUE result__chunk_stream(VALUE oDuckDBResult) {
163
160
  rubyDuckDBResult *ctx;
164
161
  struct chunk_arg arg;
165
162
 
@@ -199,28 +196,21 @@ static VALUE yield_rows(VALUE arg) {
199
196
  }
200
197
 
201
198
  /* :nodoc: */
202
- static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx) {
203
- rubyDuckDBResult *ctx;
204
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
205
- return LL2NUM(duckdb_column_type(&(ctx->result), NUM2LL(col_idx)));
206
- }
207
-
208
- /* :nodoc: */
209
- static VALUE duckdb_result__return_type(VALUE oDuckDBResult) {
199
+ static VALUE result__return_type(VALUE oDuckDBResult) {
210
200
  rubyDuckDBResult *ctx;
211
201
  TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
212
202
  return INT2FIX(duckdb_result_return_type(ctx->result));
213
203
  }
214
204
 
215
205
  /* :nodoc: */
216
- static VALUE duckdb_result__statement_type(VALUE oDuckDBResult) {
206
+ static VALUE result__statement_type(VALUE oDuckDBResult) {
217
207
  rubyDuckDBResult *ctx;
218
208
  TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
219
209
  return INT2FIX(duckdb_result_statement_type(ctx->result));
220
210
  }
221
211
 
222
212
  /* :nodoc: */
223
- static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx) {
213
+ static VALUE result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx) {
224
214
  rubyDuckDBResult *ctx;
225
215
  VALUE type = Qnil;
226
216
  duckdb_logical_type logical_type;
@@ -234,46 +224,10 @@ static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_id
234
224
  return type;
235
225
  }
236
226
 
237
- /* :nodoc: */
238
- static VALUE duckdb_result__enum_dictionary_size(VALUE oDuckDBResult, VALUE col_idx) {
239
- rubyDuckDBResult *ctx;
240
- VALUE size = Qnil;
241
- duckdb_logical_type logical_type;
242
-
243
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
244
- logical_type = duckdb_column_logical_type(&(ctx->result), NUM2LL(col_idx));
245
- if (logical_type) {
246
- size = UINT2NUM(duckdb_enum_dictionary_size(logical_type));
247
- }
248
- duckdb_destroy_logical_type(&logical_type);
249
- return size;
250
- }
251
-
252
- /* :nodoc: */
253
- static VALUE duckdb_result__enum_dictionary_value(VALUE oDuckDBResult, VALUE col_idx, VALUE idx) {
254
- rubyDuckDBResult *ctx;
255
- VALUE value = Qnil;
256
- duckdb_logical_type logical_type;
257
- char *p;
258
-
259
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
260
- logical_type = duckdb_column_logical_type(&(ctx->result), NUM2LL(col_idx));
261
- if (logical_type) {
262
- p = duckdb_enum_dictionary_value(logical_type, NUM2LL(idx));
263
- if (p) {
264
- value = rb_utf8_str_new_cstr(p);
265
- duckdb_free(p);
266
- }
267
- }
268
- duckdb_destroy_logical_type(&logical_type);
269
- return value;
270
- }
271
-
272
227
  VALUE rbduckdb_create_result(void) {
273
228
  return allocate(cDuckDBResult);
274
229
  }
275
230
 
276
-
277
231
  static VALUE vector_date(void *vector_data, idx_t row_idx) {
278
232
  return rbduckdb_date_to_ruby(((duckdb_date *)vector_data)[row_idx]);
279
233
  }
@@ -286,7 +240,6 @@ static VALUE vector_time(void* vector_data, idx_t row_idx) {
286
240
  return rbduckdb_time_to_ruby(((duckdb_time *)vector_data)[row_idx]);
287
241
  }
288
242
 
289
-
290
243
  static VALUE vector_interval(void* vector_data, idx_t row_idx) {
291
244
  return rbduckdb_interval_to_ruby(((duckdb_interval *)vector_data)[row_idx]);
292
245
  }
@@ -706,7 +659,7 @@ static VALUE vector_value(duckdb_vector vector, idx_t row_idx) {
706
659
  return obj;
707
660
  }
708
661
 
709
- void rbduckdb_init_duckdb_result(void) {
662
+ void rbduckdb_init_result(void) {
710
663
  #if 0
711
664
  VALUE mDuckDB = rb_define_module("DuckDB");
712
665
  #endif
@@ -714,15 +667,12 @@ void rbduckdb_init_duckdb_result(void) {
714
667
 
715
668
  rb_define_alloc_func(cDuckDBResult, allocate);
716
669
 
717
- rb_define_method(cDuckDBResult, "column_count", duckdb_result_column_count, 0);
718
- rb_define_method(cDuckDBResult, "rows_changed", duckdb_result_rows_changed, 0);
719
- rb_define_method(cDuckDBResult, "columns", duckdb_result_columns, 0);
720
- rb_define_private_method(cDuckDBResult, "_chunk_stream", duckdb_result__chunk_stream, 0);
721
- rb_define_private_method(cDuckDBResult, "_column_type", duckdb_result__column_type, 1);
722
- rb_define_private_method(cDuckDBResult, "_return_type", duckdb_result__return_type, 0);
723
- rb_define_private_method(cDuckDBResult, "_statement_type", duckdb_result__statement_type, 0);
724
-
725
- rb_define_private_method(cDuckDBResult, "_enum_internal_type", duckdb_result__enum_internal_type, 1);
726
- rb_define_private_method(cDuckDBResult, "_enum_dictionary_size", duckdb_result__enum_dictionary_size, 1);
727
- rb_define_private_method(cDuckDBResult, "_enum_dictionary_value", duckdb_result__enum_dictionary_value, 2);
670
+ rb_define_method(cDuckDBResult, "column_count", result_column_count, 0);
671
+ rb_define_method(cDuckDBResult, "rows_changed", result_rows_changed, 0);
672
+ rb_define_method(cDuckDBResult, "columns", result_columns, 0);
673
+ rb_define_private_method(cDuckDBResult, "_chunk_stream", result__chunk_stream, 0);
674
+ rb_define_private_method(cDuckDBResult, "_return_type", result__return_type, 0);
675
+ rb_define_private_method(cDuckDBResult, "_statement_type", result__statement_type, 0);
676
+
677
+ rb_define_private_method(cDuckDBResult, "_enum_internal_type", result__enum_internal_type, 1);
728
678
  }
data/ext/duckdb/result.h CHANGED
@@ -7,10 +7,9 @@ struct _rubyDuckDBResult {
7
7
 
8
8
  typedef struct _rubyDuckDBResult rubyDuckDBResult;
9
9
 
10
- rubyDuckDBResult *get_struct_result(VALUE obj);
11
- void rbduckdb_init_duckdb_result(void);
10
+ rubyDuckDBResult *rbduckdb_get_struct_result(VALUE obj);
11
+ void rbduckdb_init_result(void);
12
12
  VALUE rbduckdb_create_result(void);
13
13
  VALUE rbduckdb_vector_value_at(duckdb_vector vector, duckdb_logical_type element_type, idx_t index);
14
14
 
15
15
  #endif
16
-
@@ -12,6 +12,10 @@
12
12
  #define HAVE_DUCKDB_H_GE_V1_5_0 1
13
13
  #endif
14
14
 
15
+ #ifdef HAVE_DUCKDB_GEOMETRY_TYPE_GET_CRS
16
+ #define HAVE_DUCKDB_H_GE_V1_5_2 1
17
+ #endif
18
+
15
19
  #include "./error.h"
16
20
  #include "./database.h"
17
21
  #include "./connection.h"
@@ -34,6 +38,7 @@
34
38
  #include "./scalar_function.h"
35
39
  #include "./scalar_function_set.h"
36
40
  #include "./aggregate_function.h"
41
+ #include "./aggregate_function_set.h"
37
42
  #include "./expression.h"
38
43
  #include "./client_context.h"
39
44
  #include "./scalar_function_bind_info.h"
@@ -139,7 +139,7 @@ static VALUE rbduckdb_scalar_function__set_return_type(VALUE self, VALUE logical
139
139
  rubyDuckDBLogicalType *lt;
140
140
 
141
141
  TypedData_Get_Struct(self, rubyDuckDBScalarFunction, &scalar_function_data_type, p);
142
- lt = get_struct_logical_type(logical_type);
142
+ lt = rbduckdb_get_struct_logical_type(logical_type);
143
143
 
144
144
  duckdb_scalar_function_set_return_type(p->scalar_function, lt->logical_type);
145
145
 
@@ -151,7 +151,7 @@ static VALUE rbduckdb_scalar_function__set_varargs(VALUE self, VALUE logical_typ
151
151
  rubyDuckDBLogicalType *lt;
152
152
 
153
153
  TypedData_Get_Struct(self, rubyDuckDBScalarFunction, &scalar_function_data_type, p);
154
- lt = get_struct_logical_type(logical_type);
154
+ lt = rbduckdb_get_struct_logical_type(logical_type);
155
155
 
156
156
  duckdb_scalar_function_set_varargs(p->scalar_function, lt->logical_type);
157
157
 
@@ -172,7 +172,7 @@ static VALUE rbduckdb_scalar_function_add_parameter(VALUE self, VALUE logical_ty
172
172
  rubyDuckDBLogicalType *lt;
173
173
 
174
174
  TypedData_Get_Struct(self, rubyDuckDBScalarFunction, &scalar_function_data_type, p);
175
- lt = get_struct_logical_type(logical_type);
175
+ lt = rbduckdb_get_struct_logical_type(logical_type);
176
176
 
177
177
  duckdb_scalar_function_add_parameter(p->scalar_function, lt->logical_type);
178
178
 
@@ -70,7 +70,7 @@ static VALUE duckdb_table_description__initialize(VALUE self, VALUE con, VALUE c
70
70
  if (!NIL_P(table)) {
71
71
  ptable = StringValuePtr(table);
72
72
  }
73
- ctxcon = get_struct_connection(con);
73
+ ctxcon = rbduckdb_get_struct_connection(con);
74
74
  ctx = get_struct_table_description(self);
75
75
 
76
76
  if (ctx->table_description) {
@@ -148,7 +148,7 @@ static VALUE rbduckdb_table_function_add_parameter(VALUE self, VALUE logical_typ
148
148
  rb_raise(eDuckDBError, "Table function is destroyed");
149
149
  }
150
150
 
151
- ctx_logical_type = get_struct_logical_type(logical_type);
151
+ ctx_logical_type = rbduckdb_get_struct_logical_type(logical_type);
152
152
  duckdb_table_function_add_parameter(ctx->table_function, ctx_logical_type->logical_type);
153
153
 
154
154
  return self;
@@ -174,7 +174,7 @@ static VALUE rbduckdb_table_function_add_named_parameter(VALUE self, VALUE name,
174
174
  }
175
175
 
176
176
  param_name = StringValueCStr(name);
177
- ctx_logical_type = get_struct_logical_type(logical_type);
177
+ ctx_logical_type = rbduckdb_get_struct_logical_type(logical_type);
178
178
  duckdb_table_function_add_named_parameter(ctx->table_function, param_name, ctx_logical_type->logical_type);
179
179
 
180
180
  return self;
@@ -388,7 +388,7 @@ static void execute_execute_callback_protected(void *user_data) {
388
388
  func_info_ctx->info = darg->info;
389
389
 
390
390
  data_chunk_obj = rb_class_new_instance(0, NULL, cDuckDBDataChunk);
391
- data_chunk_ctx = get_struct_data_chunk(data_chunk_obj);
391
+ data_chunk_ctx = rbduckdb_get_struct_data_chunk(data_chunk_obj);
392
392
  data_chunk_ctx->data_chunk = darg->output;
393
393
 
394
394
  VALUE call_args[3] = { darg->ctx->execute_proc, func_info_obj, data_chunk_obj };
@@ -135,7 +135,7 @@ static VALUE rbduckdb_bind_info__add_result_column(VALUE self, VALUE column_name
135
135
  const char *col_name;
136
136
 
137
137
  TypedData_Get_Struct(self, rubyDuckDBBindInfo, &bind_info_data_type, ctx);
138
- ctx_logical_type = get_struct_logical_type(logical_type);
138
+ ctx_logical_type = rbduckdb_get_struct_logical_type(logical_type);
139
139
 
140
140
  col_name = StringValueCStr(column_name);
141
141
  duckdb_bind_add_result_column(ctx->bind_info, col_name, ctx_logical_type->logical_type);
data/ext/duckdb/value.c CHANGED
@@ -5,22 +5,23 @@ VALUE cDuckDBValue;
5
5
  static void deallocate(void *);
6
6
  static VALUE allocate(VALUE klass);
7
7
  static size_t memsize(const void *p);
8
- static VALUE duckdb_value_s__create_bool(VALUE klass, VALUE flag);
9
- static VALUE duckdb_value_s__create_int8(VALUE klass, VALUE val);
10
- static VALUE duckdb_value_s__create_int16(VALUE klass, VALUE val);
11
- static VALUE duckdb_value_s__create_int32(VALUE klass, VALUE val);
12
- static VALUE duckdb_value_s__create_int64(VALUE klass, VALUE val);
13
- static VALUE duckdb_value_s__create_uint8(VALUE klass, VALUE val);
14
- static VALUE duckdb_value_s__create_uint16(VALUE klass, VALUE val);
15
- static VALUE duckdb_value_s__create_uint32(VALUE klass, VALUE val);
16
- static VALUE duckdb_value_s__create_uint64(VALUE klass, VALUE val);
17
- static VALUE duckdb_value_s__create_float(VALUE klass, VALUE val);
18
- static VALUE duckdb_value_s__create_double(VALUE klass, VALUE val);
19
- static VALUE duckdb_value_s__create_varchar(VALUE klass, VALUE str);
20
- static VALUE duckdb_value_s__create_blob(VALUE klass, VALUE str);
21
- static VALUE duckdb_value_s__create_hugeint(VALUE klass, VALUE lower, VALUE upper);
22
- static VALUE duckdb_value_s__create_uhugeint(VALUE klass, VALUE lower, VALUE upper);
23
- static VALUE duckdb_value_s_create_null(VALUE klass);
8
+ static VALUE value_s__create_bool(VALUE klass, VALUE flag);
9
+ static VALUE value_s__create_int8(VALUE klass, VALUE val);
10
+ static VALUE value_s__create_int16(VALUE klass, VALUE val);
11
+ static VALUE value_s__create_int32(VALUE klass, VALUE val);
12
+ static VALUE value_s__create_int64(VALUE klass, VALUE val);
13
+ static VALUE value_s__create_uint8(VALUE klass, VALUE val);
14
+ static VALUE value_s__create_uint16(VALUE klass, VALUE val);
15
+ static VALUE value_s__create_uint32(VALUE klass, VALUE val);
16
+ static VALUE value_s__create_uint64(VALUE klass, VALUE val);
17
+ static VALUE value_s__create_float(VALUE klass, VALUE val);
18
+ static VALUE value_s__create_double(VALUE klass, VALUE val);
19
+ static VALUE value_s__create_varchar(VALUE klass, VALUE str);
20
+ static VALUE value_s__create_blob(VALUE klass, VALUE str);
21
+ static VALUE value_s__create_hugeint(VALUE klass, VALUE lower, VALUE upper);
22
+ static VALUE value_s__create_uhugeint(VALUE klass, VALUE lower, VALUE upper);
23
+ static VALUE value_s__create_decimal(VALUE klass, VALUE lower, VALUE upper, VALUE width, VALUE scale);
24
+ static VALUE value_s_create_null(VALUE klass);
24
25
 
25
26
  static const rb_data_type_t value_data_type = {
26
27
  "DuckDB/Value",
@@ -44,76 +45,76 @@ static size_t memsize(const void *p) {
44
45
  return sizeof(rubyDuckDBValue);
45
46
  }
46
47
 
47
- static VALUE duckdb_value_s__create_bool(VALUE klass, VALUE flag) {
48
+ static VALUE value_s__create_bool(VALUE klass, VALUE flag) {
48
49
  duckdb_value value = duckdb_create_bool(RTEST(flag) ? true : false);
49
50
  return rbduckdb_value_new(value);
50
51
  }
51
52
 
52
- static VALUE duckdb_value_s__create_int8(VALUE klass, VALUE val) {
53
+ static VALUE value_s__create_int8(VALUE klass, VALUE val) {
53
54
  duckdb_value value = duckdb_create_int8((int8_t)NUM2INT(val));
54
55
  return rbduckdb_value_new(value);
55
56
  }
56
57
 
57
- static VALUE duckdb_value_s__create_int16(VALUE klass, VALUE val) {
58
+ static VALUE value_s__create_int16(VALUE klass, VALUE val) {
58
59
  duckdb_value value = duckdb_create_int16((int16_t)NUM2INT(val));
59
60
  return rbduckdb_value_new(value);
60
61
  }
61
62
 
62
- static VALUE duckdb_value_s__create_int32(VALUE klass, VALUE val) {
63
+ static VALUE value_s__create_int32(VALUE klass, VALUE val) {
63
64
  duckdb_value value = duckdb_create_int32(NUM2INT(val));
64
65
  return rbduckdb_value_new(value);
65
66
  }
66
67
 
67
- static VALUE duckdb_value_s__create_int64(VALUE klass, VALUE val) {
68
+ static VALUE value_s__create_int64(VALUE klass, VALUE val) {
68
69
  duckdb_value value = duckdb_create_int64((int64_t)NUM2LL(val));
69
70
  return rbduckdb_value_new(value);
70
71
  }
71
72
 
72
- static VALUE duckdb_value_s__create_uint8(VALUE klass, VALUE val) {
73
+ static VALUE value_s__create_uint8(VALUE klass, VALUE val) {
73
74
  duckdb_value value = duckdb_create_uint8((uint8_t)NUM2UINT(val));
74
75
  return rbduckdb_value_new(value);
75
76
  }
76
77
 
77
- static VALUE duckdb_value_s__create_uint16(VALUE klass, VALUE val) {
78
+ static VALUE value_s__create_uint16(VALUE klass, VALUE val) {
78
79
  duckdb_value value = duckdb_create_uint16((uint16_t)NUM2UINT(val));
79
80
  return rbduckdb_value_new(value);
80
81
  }
81
82
 
82
- static VALUE duckdb_value_s__create_uint32(VALUE klass, VALUE val) {
83
+ static VALUE value_s__create_uint32(VALUE klass, VALUE val) {
83
84
  duckdb_value value = duckdb_create_uint32((uint32_t)NUM2UINT(val));
84
85
  return rbduckdb_value_new(value);
85
86
  }
86
87
 
87
- static VALUE duckdb_value_s__create_uint64(VALUE klass, VALUE val) {
88
+ static VALUE value_s__create_uint64(VALUE klass, VALUE val) {
88
89
  duckdb_value value = duckdb_create_uint64((uint64_t)RB_NUM2ULL(val));
89
90
  return rbduckdb_value_new(value);
90
91
  }
91
92
 
92
- static VALUE duckdb_value_s__create_float(VALUE klass, VALUE val) {
93
+ static VALUE value_s__create_float(VALUE klass, VALUE val) {
93
94
  duckdb_value value = duckdb_create_float((float)NUM2DBL(val));
94
95
  return rbduckdb_value_new(value);
95
96
  }
96
97
 
97
- static VALUE duckdb_value_s__create_double(VALUE klass, VALUE val) {
98
+ static VALUE value_s__create_double(VALUE klass, VALUE val) {
98
99
  duckdb_value value = duckdb_create_double(NUM2DBL(val));
99
100
  return rbduckdb_value_new(value);
100
101
  }
101
102
 
102
- static VALUE duckdb_value_s__create_varchar(VALUE klass, VALUE str) {
103
+ static VALUE value_s__create_varchar(VALUE klass, VALUE str) {
103
104
  const char *str_ptr = StringValuePtr(str);
104
105
  idx_t str_len = RSTRING_LEN(str);
105
106
  duckdb_value value = duckdb_create_varchar_length(str_ptr, str_len);
106
107
  return rbduckdb_value_new(value);
107
108
  }
108
109
 
109
- static VALUE duckdb_value_s__create_blob(VALUE klass, VALUE str) {
110
+ static VALUE value_s__create_blob(VALUE klass, VALUE str) {
110
111
  const uint8_t *data_ptr = (const uint8_t *)StringValuePtr(str);
111
112
  idx_t data_len = RSTRING_LEN(str);
112
113
  duckdb_value value = duckdb_create_blob(data_ptr, data_len);
113
114
  return rbduckdb_value_new(value);
114
115
  }
115
116
 
116
- static VALUE duckdb_value_s__create_hugeint(VALUE klass, VALUE lower, VALUE upper) {
117
+ static VALUE value_s__create_hugeint(VALUE klass, VALUE lower, VALUE upper) {
117
118
  duckdb_hugeint hugeint;
118
119
  hugeint.lower = NUM2ULL(lower);
119
120
  hugeint.upper = NUM2LL(upper);
@@ -121,7 +122,7 @@ static VALUE duckdb_value_s__create_hugeint(VALUE klass, VALUE lower, VALUE uppe
121
122
  return rbduckdb_value_new(value);
122
123
  }
123
124
 
124
- static VALUE duckdb_value_s__create_uhugeint(VALUE klass, VALUE lower, VALUE upper) {
125
+ static VALUE value_s__create_uhugeint(VALUE klass, VALUE lower, VALUE upper) {
125
126
  duckdb_uhugeint uhugeint;
126
127
  uhugeint.lower = NUM2ULL(lower);
127
128
  uhugeint.upper = NUM2ULL(upper);
@@ -129,6 +130,16 @@ static VALUE duckdb_value_s__create_uhugeint(VALUE klass, VALUE lower, VALUE upp
129
130
  return rbduckdb_value_new(value);
130
131
  }
131
132
 
133
+ static VALUE value_s__create_decimal(VALUE klass, VALUE lower, VALUE upper, VALUE width, VALUE scale) {
134
+ duckdb_decimal decimal;
135
+ decimal.value.lower = NUM2ULL(lower);
136
+ decimal.value.upper = NUM2LL(upper);
137
+ decimal.width = (uint8_t)NUM2UINT(width);
138
+ decimal.scale = (uint8_t)NUM2UINT(scale);
139
+ duckdb_value value = duckdb_create_decimal(decimal);
140
+ return rbduckdb_value_new(value);
141
+ }
142
+
132
143
  /*
133
144
  * call-seq:
134
145
  * DuckDB::Value.create_null -> DuckDB::Value
@@ -138,7 +149,7 @@ static VALUE duckdb_value_s__create_uhugeint(VALUE klass, VALUE lower, VALUE upp
138
149
  * require 'duckdb'
139
150
  * value = DuckDB::Value.create_null
140
151
  */
141
- static VALUE duckdb_value_s_create_null(VALUE klass) {
152
+ static VALUE value_s_create_null(VALUE klass) {
142
153
  duckdb_value value = duckdb_create_null_value();
143
154
  return rbduckdb_value_new(value);
144
155
  }
@@ -151,7 +162,7 @@ VALUE rbduckdb_value_new(duckdb_value value) {
151
162
  return obj;
152
163
  }
153
164
 
154
- rubyDuckDBValue *get_struct_value(VALUE obj) {
165
+ rubyDuckDBValue *rbduckdb_get_struct_value(VALUE obj) {
155
166
  rubyDuckDBValue *ctx;
156
167
  TypedData_Get_Struct(obj, rubyDuckDBValue, &value_data_type, ctx);
157
168
  return ctx;
@@ -252,28 +263,29 @@ VALUE rbduckdb_duckdb_value_to_ruby(duckdb_value val) {
252
263
  return result;
253
264
  }
254
265
 
255
- void rbduckdb_init_duckdb_value(void) {
266
+ void rbduckdb_init_value(void) {
256
267
  #if 0
257
268
  VALUE mDuckDB = rb_define_module("DuckDB");
258
269
  #endif
259
270
  cDuckDBValue = rb_define_class_under(mDuckDB, "Value", rb_cObject);
260
271
  rb_define_alloc_func(cDuckDBValue, allocate);
261
272
 
262
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_bool", duckdb_value_s__create_bool, 1);
263
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int8", duckdb_value_s__create_int8, 1);
264
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int16", duckdb_value_s__create_int16, 1);
265
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int32", duckdb_value_s__create_int32, 1);
266
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int64", duckdb_value_s__create_int64, 1);
267
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint8", duckdb_value_s__create_uint8, 1);
268
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint16", duckdb_value_s__create_uint16, 1);
269
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint32", duckdb_value_s__create_uint32, 1);
270
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint64", duckdb_value_s__create_uint64, 1);
271
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_float", duckdb_value_s__create_float, 1);
272
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_double", duckdb_value_s__create_double, 1);
273
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_varchar", duckdb_value_s__create_varchar, 1);
274
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_blob", duckdb_value_s__create_blob, 1);
275
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_hugeint", duckdb_value_s__create_hugeint, 2);
276
- rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uhugeint", duckdb_value_s__create_uhugeint, 2);
277
- rb_define_singleton_method(cDuckDBValue, "create_null", duckdb_value_s_create_null, 0);
273
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_bool", value_s__create_bool, 1);
274
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int8", value_s__create_int8, 1);
275
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int16", value_s__create_int16, 1);
276
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int32", value_s__create_int32, 1);
277
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_int64", value_s__create_int64, 1);
278
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint8", value_s__create_uint8, 1);
279
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint16", value_s__create_uint16, 1);
280
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint32", value_s__create_uint32, 1);
281
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uint64", value_s__create_uint64, 1);
282
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_float", value_s__create_float, 1);
283
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_double", value_s__create_double, 1);
284
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_varchar", value_s__create_varchar, 1);
285
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_blob", value_s__create_blob, 1);
286
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_hugeint", value_s__create_hugeint, 2);
287
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_uhugeint", value_s__create_uhugeint, 2);
288
+ rb_define_private_method(rb_singleton_class(cDuckDBValue), "_create_decimal", value_s__create_decimal, 4);
289
+ rb_define_singleton_method(cDuckDBValue, "create_null", value_s_create_null, 0);
278
290
  }
279
291
 
data/ext/duckdb/value.h CHANGED
@@ -7,9 +7,9 @@ struct _rubyDuckDBValue {
7
7
 
8
8
  typedef struct _rubyDuckDBValue rubyDuckDBValue;
9
9
 
10
- void rbduckdb_init_duckdb_value(void);
10
+ void rbduckdb_init_value(void);
11
11
  VALUE rbduckdb_value_new(duckdb_value value);
12
12
  VALUE rbduckdb_duckdb_value_to_ruby(duckdb_value val);
13
- rubyDuckDBValue *get_struct_value(VALUE obj);
13
+ rubyDuckDBValue *rbduckdb_get_struct_value(VALUE obj);
14
14
 
15
15
  #endif
data/ext/duckdb/vector.c CHANGED
@@ -5,12 +5,12 @@ VALUE cDuckDBVector;
5
5
  static void deallocate(void *ctx);
6
6
  static VALUE allocate(VALUE klass);
7
7
  static size_t memsize(const void *p);
8
- static VALUE rbduckdb_vector_get_data(VALUE self);
9
- static VALUE rbduckdb_vector_get_validity(VALUE self);
10
- static VALUE rbduckdb_vector_assign_string_element(VALUE self, VALUE index, VALUE str);
11
- static VALUE rbduckdb_vector_assign_string_element_len(VALUE self, VALUE index, VALUE str);
12
- static VALUE rbduckdb_vector_logical_type(VALUE self);
13
- static VALUE rbduckdb_vector_set_validity(VALUE self, VALUE index, VALUE valid);
8
+ static VALUE vector_get_data(VALUE self);
9
+ static VALUE vector_get_validity(VALUE self);
10
+ static VALUE vector_assign_string_element(VALUE self, VALUE index, VALUE str);
11
+ static VALUE vector_assign_string_element_len(VALUE self, VALUE index, VALUE str);
12
+ static VALUE vector_logical_type(VALUE self);
13
+ static VALUE vector_set_validity(VALUE self, VALUE index, VALUE valid);
14
14
 
15
15
  static const rb_data_type_t vector_data_type = {
16
16
  "DuckDB/Vector",
@@ -32,7 +32,7 @@ static size_t memsize(const void *p) {
32
32
  return sizeof(rubyDuckDBVector);
33
33
  }
34
34
 
35
- rubyDuckDBVector *get_struct_vector(VALUE obj) {
35
+ rubyDuckDBVector *rbduckdb_get_struct_vector(VALUE obj) {
36
36
  rubyDuckDBVector *ctx;
37
37
  TypedData_Get_Struct(obj, rubyDuckDBVector, &vector_data_type, ctx);
38
38
  return ctx;
@@ -47,7 +47,7 @@ rubyDuckDBVector *get_struct_vector(VALUE obj) {
47
47
  *
48
48
  * ptr = vector.get_data
49
49
  */
50
- static VALUE rbduckdb_vector_get_data(VALUE self) {
50
+ static VALUE vector_get_data(VALUE self) {
51
51
  rubyDuckDBVector *ctx;
52
52
  void *data;
53
53
 
@@ -67,7 +67,7 @@ static VALUE rbduckdb_vector_get_data(VALUE self) {
67
67
  *
68
68
  * validity = vector.get_validity
69
69
  */
70
- static VALUE rbduckdb_vector_get_validity(VALUE self) {
70
+ static VALUE vector_get_validity(VALUE self) {
71
71
  rubyDuckDBVector *ctx;
72
72
  uint64_t *validity;
73
73
 
@@ -90,7 +90,7 @@ static VALUE rbduckdb_vector_get_validity(VALUE self) {
90
90
  *
91
91
  * vector.assign_string_element(0, 'hello')
92
92
  */
93
- static VALUE rbduckdb_vector_assign_string_element(VALUE self, VALUE index, VALUE str) {
93
+ static VALUE vector_assign_string_element(VALUE self, VALUE index, VALUE str) {
94
94
  rubyDuckDBVector *ctx;
95
95
  idx_t idx;
96
96
  const char *string_val;
@@ -114,7 +114,7 @@ static VALUE rbduckdb_vector_assign_string_element(VALUE self, VALUE index, VALU
114
114
  *
115
115
  * vector.assign_string_element_len(0, "\x00\x01\x02\x03")
116
116
  */
117
- static VALUE rbduckdb_vector_assign_string_element_len(VALUE self, VALUE index, VALUE str) {
117
+ static VALUE vector_assign_string_element_len(VALUE self, VALUE index, VALUE str) {
118
118
  rubyDuckDBVector *ctx;
119
119
  idx_t idx;
120
120
  const char *string_val;
@@ -141,7 +141,7 @@ static VALUE rbduckdb_vector_assign_string_element_len(VALUE self, VALUE index,
141
141
  * type = vector.logical_type
142
142
  * type.id #=> DuckDB::Type::BIGINT
143
143
  */
144
- static VALUE rbduckdb_vector_logical_type(VALUE self) {
144
+ static VALUE vector_logical_type(VALUE self) {
145
145
  rubyDuckDBVector *ctx;
146
146
  duckdb_logical_type logical_type;
147
147
 
@@ -161,7 +161,7 @@ static VALUE rbduckdb_vector_logical_type(VALUE self) {
161
161
  * vector.set_validity(0, false) # Mark row 0 as NULL
162
162
  * vector.set_validity(1, true) # Mark row 1 as valid
163
163
  */
164
- static VALUE rbduckdb_vector_set_validity(VALUE self, VALUE index, VALUE valid) {
164
+ static VALUE vector_set_validity(VALUE self, VALUE index, VALUE valid) {
165
165
  rubyDuckDBVector *ctx;
166
166
  idx_t idx;
167
167
  uint64_t *validity;
@@ -185,17 +185,17 @@ static VALUE rbduckdb_vector_set_validity(VALUE self, VALUE index, VALUE valid)
185
185
  return self;
186
186
  }
187
187
 
188
- void rbduckdb_init_duckdb_vector(void) {
188
+ void rbduckdb_init_vector(void) {
189
189
  #if 0
190
190
  VALUE mDuckDB = rb_define_module("DuckDB");
191
191
  #endif
192
192
  cDuckDBVector = rb_define_class_under(mDuckDB, "Vector", rb_cObject);
193
193
  rb_define_alloc_func(cDuckDBVector, allocate);
194
194
 
195
- rb_define_method(cDuckDBVector, "get_data", rbduckdb_vector_get_data, 0);
196
- rb_define_method(cDuckDBVector, "get_validity", rbduckdb_vector_get_validity, 0);
197
- rb_define_method(cDuckDBVector, "assign_string_element", rbduckdb_vector_assign_string_element, 2);
198
- rb_define_method(cDuckDBVector, "assign_string_element_len", rbduckdb_vector_assign_string_element_len, 2);
199
- rb_define_method(cDuckDBVector, "logical_type", rbduckdb_vector_logical_type, 0);
200
- rb_define_method(cDuckDBVector, "set_validity", rbduckdb_vector_set_validity, 2);
195
+ rb_define_method(cDuckDBVector, "get_data", vector_get_data, 0);
196
+ rb_define_method(cDuckDBVector, "get_validity", vector_get_validity, 0);
197
+ rb_define_method(cDuckDBVector, "assign_string_element", vector_assign_string_element, 2);
198
+ rb_define_method(cDuckDBVector, "assign_string_element_len", vector_assign_string_element_len, 2);
199
+ rb_define_method(cDuckDBVector, "logical_type", vector_logical_type, 0);
200
+ rb_define_method(cDuckDBVector, "set_validity", vector_set_validity, 2);
201
201
  }
data/ext/duckdb/vector.h CHANGED
@@ -7,7 +7,7 @@ struct _rubyDuckDBVector {
7
7
 
8
8
  typedef struct _rubyDuckDBVector rubyDuckDBVector;
9
9
 
10
- rubyDuckDBVector *get_struct_vector(VALUE obj);
11
- void rbduckdb_init_duckdb_vector(void);
10
+ rubyDuckDBVector *rbduckdb_get_struct_vector(VALUE obj);
11
+ void rbduckdb_init_vector(void);
12
12
 
13
13
  #endif