Module: DuckDB::MemoryHelper

Defined in:
ext/duckdb/memory_helper.c

Class Method Summary collapse

Class Method Details

.DuckDB::MemoryHelper.write_bigint(ptr, index, value) ⇒ nil

Writes a 64-bit signed integer (BIGINT) to raw memory.

ptr = vector.get_data
DuckDB::MemoryHelper.write_bigint(ptr, 0, 42)  # Write 42 at index 0
DuckDB::MemoryHelper.write_bigint(ptr, 1, 84)  # Write 84 at index 1

Returns:

  • (nil)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'ext/duckdb/memory_helper.c', line 17

static VALUE rbduckdb_memory_helper_write_bigint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    int64_t *data;
    idx_t idx;
    int64_t val;

    (void)self;

    /* Convert Ruby values to C types */
    data = (int64_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    val = (int64_t)NUM2LL(value);

    /* Write the value */
    data[idx] = val;

    return Qnil;
}

.DuckDB::MemoryHelper.write_boolean(ptr, index, value) ⇒ nil

Writes a boolean to raw memory.

Returns:

  • (nil)


91
92
93
94
95
96
97
98
99
100
101
102
# File 'ext/duckdb/memory_helper.c', line 91

static VALUE rbduckdb_memory_helper_write_boolean(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    bool *data;
    idx_t idx;

    (void)self;

    data = (bool *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = RTEST(value);

    return Qnil;
}

.write_date(ptr, index, value) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'ext/duckdb/memory_helper.c', line 298

static VALUE rbduckdb_memory_helper_write_date(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    duckdb_date *data;
    idx_t idx;

    data = (duckdb_date *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);

    data[idx] = rbduckdb_to_duckdb_date_from_value(
        rb_funcall(value, rb_intern("year"), 0),
        rb_funcall(value, rb_intern("month"), 0),
        rb_funcall(value, rb_intern("day"), 0)
    );

    return Qnil;
}

.DuckDB::MemoryHelper.write_double(ptr, index, value) ⇒ nil

Writes a 64-bit floating point number (DOUBLE) to raw memory.

ptr = vector.get_data
DuckDB::MemoryHelper.write_double(ptr, 0, 3.14)

Returns:

  • (nil)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'ext/duckdb/memory_helper.c', line 44

static VALUE rbduckdb_memory_helper_write_double(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    double *data;
    idx_t idx;
    double val;

    (void)self;

    data = (double *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    val = NUM2DBL(value);

    data[idx] = val;

    return Qnil;
}

.DuckDB::MemoryHelper.write_float(ptr, index, value) ⇒ nil

Writes a 32-bit floating point number (FLOAT) to raw memory.

Returns:

  • (nil)


224
225
226
227
228
229
230
231
232
233
234
235
# File 'ext/duckdb/memory_helper.c', line 224

static VALUE rbduckdb_memory_helper_write_float(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    float *data;
    idx_t idx;

    (void)self;

    data = (float *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = (float)NUM2DBL(value);

    return Qnil;
}

.DuckDB::MemoryHelper.write_integer(ptr, index, value) ⇒ nil

Writes a 32-bit signed integer (INTEGER) to raw memory.

ptr = vector.get_data
DuckDB::MemoryHelper.write_integer(ptr, 0, 42)

Returns:

  • (nil)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/duckdb/memory_helper.c', line 69

static VALUE rbduckdb_memory_helper_write_integer(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    int32_t *data;
    idx_t idx;
    int32_t val;

    (void)self;

    data = (int32_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    val = (int32_t)NUM2INT(value);

    data[idx] = val;

    return Qnil;
}

.DuckDB::MemoryHelper.write_smallint(ptr, index, value) ⇒ nil

Writes a 16-bit signed integer (SMALLINT) to raw memory.

Returns:

  • (nil)


129
130
131
132
133
134
135
136
137
138
139
140
# File 'ext/duckdb/memory_helper.c', line 129

static VALUE rbduckdb_memory_helper_write_smallint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    int16_t *data;
    idx_t idx;

    (void)self;

    data = (int16_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = (int16_t)NUM2INT(value);

    return Qnil;
}

.DuckDB::MemoryHelper.write_timestamp(ptr, index, value) ⇒ nil

Writes a DuckDB timestamp to raw memory. value must be a Ruby Time object.

ptr = vector.get_data
DuckDB::MemoryHelper.write_timestamp(ptr, 0, Time.new(2024, 3, 15, 10, 30, 45))

Returns:

  • (nil)


247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'ext/duckdb/memory_helper.c', line 247

static VALUE rbduckdb_memory_helper_write_timestamp(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    duckdb_timestamp *data;
    idx_t idx;

    (void)self;

    if (!rb_obj_is_kind_of(value, rb_cTime)) {
        rb_raise(rb_eTypeError, "Expected Time object");
    }

    data = (duckdb_timestamp *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);

    VALUE local_time = rb_funcall(value, rb_intern("getlocal"), 0);
    data[idx] = rbduckdb_to_duckdb_timestamp_from_time_value(local_time);

    return Qnil;
}

.DuckDB::MemoryHelper.write_timestamp_tz(ptr, index, value) ⇒ nil

Writes a DuckDB TIMESTAMP_TZ to raw memory as microseconds since Unix epoch (UTC). value must be a Ruby Time object.

ptr = vector.get_data
DuckDB::MemoryHelper.write_timestamp_tz(ptr, 0, Time.new(2024, 3, 15, 10, 30, 45, '+00:00'))

Returns:

  • (nil)


276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'ext/duckdb/memory_helper.c', line 276

static VALUE rbduckdb_memory_helper_write_timestamp_tz(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    duckdb_time_tz *data;
    idx_t idx;
    int64_t secs;
    int32_t usecs;

    (void)self;

    if (!rb_obj_is_kind_of(value, rb_cTime)) {
        rb_raise(rb_eTypeError, "Expected Time object for TIMESTAMP_TZ");
    }

    data = (duckdb_time_tz *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);

    secs = NUM2LL(rb_funcall(value, rb_intern("to_i"), 0));
    usecs = NUM2INT(rb_funcall(value, rb_intern("usec"), 0));
    data[idx].bits = (uint64_t)(secs * 1000000LL + usecs);

    return Qnil;
}

.DuckDB::MemoryHelper.write_tinyint(ptr, index, value) ⇒ nil

Writes an 8-bit signed integer (TINYINT) to raw memory.

Returns:

  • (nil)


110
111
112
113
114
115
116
117
118
119
120
121
# File 'ext/duckdb/memory_helper.c', line 110

static VALUE rbduckdb_memory_helper_write_tinyint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    int8_t *data;
    idx_t idx;

    (void)self;

    data = (int8_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = (int8_t)NUM2INT(value);

    return Qnil;
}

.DuckDB::MemoryHelper.write_ubigint(ptr, index, value) ⇒ nil

Writes a 64-bit unsigned integer (UBIGINT) to raw memory.

Returns:

  • (nil)


205
206
207
208
209
210
211
212
213
214
215
216
# File 'ext/duckdb/memory_helper.c', line 205

static VALUE rbduckdb_memory_helper_write_ubigint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    uint64_t *data;
    idx_t idx;

    (void)self;

    data = (uint64_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = NUM2ULL(value);

    return Qnil;
}

.DuckDB::MemoryHelper.write_uinteger(ptr, index, value) ⇒ nil

Writes a 32-bit unsigned integer (UINTEGER) to raw memory.

Returns:

  • (nil)


186
187
188
189
190
191
192
193
194
195
196
197
# File 'ext/duckdb/memory_helper.c', line 186

static VALUE rbduckdb_memory_helper_write_uinteger(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    uint32_t *data;
    idx_t idx;

    (void)self;

    data = (uint32_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = (uint32_t)NUM2ULL(value);

    return Qnil;
}

.DuckDB::MemoryHelper.write_usmallint(ptr, index, value) ⇒ nil

Writes a 16-bit unsigned integer (USMALLINT) to raw memory.

Returns:

  • (nil)


167
168
169
170
171
172
173
174
175
176
177
178
# File 'ext/duckdb/memory_helper.c', line 167

static VALUE rbduckdb_memory_helper_write_usmallint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    uint16_t *data;
    idx_t idx;

    (void)self;

    data = (uint16_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = (uint16_t)NUM2UINT(value);

    return Qnil;
}

.DuckDB::MemoryHelper.write_utinyint(ptr, index, value) ⇒ nil

Writes an 8-bit unsigned integer (UTINYINT) to raw memory.

Returns:

  • (nil)


148
149
150
151
152
153
154
155
156
157
158
159
# File 'ext/duckdb/memory_helper.c', line 148

static VALUE rbduckdb_memory_helper_write_utinyint(VALUE self, VALUE ptr, VALUE index, VALUE value) {
    uint8_t *data;
    idx_t idx;

    (void)self;

    data = (uint8_t *)NUM2ULL(ptr);
    idx = (idx_t)NUM2ULL(index);
    data[idx] = (uint8_t)NUM2UINT(value);

    return Qnil;
}