Class: ArrowFormat::MapType

Inherits:
VariableSizeListType show all
Defined in:
lib/arrow-format/type.rb

Instance Attribute Summary

Attributes inherited from VariableSizeListType

#child

Instance Method Summary collapse

Constructor Details

#initialize(child, keys_sorted) ⇒ MapType

Returns a new instance of MapType.



912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
# File 'lib/arrow-format/type.rb', line 912

def initialize(child, keys_sorted)
  if child.nullable?
    raise TypeError.new("Map entry field must not be nullable: " +
                        child.inspect)
  end
  type = child.type
  unless type.is_a?(StructType)
    raise TypeError.new("Map entry type must be struct: #{type.inspect}")
  end
  unless type.children.size == 2
    raise TypeError.new("Map entry struct type must have 2 children: " +
                        type.inspect)
  end
  if type.children[0].nullable?
    raise TypeError.new("Map key field must not be nullable: " +
                        type.children[0].inspect)
  end
  super(child)
  @keys_sorted = keys_sorted
end

Instance Method Details

#build_array(size, validity_buffer, offsets_buffer, child) ⇒ Object



945
946
947
# File 'lib/arrow-format/type.rb', line 945

def build_array(size, validity_buffer, offsets_buffer, child)
  MapArray.new(self, size, validity_buffer, offsets_buffer, child)
end

#keys_sorted?Boolean

Returns:

  • (Boolean)


937
938
939
# File 'lib/arrow-format/type.rb', line 937

def keys_sorted?
  @keys_sorted
end

#nameObject



933
934
935
# File 'lib/arrow-format/type.rb', line 933

def name
  "Map"
end

#offset_buffer_typeObject



941
942
943
# File 'lib/arrow-format/type.rb', line 941

def offset_buffer_type
  :s32 # TODO: big endian support
end

#to_flatbuffersObject



954
955
956
# File 'lib/arrow-format/type.rb', line 954

def to_flatbuffers
  FB::Map::Data.new
end

#to_sObject



949
950
951
952
# File 'lib/arrow-format/type.rb', line 949

def to_s
  key, value, = child.type.children
  "#{name}<#{key.type}, #{value.type}>"
end