Class: Arrow::ListArrayBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/list-array-builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(data_type, values) ⇒ Object



21
22
23
24
# File 'lib/arrow/list-array-builder.rb', line 21

def build(data_type, values)
  builder = new(data_type)
  builder.build(values)
end

Instance Method Details

#append(*values) ⇒ Object

Since:

  • 0.12.0



87
88
89
90
91
92
93
94
# File 'lib/arrow/list-array-builder.rb', line 87

def append(*values)
  if values.empty?
    # For backward compatibility
    append_value
  else
    super
  end
end

#append_valueObject #append_value(list) ⇒ Object

Overloads:

  • #append_valueObject

    Starts appending a list record. You also need to append list value by #value_builder.

  • #append_value(list) ⇒ Object

    Appends a list record including list value.

    Parameters:

    • value (nil, ::Array)

      The list value of the record.

      If this is ‘nil`, the list record is null.

      If this is ‘Array`, it’s the list value of the record.

Since:

  • 0.12.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
# File 'lib/arrow/list-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
    when ::Array
      append_value_raw
      @value_builder ||= value_builder
      @value_builder.append(*value)
    else
      message = "list value must be nil or Array: #{value.inspect}"
      raise ArgumentError, message
    end
  else
    message = "wrong number of arguments (given #{n_args}, expected 0..1)"
    raise ArgumentError, message
  end
end

#append_value_rawObject



27
# File 'lib/arrow/list-array-builder.rb', line 27

alias_method :append_value_raw, :append_value

#append_values(lists, is_valids = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/arrow/list-array-builder.rb', line 70

def append_values(lists, is_valids=nil)
  if is_valids
    is_valids.each_with_index do |is_valid, i|
      if is_valid
        append_value(lists[i])
      else
        append_null
      end
    end
  else
    lists.each do |list|
      append_value(list)
    end
  end
end