Class: Nanoarrow::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoarrow/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj, name: nil, nullable: nil, metadata: nil, fields: nil, **params) ⇒ Schema

Returns a new instance of Schema.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nanoarrow/schema.rb', line 3

def initialize(
  obj,
  name: nil,
  nullable: nil,
  metadata: nil,
  fields: nil,
  **params
)
  if obj.is_a?(Integer)
    @c_schema = Utils.c_schema_from_type_and_params(obj, params)
  else
    if params.any?
      raise ArgumentError, "params are only supported for obj of class Type"
    end
    @c_schema = Utils.c_schema(obj)
  end

  if !name.nil? || !nullable.nil? || !.nil? || !fields.nil?
    @c_schema = @c_schema.modify(name:, nullable:, metadata:, children: clean_fields(fields))
  end

  @c_schema_view = CSchemaView.new(@c_schema)
end

Instance Method Details

#arrow_c_schemaObject



81
82
83
# File 'lib/nanoarrow/schema.rb', line 81

def arrow_c_schema
  @c_schema.arrow_c_schema
end

#byte_widthObject



43
44
45
46
47
# File 'lib/nanoarrow/schema.rb', line 43

def byte_width
  if @c_schema_view.type_id == Type::FIXED_SIZE_BINARY
    @c_schema_view.fixed_size
  end
end

#field(i) ⇒ Object



69
70
71
# File 'lib/nanoarrow/schema.rb', line 69

def field(i)
  Schema.new(@c_schema.child(i).deep_dup)
end

#fieldsObject



73
74
75
# File 'lib/nanoarrow/schema.rb', line 73

def fields
  n_fields.times.map { |i| field(i) }
end

#inspectObject



77
78
79
# File 'lib/nanoarrow/schema.rb', line 77

def inspect
  @c_schema.to_s
end

#metadataObject



39
40
41
# File 'lib/nanoarrow/schema.rb', line 39

def 
  @c_schema.
end

#n_fieldsObject



65
66
67
# File 'lib/nanoarrow/schema.rb', line 65

def n_fields
  @c_schema.n_children
end

#nameObject



31
32
33
# File 'lib/nanoarrow/schema.rb', line 31

def name
  @c_schema.name
end

#nullableObject



35
36
37
# File 'lib/nanoarrow/schema.rb', line 35

def nullable
  @c_schema_view.nullable
end

#precisionObject



57
58
59
# File 'lib/nanoarrow/schema.rb', line 57

def precision
  @c_schema_view.decimal_precision
end

#scaleObject



61
62
63
# File 'lib/nanoarrow/schema.rb', line 61

def scale
  @c_schema_view.decimal_scale
end

#timezoneObject



53
54
55
# File 'lib/nanoarrow/schema.rb', line 53

def timezone
  @c_schema_view.timezone
end

#typeObject



27
28
29
# File 'lib/nanoarrow/schema.rb', line 27

def type
  @c_schema_view.type
end

#unitObject



49
50
51
# File 'lib/nanoarrow/schema.rb', line 49

def unit
  @c_schema_view.time_unit
end