Method: Arrow::MapArrayBuilder#append_value

Defined in:
lib/arrow/map-array-builder.rb

#append_valueObject #append_value(value) ⇒ Object

Overloads:

  • #append_valueObject

    Starts appending a map record. You need to append values of map by #key_builder and #item_builder.

  • #append_value(value) ⇒ Object

    Appends a map record including key and item values.

    Parameters:

    • value (nil, #each)

      The map record.

      If this is nil, the map record is null.

      If this is an Object that has #each, each value is a pair of key and item.

Since:

  • 6.0.0



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/arrow/map-array-builder.rb', line 45

def append_value(*args)
  n_args = args.size

  case n_args
  when 0
    append_value_raw
  when 1
    value = args[0]
    case value
    when nil
      append_null
    else
      unless value.respond_to?(:each)
        message = "map value must be nil, Hash or Object that has #each: #{value.inspect}"
        raise ArgumentError, message
      end
      append_value_raw
      @key_builder ||= key_builder
      @item_builder ||= item_builder
      case value
      when Hash
        keys = value.keys
        values = value.values
      else
        keys = []
        values = []
        value.each do |key, item|
          keys << key
          values << item
        end
      end
      @key_builder.append(*keys)
      @item_builder.append(*values)
    end
  else
    message = "wrong number of arguments (given #{n_args}, expected 0..1)"
    raise ArgumentError, message
  end
end