Class: Arrow::StructArrayBuilder
- Inherits:
-
Object
- Object
- Arrow::StructArrayBuilder
- Defined in:
- lib/arrow/struct-array-builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](index_or_name) ⇒ Object
- #append(*values) ⇒ Object
- #append_value(*args) ⇒ Object
- #append_value_raw ⇒ Object
- #append_values(values, is_valids = nil) ⇒ Object
- #find_field_builder(index_or_name) ⇒ Object
Class Method Details
.build(data_type, values) ⇒ Object
21 22 23 24 |
# File 'lib/arrow/struct-array-builder.rb', line 21 def build(data_type, values) builder = new(data_type) builder.build(values) end |
Instance Method Details
#[](index_or_name) ⇒ Object
27 28 29 |
# File 'lib/arrow/struct-array-builder.rb', line 27 def [](index_or_name) find_field_builder(index_or_name) end |
#append(*values) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/arrow/struct-array-builder.rb', line 114 def append(*values) if values.empty? # For backward compatibility append_value_raw else super end end |
#append_value ⇒ Object #append_value(value) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/arrow/struct-array-builder.rb', line 60 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 cached_field_builders.zip(value) do |builder, sub_value| builder.append(sub_value) end when Hash append_value_raw local_name_to_builder = cached_name_to_builder.dup value.each do |name, sub_value| builder = local_name_to_builder.delete(name.to_s) builder.append(sub_value) end local_name_to_builder.each do |_, builder| builder.append_null end else = "struct value must be nil, Array or Hash: #{value.inspect}" raise ArgumentError, end else = "wrong number of arguments (given #{n_args}, expected 0..1)" raise ArgumentError, end end |
#append_value_raw ⇒ Object
42 |
# File 'lib/arrow/struct-array-builder.rb', line 42 alias_method :append_value_raw, :append_value |
#append_values(values, is_valids = nil) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/arrow/struct-array-builder.rb', line 97 def append_values(values, is_valids=nil) if is_valids is_valids.each_with_index do |is_valid, i| if is_valid append_value(values[i]) else append_null end end else values.each do |value| append_value(value) end end end |
#find_field_builder(index_or_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/arrow/struct-array-builder.rb', line 31 def find_field_builder(index_or_name) case index_or_name when String, Symbol name = index_or_name cached_name_to_builder[name.to_s] else index = index_or_name cached_field_builders[index] end end |