class DuckDB::Value
Public Class Methods
Source
# File lib/duckdb/value.rb, line 522 def create_array(child_type, values) check_value_array!(values) _create_array(DuckDB::LogicalType.resolve(child_type), values) end
Creates a DuckDB::Value of ARRAY type. The array size is the number of elements given. The first argument is the element type: a Symbol (e.g. :integer) or a DuckDB::LogicalType. The second argument is an Array of DuckDB::Value elements.
values = [1, 2, 3].map { |i| DuckDB::Value.create_int32(i) } array = DuckDB::Value.create_array(:integer, values)
@param child_type [Symbol, DuckDB::LogicalType] the element logical type. @param values [Array<DuckDB::Value>] the array elements. @return [DuckDB::Value] the created Value object. @raise [DuckDB::Error] if child_type cannot be resolved to a
DuckDB::LogicalType.
@raise [ArgumentError] if values is not an Array of DuckDB::Value.
Source
# File lib/duckdb/value.rb, line 479 def create_bignum(value) check_type!(value, Integer) hex = value.abs.to_s(16) hex = "0#{hex}" if hex.length.odd? _create_bignum([hex].pack('H*'), value.negative?) end
Creates a DuckDB::Value of BIGNUM (arbitrary-precision integer) type.
value = DuckDB::Value.create_bignum(2**200)
@param value [Integer] the integer value, of arbitrary size. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not an Integer.
Source
# File lib/duckdb/value.rb, line 463 def create_bit(value) check_type!(value, String) raise ArgumentError, "expected a String of '0'/'1' characters" unless value.match?(/\A[01]+\z/) pad = -value.length % 8 _create_bit("#{pad.chr}#{[('1' * pad) + value].pack('B*')}".b) end
Creates a DuckDB::Value of BIT (bitstring) type.
value = DuckDB::Value.create_bit('0101')
@param value [String] the bitstring: โ0โ/โ1โ characters, MSB first. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not a non-empty String of โ0โ
and '1' characters.
Source
# File lib/duckdb/value.rb, line 188 def create_blob(value) check_type!(value, String) check_binary!(value) _create_blob(value) end
Creates a DuckDB::Value of BLOB type.
value = DuckDB::Value.create_blob("\x00\x01\x02".b)
@param value [String] the binary string value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not a BINARY encoded String.
Source
# File lib/duckdb/value.rb, line 18 def create_bool(value) check_type!(value, [TrueClass, FalseClass]) _create_bool(value) end
Creates a new DuckDB::Value with a boolean value.
require 'duckdb' value = DuckDB::Value.create_bool(true)
@param value [TrueClass, FalseClass] the boolean value @return [DuckDB::Value] @raise [ArgumentError] if value is not a boolean
Source
# File lib/duckdb/value.rb, line 251 def create_date(value) date = _parse_date(value) _create_date(date.year, date.month, date.day) end
Creates a DuckDB::Value of DATE type. The argument is parsed leniently: a Date, a Time, or a String accepted by Date.parse, matching Appender#append_date.
value = DuckDB::Value.create_date(Date.new(2026, 7, 12)) value = DuckDB::Value.create_date('2026-07-12')
@param value [Date, Time, String] the date value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Date.
Source
# File lib/duckdb/value.rb, line 231 def create_decimal(value) check_type!(value, BigDecimal) width = _decimal_width(value) check_range!(width, RANGE_DECIMAL_WIDTH, 'DECIMAL width') lower, upper = decimal_to_hugeint(value) _create_decimal(lower, upper, width, value.scale) end
Creates a DuckDB::Value of DECIMAL type.
value = DuckDB::Value.create_decimal(BigDecimal('12345.678'))
@param value [BigDecimal] the decimal value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not a BigDecimal or its width is out of range (1..38).
Source
# File lib/duckdb/value.rb, line 163 def create_double(value) check_type!(value, [Integer, Float]) _create_double(value) end
Creates a DuckDB::Value of DOUBLE type.
value = DuckDB::Value.create_double(1.5)
@param value [Numeric] the numeric value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not a Numeric.
Source
# File lib/duckdb/value.rb, line 412 def create_enum(enum_type, member) enum_type = DuckDB::LogicalType.create_enum(*enum_type) if enum_type.is_a?(Array) check_type!(enum_type, DuckDB::LogicalType) raise ArgumentError, "expected ENUM LogicalType, got #{enum_type.type}" unless enum_type.type == :enum _create_enum(enum_type, enum_member_index(enum_type, member)) end
Creates a DuckDB::Value of ENUM type. The first argument is the enum type: an Array of member names (as accepted by DuckDB::LogicalType.create_enum) or an ENUM DuckDB::LogicalType. The second argument is the member: its name (String or Symbol) or its 0-based index (Integer).
value = DuckDB::Value.create_enum(%w[happy sad neutral], 'sad') # equivalent, with an explicit ENUM logical type: enum_type = DuckDB::LogicalType.create_enum('happy', 'sad', 'neutral') value = DuckDB::Value.create_enum(enum_type, 'sad')
@param enum_type [Array<String>, DuckDB::LogicalType] the member names or ENUM logical type. @param member [String, Symbol, Integer] the member name or 0-based index. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if enum_type is not an Array or an ENUM
DuckDB::LogicalType, or member is not a member of the enum.
Source
# File lib/duckdb/value.rb, line 151 def create_float(value) check_type!(value, [Integer, Float]) _create_float(value) end
Creates a DuckDB::Value of FLOAT type.
value = DuckDB::Value.create_float(1.5)
@param value [Numeric] the numeric value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not a Numeric.
Source
# File lib/duckdb/value.rb, line 201 def create_hugeint(value) check_type!(value, Integer) check_range!(value, RANGE_HUGEINT, 'HUGEINT') lower, upper = integer_to_hugeint(value) _create_hugeint(lower, upper) end
Creates a DuckDB::Value of HUGEINT type.
value = DuckDB::Value.create_hugeint(1_234_567_890_123_456_789_012_345)
@param value [Integer] the integer value (-(2**127)..(2**127 - 1)) @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not an Integer or out of range.
Source
# File lib/duckdb/value.rb, line 47 def create_int16(value) check_type!(value, Integer) check_range!(value, RANGE_INT16, 'INT16') _create_int16(value) end
Creates a new DuckDB::Value with an INT16 (SMALLINT) value.
require 'duckdb' value = DuckDB::Value.create_int16(32_767)
@param value [Integer] the integer value (-32768..32767) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 62 def create_int32(value) check_type!(value, Integer) check_range!(value, RANGE_INT32, 'INT32') _create_int32(value) end
Creates a new DuckDB::Value with an INT32 (INTEGER) value.
require 'duckdb' value = DuckDB::Value.create_int32(2_147_483_647)
@param value [Integer] the integer value (-2147483648..2147483647) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 77 def create_int64(value) check_type!(value, Integer) check_range!(value, RANGE_INT64, 'INT64') _create_int64(value) end
Creates a new DuckDB::Value with an INT64 (BIGINT) value.
require 'duckdb' value = DuckDB::Value.create_int64(9_223_372_036_854_775_807)
@param value [Integer] the integer value (-9223372036854775808..9223372036854775807) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 32 def create_int8(value) check_type!(value, Integer) check_range!(value, RANGE_INT8, 'INT8') _create_int8(value) end
Creates a new DuckDB::Value with an INT8 (TINYINT) value.
require 'duckdb' value = DuckDB::Value.create_int8(127)
@param value [Integer] the integer value (-128..127) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 388 def create_interval(value) check_type!(value, DuckDB::Interval) _create_interval(value.interval_months, value.interval_days, value.interval_micros) end
Creates a DuckDB::Value of INTERVAL type. Unlike the other temporal creators, the input is strict: it must be a DuckDB::Interval.
interval = DuckDB::Interval.new(interval_months: 14, interval_days: 3, interval_micros: 12_000_000) value = DuckDB::Value.create_interval(interval)
@param value [DuckDB::Interval] the interval value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not a DuckDB::Interval.
Source
# File lib/duckdb/value.rb, line 501 def create_list(child_type, values) check_value_array!(values) _create_list(DuckDB::LogicalType.resolve(child_type), values) end
Creates a DuckDB::Value of LIST type. The first argument is the element type: a Symbol (e.g. :integer) or a DuckDB::LogicalType. The second argument is an Array of DuckDB::Value elements.
values = [1, 2, 3].map { |i| DuckDB::Value.create_int32(i) } list = DuckDB::Value.create_list(:integer, values)
@param child_type [Symbol, DuckDB::LogicalType] the element logical type. @param values [Array<DuckDB::Value>] the list elements. @return [DuckDB::Value] the created Value object. @raise [DuckDB::Error] if child_type cannot be resolved to a
DuckDB::LogicalType.
@raise [ArgumentError] if values is not an Array of DuckDB::Value.
Source
# File lib/duckdb/value.rb, line 590 def create_map(map_type, entries) map_type = resolve_map_type(map_type) check_type!(entries, Hash) check_value_array!(entries.keys) check_value_array!(entries.values) _create_map(map_type, entries.keys, entries.values) end
Creates a DuckDB::Value of MAP type. The first argument is the type spec: a one-pair Hash of key type to value type (each a Symbol or a DuckDB::LogicalType, as accepted by DuckDB::LogicalType.create_map) or a MAP DuckDB::LogicalType. The second argument is a Hash of DuckDB::Value keys to DuckDB::Value values.
entries = { DuckDB::Value.create_varchar('a') => DuckDB::Value.create_int32(1), DuckDB::Value.create_varchar('b') => DuckDB::Value.create_int32(2) } map = DuckDB::Value.create_map({ varchar: :integer }, entries) # equivalent, with an explicit MAP logical type: map_type = DuckDB::LogicalType.create_map(:varchar, :integer) map = DuckDB::Value.create_map(map_type, entries)
@param map_type [Hash, DuckDB::LogicalType] the type spec or MAP logical type. @param entries [Hash{DuckDB::Value => DuckDB::Value}] the map entries. @return [DuckDB::Value] the created Value object. @raise [DuckDB::Error] if a type in the Hash spec cannot be resolved
to a DuckDB::LogicalType.
@raise [ArgumentError] if map_type is not a one-pair Hash or a MAP
DuckDB::LogicalType, or entries is not a Hash of DuckDB::Value to DuckDB::Value.
Source
static VALUE value_s_create_null(VALUE klass) {
duckdb_value value = duckdb_create_null_value();
return rbduckdb_value_new(value);
}
Creates a new DuckDB::Value representing SQL NULL.
require 'duckdb' value = DuckDB::Value.create_null
Source
# File lib/duckdb/value.rb, line 550 def create_struct(struct_type, values) struct_type = DuckDB::LogicalType.create_struct(**struct_type) if struct_type.is_a?(Hash) check_type!(struct_type, DuckDB::LogicalType) raise ArgumentError, "expected STRUCT LogicalType, got #{struct_type.type}" unless struct_type.type == :struct check_value_array!(values) # The C API's duckdb_create_struct_value reads exactly child_count # values from the buffer with no count argument, so a size mismatch # here would cause an out-of-bounds read in C. n = struct_type.child_count raise ArgumentError, "expected #{n} values for STRUCT, got #{values.size}" unless values.size == n _create_struct(struct_type, values) end
Creates a DuckDB::Value of STRUCT type. The first argument is the field spec: a Hash of field name to field type (a Symbol or a DuckDB::LogicalType, as accepted by DuckDB::LogicalType.create_struct) or a STRUCT DuckDB::LogicalType. The second argument is an Array of DuckDB::Value field values, positional, matching the structโs field order.
values = [DuckDB::Value.create_int32(1), DuckDB::Value.create_varchar('x')] struct = DuckDB::Value.create_struct({ a: :integer, b: :varchar }, values) # equivalent, with an explicit STRUCT logical type: struct_type = DuckDB::LogicalType.create_struct(a: :integer, b: :varchar) struct = DuckDB::Value.create_struct(struct_type, values)
@param struct_type [Hash, DuckDB::LogicalType] the field spec or STRUCT logical type. @param values [Array<DuckDB::Value>] the field values, in field order. @return [DuckDB::Value] the created Value object. @raise [DuckDB::Error] if a field type in the Hash cannot be resolved
to a DuckDB::LogicalType.
@raise [ArgumentError] if struct_type is not a Hash or a STRUCT
DuckDB::LogicalType, values is not an Array of DuckDB::Value, or values.size does not match the struct's field count.
Source
# File lib/duckdb/value.rb, line 266 def create_time(value) time = _parse_time(value) _create_time(time.hour, time.min, time.sec, time.usec) end
Creates a DuckDB::Value of TIME type (microsecond precision). The argument is parsed leniently: a Time or a String accepted by Time.parse, matching Appender#append_time.
value = DuckDB::Value.create_time(Time.now) value = DuckDB::Value.create_time('12:34:56.789')
@param value [Time, String] the time value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 281 def create_time_ns(value) time = _parse_time(value) _create_time_ns(time.hour, time.min, time.sec, time.nsec) end
Creates a DuckDB::Value of TIME_NS type (nanosecond precision). The argument is parsed leniently: a Time or a String accepted by Time.parse. Nanoseconds are preserved.
value = DuckDB::Value.create_time_ns(Time.now) value = DuckDB::Value.create_time_ns('12:34:56.123456789')
@param value [Time, String] the time value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 296 def create_time_tz(value) time = _parse_time(value) micros = (((((time.hour * 60) + time.min) * 60) + time.sec) * 1_000_000) + time.usec _create_time_tz(micros, time.utc_offset) end
Creates a DuckDB::Value of TIMETZ type (time with UTC offset). The argument is parsed leniently: a Time (the offset is taken from the Time) or a String accepted by Time.parse.
value = DuckDB::Value.create_time_tz(Time.now) value = DuckDB::Value.create_time_tz('12:34:56.789012+05:30')
@param value [Time, String] the time value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 312 def create_timestamp(value) time = to_time(value) _create_timestamp(time.year, time.month, time.day, time.hour, time.min, time.sec, time.usec) end
Creates a DuckDB::Value of TIMESTAMP type (microsecond precision). The argument is parsed leniently: a Time, a Date, or a String accepted by Time.parse, matching Appender#append_timestamp.
value = DuckDB::Value.create_timestamp(Time.now) value = DuckDB::Value.create_timestamp('2026-07-12 12:34:56.789')
@param value [Time, Date, String] the timestamp value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 342 def create_timestamp_ms(value) time = to_time(value) _create_timestamp_ms(time.year, time.month, time.day, time.hour, time.min, time.sec, time.usec) end
Creates a DuckDB::Value of TIMESTAMP_MS type (millisecond precision). The argument is parsed leniently: a Time, a Date, or a String accepted by Time.parse. Sub-millisecond input is truncated.
value = DuckDB::Value.create_timestamp_ms(Time.now) value = DuckDB::Value.create_timestamp_ms('2026-07-12 12:34:56.789')
@param value [Time, Date, String] the timestamp value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 357 def create_timestamp_ns(value) time = to_time(value) _create_timestamp_ns(time.year, time.month, time.day, time.hour, time.min, time.sec, time.nsec) end
Creates a DuckDB::Value of TIMESTAMP_NS type (nanosecond precision). The argument is parsed leniently: a Time, a Date, or a String accepted by Time.parse. Nanoseconds are preserved.
value = DuckDB::Value.create_timestamp_ns(Time.now) value = DuckDB::Value.create_timestamp_ns('2026-07-12 12:34:56.123456789')
@param value [Time, Date, String] the timestamp value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 327 def create_timestamp_s(value) time = to_time(value) _create_timestamp_s(time.year, time.month, time.day, time.hour, time.min, time.sec) end
Creates a DuckDB::Value of TIMESTAMP_S type (second precision). The argument is parsed leniently: a Time, a Date, or a String accepted by Time.parse. Sub-second input is truncated to seconds.
value = DuckDB::Value.create_timestamp_s(Time.now) value = DuckDB::Value.create_timestamp_s('2026-07-12 12:34:56')
@param value [Time, Date, String] the timestamp value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 373 def create_timestamp_tz(value) time = to_time(value) _create_timestamp_tz((time.to_i * 1_000_000) + time.usec) end
Creates a DuckDB::Value of TIMESTAMP WITH TIME ZONE type. The argument is parsed leniently: a Time, a Date, or a String accepted by Time.parse. The instant is stored (as microseconds since the Unix epoch), so the inputโs UTC offset is honored.
value = DuckDB::Value.create_timestamp_tz(Time.now) value = DuckDB::Value.create_timestamp_tz('2026-07-12 12:34:56.789+05:30')
@param value [Time, Date, String] the timestamp value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value cannot be parsed to a Time.
Source
# File lib/duckdb/value.rb, line 216 def create_uhugeint(value) check_type!(value, Integer) check_range!(value, RANGE_UHUGEINT, 'UHUGEINT') lower, upper = integer_to_hugeint(value) _create_uhugeint(lower, upper) end
Creates a DuckDB::Value of UHUGEINT type.
value = DuckDB::Value.create_uhugeint(340_282_366_920_938_463_463_374_607_431_768_211_455)
@param value [Integer] the integer value (0..(2**128 - 1)) @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not an Integer or out of range.
Source
# File lib/duckdb/value.rb, line 107 def create_uint16(value) check_type!(value, Integer) check_range!(value, RANGE_UINT16, 'UINT16') _create_uint16(value) end
Creates a new DuckDB::Value with a UINT16 (USMALLINT) value.
require 'duckdb' value = DuckDB::Value.create_uint16(65_535)
@param value [Integer] the integer value (0..65535) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 122 def create_uint32(value) check_type!(value, Integer) check_range!(value, RANGE_UINT32, 'UINT32') _create_uint32(value) end
Creates a new DuckDB::Value with a UINT32 (UINTEGER) value.
require 'duckdb' value = DuckDB::Value.create_uint32(4_294_967_295)
@param value [Integer] the integer value (0..4294967295) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 137 def create_uint64(value) check_type!(value, Integer) check_range!(value, RANGE_UINT64, 'UINT64') _create_uint64(value) end
Creates a new DuckDB::Value with a UINT64 (UBIGINT) value.
require 'duckdb' value = DuckDB::Value.create_uint64(18_446_744_073_709_551_615)
@param value [Integer] the integer value (0..18446744073709551615) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 92 def create_uint8(value) check_type!(value, Integer) check_range!(value, RANGE_UINT8, 'UINT8') _create_uint8(value) end
Creates a new DuckDB::Value with a UINT8 (UTINYINT) value.
require 'duckdb' value = DuckDB::Value.create_uint8(255)
@param value [Integer] the integer value (0..255) @return [DuckDB::Value] @raise [ArgumentError] if value is not an Integer or out of range
Source
# File lib/duckdb/value.rb, line 443 def create_union(union_type, tag, member_value) union_type = DuckDB::LogicalType.create_union(**union_type) if union_type.is_a?(Hash) check_type!(union_type, DuckDB::LogicalType) raise ArgumentError, "expected UNION LogicalType, got #{union_type.type}" unless union_type.type == :union check_type!(member_value, DuckDB::Value) tag_index = union_type.each_member_name.find_index(tag.to_s) raise ArgumentError, "`#{tag}` is not a member of the union" if tag_index.nil? _create_union(union_type, tag_index, member_value) end
Creates a DuckDB::Value of UNION type. The first argument is the union type: a Hash of member name to member type (as accepted by DuckDB::LogicalType.create_union) or a UNION DuckDB::LogicalType. The second argument is the member tag (String or Symbol), and the third is the member value as a DuckDB::Value of the tagged type.
value = DuckDB::Value.create_union({ num: :integer, str: :varchar }, :num, DuckDB::Value.create_int32(42)) value.to_ruby #=> 42 # equivalent, with an explicit UNION logical type: union_type = DuckDB::LogicalType.create_union(num: :integer, str: :varchar) value = DuckDB::Value.create_union(union_type, :num, DuckDB::Value.create_int32(42))
@param union_type [Hash, DuckDB::LogicalType] the member spec or UNION logical type. @param tag [String, Symbol] the member tag. @param member_value [DuckDB::Value] the member value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if union_type is not a Hash or a UNION
DuckDB::LogicalType, tag is not a member of the union, or member_value is not a DuckDB::Value.
@raise [DuckDB::Error] if member_value does not match the tagged
member's type.
Source
# File lib/duckdb/value.rb, line 175 def create_varchar(value) check_type!(value, String) check_utf8_compatible!(value) _create_varchar(value) end
Creates a DuckDB::Value of VARCHAR type.
value = DuckDB::Value.create_varchar('hello')
@param value [String] the string value. @return [DuckDB::Value] the created Value object. @raise [ArgumentError] if value is not a String.
Public Instance Methods
Source
static VALUE value_list_child(VALUE self, VALUE vidx) {
duckdb_value child = duckdb_get_list_child(rbduckdb_get_struct_value(self)->value, (idx_t)NUM2ULL(vidx));
if (child == NULL) {
rb_raise(rb_eIndexError, "list index out of range (or the value is not a LIST)");
}
return rbduckdb_value_new(child);
}
Returns the element at the specified index (0-based) of a LIST value as a DuckDB::Value. Raises IndexError if the index is out of range or the value is not a LIST.
require 'duckdb' child_type = DuckDB::LogicalType.resolve(:integer) values = [1, 2, 3].map { |i| DuckDB::Value.create_int32(i) } list = DuckDB::Value.create_list(child_type, values) list.list_child(0) # => DuckDB::Value
Source
static VALUE value_list_size(VALUE self) {
return ULL2NUM(duckdb_get_list_size(rbduckdb_get_struct_value(self)->value));
}
Returns the number of elements of a LIST value.
require 'duckdb' child_type = DuckDB::LogicalType.resolve(:integer) values = [1, 2, 3].map { |i| DuckDB::Value.create_int32(i) } list = DuckDB::Value.create_list(child_type, values) list.list_size # => 3
Source
static VALUE value_map_key(VALUE self, VALUE vidx) {
duckdb_value child = duckdb_get_map_key(rbduckdb_get_struct_value(self)->value, (idx_t)NUM2ULL(vidx));
if (child == NULL) {
rb_raise(rb_eIndexError, "map index out of range (or the value is not a MAP)");
}
return rbduckdb_value_new(child);
}
Returns the key at the specified index (0-based) of a MAP value as a DuckDB::Value. Raises IndexError if the index is out of range or the value is not a MAP.
require 'duckdb' map_type = DuckDB::LogicalType.create_map(:varchar, :integer) keys = [DuckDB::Value.create_varchar('a')] values = [DuckDB::Value.create_int32(1)] map = DuckDB::Value.create_map(map_type, keys, values) map.map_key(0) # => DuckDB::Value
Source
static VALUE value_map_size(VALUE self) {
return ULL2NUM(duckdb_get_map_size(rbduckdb_get_struct_value(self)->value));
}
Returns the number of entries of a MAP value.
require 'duckdb' map_type = DuckDB::LogicalType.create_map(:varchar, :integer) keys = [DuckDB::Value.create_varchar('a')] values = [DuckDB::Value.create_int32(1)] map = DuckDB::Value.create_map(map_type, keys, values) map.map_size # => 1
Source
static VALUE value_map_value(VALUE self, VALUE vidx) {
duckdb_value child = duckdb_get_map_value(rbduckdb_get_struct_value(self)->value, (idx_t)NUM2ULL(vidx));
if (child == NULL) {
rb_raise(rb_eIndexError, "map index out of range (or the value is not a MAP)");
}
return rbduckdb_value_new(child);
}
Returns the value at the specified index (0-based) of a MAP value as a DuckDB::Value. Raises IndexError if the index is out of range or the value is not a MAP.
require 'duckdb' map_type = DuckDB::LogicalType.create_map(:varchar, :integer) keys = [DuckDB::Value.create_varchar('a')] values = [DuckDB::Value.create_int32(1)] map = DuckDB::Value.create_map(map_type, keys, values) map.map_value(0) # => DuckDB::Value
Source
static VALUE value_struct_child(VALUE self, VALUE vidx) {
duckdb_value child = duckdb_get_struct_child(rbduckdb_get_struct_value(self)->value, (idx_t)NUM2ULL(vidx));
if (child == NULL) {
rb_raise(rb_eIndexError, "struct index out of range (or the value is not a STRUCT)");
}
return rbduckdb_value_new(child);
}
Returns the field at the specified index (0-based) of a STRUCT value as a DuckDB::Value. Raises IndexError if the index is out of range or the value is not a STRUCT.
require 'duckdb' struct_type = DuckDB::LogicalType.create_struct(a: :integer, b: :varchar) values = [DuckDB::Value.create_int32(1), DuckDB::Value.create_varchar('x')] struct = DuckDB::Value.create_struct(struct_type, values) struct.struct_child(0) # => DuckDB::Value
Source
static VALUE value_to_ruby(VALUE self) {
return rbduckdb_duckdb_value_to_ruby(rbduckdb_get_struct_value(self)->value);
}
Converts the DuckDB::Value to a Ruby object. Scalar types are converted to their natural Ruby classes. LIST and ARRAY values are converted to Array recursively. STRUCT and MAP values are converted to Hash recursively (STRUCT keys are Symbols; MAP keys keep their natural Ruby type). ENUM values are converted to the member String. UNION values are converted to the memberโs Ruby value. BIT values are converted to a String of โ0โ/โ1โ characters. BIGNUM values are converted to Integer. BLOB values are converted to a BINARY-encoded String. DECIMAL values are converted to BigDecimal. NULL is converted to nil. Returns nil for unsupported types.
require 'duckdb' child_type = DuckDB::LogicalType.resolve(:integer) values = [1, 2, 3].map { |i| DuckDB::Value.create_int32(i) } list = DuckDB::Value.create_list(child_type, values) list.to_ruby # => [1, 2, 3]