duckdb 1.5.3.0 → 1.5.5.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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/CLAUDE.md +4 -0
  4. data/README.md +52 -0
  5. data/duckdb.gemspec +1 -1
  6. data/ext/duckdb/aggregate_function.c +0 -1
  7. data/ext/duckdb/appender.c +17 -0
  8. data/ext/duckdb/arrow_array_stream.c +226 -0
  9. data/ext/duckdb/arrow_array_stream.h +61 -0
  10. data/ext/duckdb/arrow_import.c +165 -0
  11. data/ext/duckdb/arrow_import.h +6 -0
  12. data/ext/duckdb/blob.c +1 -1
  13. data/ext/duckdb/blob.h +1 -2
  14. data/ext/duckdb/config.c +1 -1
  15. data/ext/duckdb/config.h +1 -1
  16. data/ext/duckdb/connection.c +26 -4
  17. data/ext/duckdb/converter.h +1 -0
  18. data/ext/duckdb/conveter.c +39 -9
  19. data/ext/duckdb/data_chunk.c +10 -0
  20. data/ext/duckdb/data_chunk.h +1 -0
  21. data/ext/duckdb/duckdb.c +13 -11
  22. data/ext/duckdb/error.c +13 -1
  23. data/ext/duckdb/error.h +2 -3
  24. data/ext/duckdb/function_executor.c +308 -2
  25. data/ext/duckdb/function_executor.h +44 -0
  26. data/ext/duckdb/function_vector.c +14 -0
  27. data/ext/duckdb/prepared_statement.c +141 -5
  28. data/ext/duckdb/result.c +49 -3
  29. data/ext/duckdb/result.h +11 -0
  30. data/ext/duckdb/ruby-duckdb.h +3 -0
  31. data/ext/duckdb/scalar_function.c +97 -29
  32. data/ext/duckdb/scalar_function.h +2 -4
  33. data/ext/duckdb/scalar_function_bind_info.c +13 -13
  34. data/ext/duckdb/scalar_function_bind_info.h +1 -1
  35. data/ext/duckdb/scalar_function_set.c +9 -9
  36. data/ext/duckdb/scalar_function_set.h +2 -2
  37. data/ext/duckdb/table_description.c +19 -19
  38. data/ext/duckdb/table_description.h +1 -1
  39. data/ext/duckdb/table_function.c +94 -28
  40. data/ext/duckdb/table_function.h +2 -2
  41. data/ext/duckdb/table_function_bind_info.c +20 -20
  42. data/ext/duckdb/table_function_bind_info.h +2 -2
  43. data/ext/duckdb/table_function_function_info.c +5 -5
  44. data/ext/duckdb/table_function_function_info.h +2 -2
  45. data/ext/duckdb/table_function_init_info.c +70 -5
  46. data/ext/duckdb/table_function_init_info.h +2 -2
  47. data/ext/duckdb/util.c +8 -0
  48. data/ext/duckdb/util.h +1 -0
  49. data/ext/duckdb/value.c +526 -1
  50. data/lib/duckdb/appender.rb +23 -0
  51. data/lib/duckdb/arrow_array_stream.rb +33 -0
  52. data/lib/duckdb/connection.rb +73 -0
  53. data/lib/duckdb/converter/int_to_sym.rb +54 -1
  54. data/lib/duckdb/converter.rb +7 -7
  55. data/lib/duckdb/error.rb +26 -0
  56. data/lib/duckdb/function_type_validation.rb +1 -0
  57. data/lib/duckdb/logical_type.rb +6 -3
  58. data/lib/duckdb/prepared_statement.rb +32 -0
  59. data/lib/duckdb/scalar_function.rb +6 -6
  60. data/lib/duckdb/value.rb +400 -0
  61. data/lib/duckdb/version.rb +1 -1
  62. data/lib/duckdb.rb +2 -0
  63. metadata +10 -3
