class DuckDB::LogicalType
Public Instance Methods
Source
static VALUE duckdb_logical_type__internal_type(VALUE self) { rubyDuckDBLogicalType *ctx; duckdb_type type_id; duckdb_type internal_type_id; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); type_id = duckdb_get_type_id(ctx->logical_type); switch (type_id) { case DUCKDB_TYPE_DECIMAL: internal_type_id = duckdb_decimal_internal_type(ctx->logical_type); break; case DUCKDB_TYPE_ENUM: internal_type_id = duckdb_enum_internal_type(ctx->logical_type); break; default: internal_type_id = DUCKDB_TYPE_INVALID; } return INT2FIX(internal_type_id); }
Returns the logical type’s internal type.
Source
static VALUE duckdb_logical_type_child_count(VALUE self) { rubyDuckDBLogicalType *ctx; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); return INT2FIX(duckdb_struct_type_child_count(ctx->logical_type)); }
Returns the number of children of a struct type, otherwise 0.
Source
static VALUE duckdb_logical_type_child_name_at(VALUE self, VALUE cidx) { rubyDuckDBLogicalType *ctx; VALUE cname; const char *child_name; idx_t idx = NUM2ULL(cidx); TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); child_name = duckdb_struct_type_child_name(ctx->logical_type, idx); if (child_name == NULL) { rb_raise(eDuckDBError, "fail to get name of %llu child", (unsigned long long)idx); } cname = rb_str_new_cstr(child_name); duckdb_free((void *)child_name); return cname; }
Returns the name of the struct child at the specified index.
Source
static VALUE duckdb_logical_type_child_type(VALUE self) { rubyDuckDBLogicalType *ctx; duckdb_type type_id; duckdb_logical_type child_logical_type; VALUE logical_type = Qnil; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); type_id = duckdb_get_type_id(ctx->logical_type); switch(type_id) { case DUCKDB_TYPE_LIST: case DUCKDB_TYPE_MAP: child_logical_type = duckdb_list_type_child_type(ctx->logical_type); logical_type = rbduckdb_create_logical_type(child_logical_type); break; case DUCKDB_TYPE_ARRAY: child_logical_type = duckdb_array_type_child_type(ctx->logical_type); logical_type = rbduckdb_create_logical_type(child_logical_type); break; default: logical_type = Qnil; } return logical_type; }
Returns the child logical type for list and map types, otherwise nil.
Source
static VALUE duckdb_logical_type_child_type_at(VALUE self, VALUE cidx) { rubyDuckDBLogicalType *ctx; duckdb_logical_type struct_child_type; idx_t idx = NUM2ULL(cidx); TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); struct_child_type = duckdb_struct_type_child_type(ctx->logical_type, idx); if (struct_child_type == NULL) { rb_raise(eDuckDBError, "Failed to get the struct child type at index %llu", (unsigned long long)idx); } return rbduckdb_create_logical_type(struct_child_type); }
Returns the child logical type for struct types at the specified index as a DuckDB::LogicalType
object.
Source
static VALUE duckdb_logical_type_dictionary_size(VALUE self) { rubyDuckDBLogicalType *ctx; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); return INT2FIX(duckdb_enum_dictionary_size(ctx->logical_type)); }
Returns the dictionary size of the enum type.
Source
static VALUE duckdb_logical_type_dictionary_value_at(VALUE self, VALUE didx) { rubyDuckDBLogicalType *ctx; VALUE dvalue; const char *dict_value; idx_t idx = NUM2ULL(didx); TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); dict_value = duckdb_enum_dictionary_value(ctx->logical_type, idx); if (dict_value == NULL) { rb_raise(eDuckDBError, "fail to get dictionary value of %llu", (unsigned long long)idx); } dvalue = rb_utf8_str_new_cstr(dict_value); duckdb_free((void *)dict_value); return dvalue; }
Returns the dictionary value at the specified index.
Source
# File lib/duckdb/logical_type.rb, line 101 def each_child_name return to_enum(__method__) {child_count} unless block_given? child_count.times do |i| yield child_name_at(i) end end
Iterates over each struct child name.
When a block is provided, this method yields each struct child name in order. It also returns the total number of children yielded.
struct_logical_type.each_child_name do |name| puts "Struct child: #{name}" end
If no block is given, an Enumerator is returned, which can be used to retrieve all child names.
names = struct_logical_type.each_child_name.to_a # => ["child1", "child2"]
Source
# File lib/duckdb/logical_type.rb, line 123 def each_child_type return to_enum(__method__) {child_count} unless block_given? child_count.times do |i| yield child_type_at(i) end end
Iterates over each struct child type.
When a block is provided, this method yields each struct child type in order. It also returns the total number of children yielded.
struct_logical_type.each_child_type do |logical_type| puts "Struct child type: #{logical_type.type}" end
If no block is given, an Enumerator is returned, which can be used to retrieve all child logical types.
types = struct_logical_type.each_child_type.map(&:type) # => [:integer, :varchar]
Source
# File lib/duckdb/logical_type.rb, line 145 def each_dictionary_value return to_enum(__method__) {dictionary_size} unless block_given? dictionary_size.times do |i| yield dictionary_value_at(i) end end
Iterates over each enum dictionary value.
When a block is provided, this method yields each enum dictionary value in order. It also returns the total number of dictionary values yielded.
enum_logical_type.each_value do |value| puts "Enum value: #{value}" end
If no block is given, an Enumerator is returned, which can be used to retrieve all enum dictionary values.
values = enum_logical_type.each_value.to_a # => ["happy", "sad"]
Source
# File lib/duckdb/logical_type.rb, line 57 def each_member_name return to_enum(__method__) {member_count} unless block_given? member_count.times do |i| yield member_name_at(i) end end
Iterates over each union member name.
When a block is provided, this method yields each union member name in order. It also returns the total number of members yielded.
union_logical_type.each_member_name do |name| puts "Union member: #{name}" end
If no block is given, an Enumerator is returned, which can be used to retrieve all member names.
names = union_logical_type.each_member_name.to_a # => ["member1", "member2"]
Source
# File lib/duckdb/logical_type.rb, line 79 def each_member_type return to_enum(__method__) {member_count} unless block_given? member_count.times do |i| yield member_type_at(i) end end
Iterates over each union member type.
When a block is provided, this method yields each union member logical type in order. It also returns the total number of members yielded.
union_logical_type.each_member_type do |logical_type| puts "Union member: #{logical_type.type}" end
If no block is given, an Enumerator is returned, which can be used to retrieve all member logical types.
names = union_logical_type.each_member_type.map(&:type) # => [:varchar, :integer]
Source
static VALUE duckdb_logical_type__get_alias(VALUE self) { rubyDuckDBLogicalType *ctx; VALUE alias = Qnil; const char *_alias; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); _alias = duckdb_logical_type_get_alias(ctx->logical_type); if (_alias != NULL) { alias = rb_utf8_str_new_cstr(_alias); } duckdb_free((void *)_alias); return alias; }
Returns the alias of the logical type.
Source
# File lib/duckdb/logical_type.rb, line 38 def internal_type type_id = _internal_type DuckDB::Converter::IntToSym.type_to_sym(type_id) end
returns logical type’s internal type symbol for Decimal or Enum types ‘:unknown` means that the logical type’s type is unknown/unsupported by ruby-duckdb. ‘:invalid` means that the logical type’s type is invalid in duckdb.
require 'duckdb' db = DuckDB::Database.open con = db.connect con.query("CREATE TYPE mood AS ENUM ('happy', 'sad')") con.query("CREATE TABLE emotions (id INTEGER, enum_col mood)") users = con.query('SELECT * FROM emotions') ernum_col = users.columns.find { |col| col.name == 'enum_col' } enum_col.logical_type.internal_type #=> :utinyint
Source
static VALUE duckdb_logical_type_key_type(VALUE self) { rubyDuckDBLogicalType *ctx; duckdb_logical_type key_logical_type; VALUE logical_type = Qnil; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); key_logical_type = duckdb_map_type_key_type(ctx->logical_type); logical_type = rbduckdb_create_logical_type(key_logical_type); return logical_type; }
Returns the key logical type for map type, otherwise nil.
Source
static VALUE duckdb_logical_type_member_count(VALUE self) { rubyDuckDBLogicalType *ctx; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); return INT2FIX(duckdb_union_type_member_count(ctx->logical_type)); }
Returns the member count of union type, otherwise 0.
Source
static VALUE duckdb_logical_type_member_name_at(VALUE self, VALUE midx) { rubyDuckDBLogicalType *ctx; VALUE mname; const char *member_name; idx_t idx = NUM2ULL(midx); TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); member_name = duckdb_union_type_member_name(ctx->logical_type, idx); if (member_name == NULL) { rb_raise(eDuckDBError, "fail to get name of %llu member", (unsigned long long)idx); } mname = rb_str_new_cstr(member_name); duckdb_free((void *)member_name); return mname; }
Returns the name of the union member at the specified index.
Source
static VALUE duckdb_logical_type_member_type_at(VALUE self, VALUE midx) { rubyDuckDBLogicalType *ctx; duckdb_logical_type union_member_type; idx_t idx = NUM2ULL(midx); TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); union_member_type = duckdb_union_type_member_type(ctx->logical_type, idx); if (union_member_type == NULL) { rb_raise(eDuckDBError, "Failed to get the union member type at index %llu", (unsigned long long)idx); } return rbduckdb_create_logical_type(union_member_type); }
Returns the logical type of the union member at the specified index as a DuckDB::LogicalType
object.
Source
static VALUE duckdb_logical_type_scale(VALUE self) { rubyDuckDBLogicalType *ctx; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); return INT2FIX(duckdb_decimal_scale(ctx->logical_type)); }
Returns the scale of the decimal column.
Source
static VALUE duckdb_logical_type__set_alias(VALUE self, VALUE aname) { rubyDuckDBLogicalType *ctx; VALUE alias = Qnil; const char *_alias = StringValuePtr(aname); TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); duckdb_logical_type_set_alias(ctx->logical_type, _alias); if (_alias != NULL) { alias = rb_utf8_str_new_cstr(_alias); } return alias; }
Return the set alias of the logical type.
Source
static VALUE duckdb_logical_type_size(VALUE self) { rubyDuckDBLogicalType *ctx; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); return INT2FIX(duckdb_array_type_array_size(ctx->logical_type)); }
Returns the size of the array column, otherwise 0.
Source
# File lib/duckdb/logical_type.rb, line 20 def type type_id = _type DuckDB::Converter::IntToSym.type_to_sym(type_id) end
returns logical type’s type symbol ‘:unknown` means that the logical type’s type is unknown/unsupported by ruby-duckdb. ‘:invalid` means that the logical type’s type is invalid in duckdb.
require 'duckdb' db = DuckDB::Database.open con = db.connect con.query('CREATE TABLE climates (id INTEGER, temperature DECIMAIL)') users = con.query('SELECT * FROM climates') columns = users.columns columns.second.logical_type.type #=> :decimal
Source
static VALUE duckdb_logical_type_value_type(VALUE self) { rubyDuckDBLogicalType *ctx; duckdb_logical_type value_logical_type; VALUE logical_type = Qnil; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); value_logical_type = duckdb_map_type_value_type(ctx->logical_type); logical_type = rbduckdb_create_logical_type(value_logical_type); return logical_type; }
Returns the value logical type for map type, otherwise nil.
Source
static VALUE duckdb_logical_type_width(VALUE self) { rubyDuckDBLogicalType *ctx; TypedData_Get_Struct(self, rubyDuckDBLogicalType, &logical_type_data_type, ctx); return INT2FIX(duckdb_decimal_width(ctx->logical_type)); }
Returns the width of the decimal column.