Class: ArrowFormat::DictionaryArray

Inherits:
Array
  • Object
show all
Defined in:
lib/arrow-format/array.rb

Instance Attribute Summary collapse

Attributes inherited from Array

#offset, #size, #type, #validity_buffer

Instance Method Summary collapse

Methods inherited from Array

#empty?, #n_nulls, #null?, #slice, #valid?

Constructor Details

#initialize(type, size, validity_buffer, indices_buffer, dictionaries) ⇒ DictionaryArray

Returns a new instance of DictionaryArray.



805
806
807
808
809
810
811
812
813
# File 'lib/arrow-format/array.rb', line 805

def initialize(type,
               size,
               validity_buffer,
               indices_buffer,
               dictionaries)
  super(type, size, validity_buffer)
  @indices_buffer = indices_buffer
  @dictionaries = dictionaries
end

Instance Attribute Details

#dictionariesObject (readonly)

Returns the value of attribute dictionaries.



804
805
806
# File 'lib/arrow-format/array.rb', line 804

def dictionaries
  @dictionaries
end

#indices_bufferObject (readonly)

Returns the value of attribute indices_buffer.



803
804
805
# File 'lib/arrow-format/array.rb', line 803

def indices_buffer
  @indices_buffer
end

Instance Method Details

#each_buffer {|@validity_buffer| ... } ⇒ Object

TODO: Slice support

Yields:



816
817
818
819
820
821
# File 'lib/arrow-format/array.rb', line 816

def each_buffer
  return to_enum(__method__) unless block_given?

  yield(@validity_buffer)
  yield(@indices_buffer)
end

#indicesObject



823
824
825
826
827
# File 'lib/arrow-format/array.rb', line 823

def indices
  buffer_type = @type.index_type.buffer_type
  offset = IO::Buffer.size_of(buffer_type) * @offset
  apply_validity(@indices_buffer.values(buffer_type, offset, @size))
end

#to_aObject



829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
# File 'lib/arrow-format/array.rb', line 829

def to_a
  return [] if empty?

  values = []
  @dictionaries.each do |dictionary|
    values.concat(dictionary.array.to_a)
  end
  indices.collect do |index|
    if index.nil?
      nil
    else
      values[index]
    end
  end
end