Class: Parqueteur::Types::MapType

Inherits:
Parqueteur::Type show all
Defined in:
lib/parqueteur/types/map_type.rb

Instance Attribute Summary

Attributes inherited from Parqueteur::Type

#arrow_type, #options

Instance Method Summary collapse

Methods inherited from Parqueteur::Type

#initialize, #resolve

Constructor Details

This class inherits a constructor from Parqueteur::Type

Instance Method Details

#arrow_type_builderObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/parqueteur/types/map_type.rb', line 21

def arrow_type_builder
  map_value = options.fetch(:value)

  Arrow::MapDataType.new(
    resolve(options.fetch(:key)).arrow_type,
    if map_value.is_a?(Hash)
      resolve(map_value.fetch(:type), map_value).arrow_type
    else
      resolve(map_value).arrow_type
    end
  )
end

#build_value_array(values) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/parqueteur/types/map_type.rb', line 6

def build_value_array(values)
  builder = Arrow::MapArrayBuilder.new(arrow_type)
  values.each do |entry|
    builder.append_value
    next if entry.nil?

    entry.each do |k, v|
      builder.key_builder.append(k)
      builder.item_builder.append(v)
    end
  end

  builder.finish
end