Class: Arrow::ArrayBuilder

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(values) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/arrow/array-builder.rb', line 23

def build(values)
  if self != ArrayBuilder
    builder = new
    return builder.build(values)
  end

  builder_info = nil
  values.each do |value|
    builder_info = detect_builder_info(value, builder_info)
    break if builder_info and builder_info[:detected]
  end
  if builder_info
    builder = builder_info[:builder]
    builder.build(values)
  else
    Arrow::StringArray.new(values)
  end
end

.buildable?(args) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/arrow/array-builder.rb', line 42

def buildable?(args)
  args.size == method(:build).arity
end

Instance Method Details

#append(*values) ⇒ Object

Since:

  • 0.12.0



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/arrow/array-builder.rb', line 149

def append(*values)
  value_convertable = respond_to?(:convert_to_arrow_value, true)
  start_index = 0
  current_index = 0
  status = :value

  values.each do |value|
    if value.nil?
      if status == :value
        if start_index != current_index
          target_values = values[start_index...current_index]
          if value_convertable
            target_values = target_values.collect do |v|
              convert_to_arrow_value(v)
            end
          end
          append_values(target_values, nil)
          start_index = current_index
        end
        status = :null
      end
    else
      if status == :null
        append_nulls(current_index - start_index)
        start_index = current_index
        status = :value
      end
    end
    current_index += 1
  end
  if start_index != current_index
    if status == :value
      if start_index == 0 and current_index == values.size
        target_values = values
      else
        target_values = values[start_index...current_index]
      end
      if value_convertable
        target_values = target_values.collect do |v|
          convert_to_arrow_value(v)
        end
      end
      append_values(target_values, nil)
    else
      append_nulls(current_index - start_index)
    end
  end
end

#append_nulls(n) ⇒ Object



198
199
200
201
202
# File 'lib/arrow/array-builder.rb', line 198

def append_nulls(n)
  n.times do
    append_null
  end
end

#build(values) ⇒ Object



143
144
145
146
# File 'lib/arrow/array-builder.rb', line 143

def build(values)
  append(*values)
  finish
end