Class: ArrowFormat::Org::Apache::Arrow::Flatbuf::Field

Inherits:
FlatBuffers::Table
  • Object
show all
Defined in:
lib/arrow-format/org/apache/arrow/flatbuf/field.rb

Overview


A field represents a named column in a record / row batch or child of a nested type.

Constant Summary collapse

FIELDS =
{
  name: ::FlatBuffers::Field.new(:name, 0, 4, :string, 0),
  nullable?: ::FlatBuffers::Field.new(:nullable?, 1, 6, :bool, 0),
  type_type: ::FlatBuffers::Field.new(:type_type, 2, 8, :utype, 0),
  type: ::FlatBuffers::Field.new(:type, 3, 10, "::ArrowFormat::Org::Apache::Arrow::Flatbuf::Type", 0),
  dictionary: ::FlatBuffers::Field.new(:dictionary, 4, 12, "::ArrowFormat::Org::Apache::Arrow::Flatbuf::DictionaryEncoding", 0),
  children: ::FlatBuffers::Field.new(:children, 5, 14, ["::ArrowFormat::Org::Apache::Arrow::Flatbuf::Field"], 0),
  custom_metadata: ::FlatBuffers::Field.new(:custom_metadata, 6, 16, ["::ArrowFormat::Org::Apache::Arrow::Flatbuf::KeyValue"], 0),
}
Data =
define_data_class

Instance Method Summary collapse

Instance Method Details

#childrenObject

children apply only to nested data types like Struct, List and Union. For primitive types children will have length 0.



35
36
37
38
39
40
41
42
43
# File 'lib/arrow-format/org/apache/arrow/flatbuf/field.rb', line 35

def children
  field_offset = @view.unpack_virtual_offset(14)
  return nil if field_offset.zero?

  element_size = 4
  @view.unpack_vector(field_offset, element_size) do |element_offset|
    @view.unpack_table(::ArrowFormat::Org::Apache::Arrow::Flatbuf::Field, element_offset)
  end
end

#custom_metadataObject

User-defined metadata



46
47
48
49
50
51
52
53
54
# File 'lib/arrow-format/org/apache/arrow/flatbuf/field.rb', line 46

def 
  field_offset = @view.unpack_virtual_offset(16)
  return nil if field_offset.zero?

  element_size = 4
  @view.unpack_vector(field_offset, element_size) do |element_offset|
    @view.unpack_table(::ArrowFormat::Org::Apache::Arrow::Flatbuf::KeyValue, element_offset)
  end
end

#dictionaryObject

Present only if the field is dictionary encoded.



57
58
59
60
61
62
# File 'lib/arrow-format/org/apache/arrow/flatbuf/field.rb', line 57

def dictionary
  field_offset = @view.unpack_virtual_offset(12)
  return nil if field_offset.zero?

  @view.unpack_table(::ArrowFormat::Org::Apache::Arrow::Flatbuf::DictionaryEncoding, field_offset)
end

#nameObject

Name is not required (e.g., in a List)



65
66
67
68
69
70
# File 'lib/arrow-format/org/apache/arrow/flatbuf/field.rb', line 65

def name
  field_offset = @view.unpack_virtual_offset(4)
  return nil if field_offset.zero?

  @view.unpack_string(field_offset)
end

#nullable?Boolean

Whether or not this field can contain nulls. Should be true in general.

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'lib/arrow-format/org/apache/arrow/flatbuf/field.rb', line 73

def nullable?
  field_offset = @view.unpack_virtual_offset(6)
  return false if field_offset.zero?

  @view.unpack_bool(field_offset)
end

#typeObject

This is the type of the decoded value if the field is dictionary encoded.



81
82
83
84
85
86
87
88
# File 'lib/arrow-format/org/apache/arrow/flatbuf/field.rb', line 81

def type
  type = type_type
  return nil if type.nil?

  field_offset = @view.unpack_virtual_offset(10)
  return nil if field_offset.zero?
  @view.unpack_union(type.table_class, field_offset)
end

#type_typeObject



90
91
92
93
94
95
96
97
98
# File 'lib/arrow-format/org/apache/arrow/flatbuf/field.rb', line 90

def type_type
  field_offset = @view.unpack_virtual_offset(8)
  if field_offset.zero?
    enum_value = 0
  else
    enum_value = @view.unpack_utype(field_offset)
  end
  ::ArrowFormat::Org::Apache::Arrow::Flatbuf::Type.try_convert(enum_value) || enum_value
end