@@ -7,7 +7,7 @@ struct _rubyDuckDBFunctionInfo {
7
7
 
8
8
  typedef struct _rubyDuckDBFunctionInfo rubyDuckDBFunctionInfo;
9
9
 
10
- rubyDuckDBFunctionInfo *get_struct_function_info(VALUE obj);
11
- void rbduckdb_init_duckdb_table_function_function_info(void);
10
+ rubyDuckDBFunctionInfo *rbduckdb_get_struct_function_info(VALUE obj);
11
+ void rbduckdb_init_table_function_function_info(void);
12
12
 
13
13
  #endif
@@ -5,7 +5,10 @@ VALUE cDuckDBTableFunctionInitInfo;
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_init_info_set_error(VALUE self, VALUE error);
8
+ static VALUE table_function_init_info_set_error(VALUE self, VALUE error);
9
+ static VALUE table_function_init_info_set_max_threads(VALUE self, VALUE max_threads);
10
+ static VALUE table_function_init_info_column_count(VALUE self);
11
+ static VALUE table_function_init_info_column_index(VALUE self, VALUE index);
9
12
 
10
13
  static const rb_data_type_t init_info_data_type = {
11
14
  "DuckDB/TableFunctionInitInfo",
@@ -27,7 +30,7 @@ static size_t memsize(const void *p) {
27
30
  return sizeof(rubyDuckDBInitInfo);
28
31
  }
29
32
 
30
- rubyDuckDBInitInfo *get_struct_init_info(VALUE obj) {
33
+ rubyDuckDBInitInfo *rbduckdb_get_struct_init_info(VALUE obj) {
31
34
  rubyDuckDBInitInfo *ctx;
32
35
  TypedData_Get_Struct(obj, rubyDuckDBInitInfo, &init_info_data_type, ctx);
33
36
  return ctx;
@@ -42,7 +45,7 @@ rubyDuckDBInitInfo *get_struct_init_info(VALUE obj) {
42
45
  *
43
46
  * init_info.set_error('Invalid initialization')
44
47
  */
45
- static VALUE rbduckdb_init_info_set_error(VALUE self, VALUE error) {
48
+ static VALUE table_function_init_info_set_error(VALUE self, VALUE error) {
46
49
  rubyDuckDBInitInfo *ctx;
47
50
  const char *error_msg;
48
51
 
@@ -54,12 +57,74 @@ static VALUE rbduckdb_init_info_set_error(VALUE self, VALUE error) {
54
57
  return self;
55
58
  }
56
59
 
57
- void rbduckdb_init_duckdb_table_function_init_info(void) {
60
+ /*
61
+ * call-seq:
62
+ * init_info.set_max_threads(max_threads) -> self
63
+ * init_info.max_threads = max_threads
64
+ *
65
+ * Sets the maximum number of threads that can execute the table function concurrently.
66
+ * This is a hint to DuckDB's scheduler; the actual number of threads is also bounded
67
+ * by the configured worker pool size (e.g., +SET threads+).
68
+ *
69
+ * init_info.max_threads = 4
70
+ */
71
+ static VALUE table_function_init_info_set_max_threads(VALUE self, VALUE max_threads) {
72
+ rubyDuckDBInitInfo *ctx;
73
+
74
+ TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
75
+
76
+ duckdb_init_set_max_threads(ctx->info, NUM2ULL(max_threads));
77
+
78
+ return self;
79
+ }
80
+
81
+ /*
82
+ * call-seq:
83
+ * init_info.column_count -> Integer
84
+ *
85
+ * Returns the number of projected result columns for this scan.
86
+ * Without projection pushdown this equals the number of result columns
87
+ * added in the bind callback.
88
+ *
89
+ * init_info.column_count # => 2
90
+ */
91
+ static VALUE table_function_init_info_column_count(VALUE self) {
92
+ rubyDuckDBInitInfo *ctx;
93
+
94
+ TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
95
+
96
+ return ULL2NUM(duckdb_init_get_column_count(ctx->info));
97
+ }
98
+
99
+ /*
100
+ * call-seq:
101
+ * init_info.column_index(index) -> Integer
102
+ *
103
+ * Returns the column index of the projected result column at +index+
104
+ * (0 <= +index+ < column_count). Without projection pushdown the projected
105
+ * columns mirror the columns added in the bind callback, so this returns
106
+ * +index+ itself.
107
+ *
108
+ * init_info.column_index(0) # => 0
109
+ */
110
+ static VALUE table_function_init_info_column_index(VALUE self, VALUE index) {
111
+ rubyDuckDBInitInfo *ctx;
112
+
113
+ TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
114
+
115
+ return ULL2NUM(duckdb_init_get_column_index(ctx->info, NUM2ULL(index)));
116
+ }
117
+
118
+ void rbduckdb_init_table_function_init_info(void) {
58
119
  #if 0
59
120
  VALUE mDuckDB = rb_define_module("DuckDB");
60
121
  #endif
61
122
  cDuckDBTableFunctionInitInfo = rb_define_class_under(cDuckDBTableFunction, "InitInfo", rb_cObject);
62
123
  rb_define_alloc_func(cDuckDBTableFunctionInitInfo, allocate);
63
124
 
64
- rb_define_method(cDuckDBTableFunctionInitInfo, "set_error", rbduckdb_init_info_set_error, 1);
125
+ rb_define_method(cDuckDBTableFunctionInitInfo, "set_error", table_function_init_info_set_error, 1);
126
+ rb_define_method(cDuckDBTableFunctionInitInfo, "set_max_threads", table_function_init_info_set_max_threads, 1);
127
+ rb_define_method(cDuckDBTableFunctionInitInfo, "max_threads=", table_function_init_info_set_max_threads, 1);
128
+ rb_define_method(cDuckDBTableFunctionInitInfo, "column_count", table_function_init_info_column_count, 0);
129
+ rb_define_method(cDuckDBTableFunctionInitInfo, "column_index", table_function_init_info_column_index, 1);
65
130
  }
@@ -8,7 +8,7 @@ struct _rubyDuckDBInitInfo {
8
8
  typedef struct _rubyDuckDBInitInfo rubyDuckDBInitInfo;
9
9
 
10
10
  extern VALUE cDuckDBTableFunctionInitInfo;
11
- rubyDuckDBInitInfo *get_struct_init_info(VALUE obj);
12
- void rbduckdb_init_duckdb_table_function_init_info(void);
11
+ rubyDuckDBInitInfo *rbduckdb_get_struct_init_info(VALUE obj);
12
+ void rbduckdb_init_table_function_init_info(void);
13
13
 
14
14
  #endif
data/ext/duckdb/util.c CHANGED
@@ -21,6 +21,14 @@ duckdb_time rbduckdb_to_duckdb_time_from_value(VALUE hour, VALUE min, VALUE sec,
21
21
  return duckdb_to_time(time_st);
22
22
  }
23
23
 
24
+ duckdb_time_ns rbduckdb_to_duckdb_time_ns_from_value(VALUE hour, VALUE min, VALUE sec, VALUE nanos) {
25
+ duckdb_time_ns time_ns;
26
+
27
+ time_ns.nanos = ((NUM2LL(hour) * 60 + NUM2LL(min)) * 60 + NUM2LL(sec)) * 1000000000LL + NUM2LL(nanos);
28
+
29
+ return time_ns;
30
+ }
31
+
24
32
  duckdb_timestamp rbduckdb_to_duckdb_timestamp_from_time_value(VALUE time_obj) {
25
33
  if (!rb_obj_is_kind_of(time_obj, rb_cTime)) {
26
34
  rb_raise(rb_eTypeError, "Expected Time object");
data/ext/duckdb/util.h CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  duckdb_date rbduckdb_to_duckdb_date_from_value(VALUE year, VALUE month, VALUE day);
5
5
  duckdb_time rbduckdb_to_duckdb_time_from_value(VALUE hour, VALUE min, VALUE sec, VALUE micros);
6
+ duckdb_time_ns rbduckdb_to_duckdb_time_ns_from_value(VALUE hour, VALUE min, VALUE sec, VALUE nanos);
6
7
  duckdb_timestamp rbduckdb_to_duckdb_timestamp_from_time_value(VALUE time_obj);
7
8
  duckdb_timestamp rbduckdb_to_duckdb_timestamp_from_value(VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros);
8
9
  void rbduckdb_to_duckdb_interval_from_value(duckdb_interval* interval, VALUE months, VALUE days, VALUE micros);