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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/arrow/array-builder.rb', line 23

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

  builder_class = nil
  values.each do |value|
    case value
    when nil
      # Ignore
    when true, false
      return BooleanArray.new(values)
    when String
      return StringArray.new(values)
    when Float
      return DoubleArray.new(values)
    when Integer
      if value < 0
        builder = IntArrayBuilder.new
        return builder.build(values)
      else
        builder_class = UIntArrayBuilder
      end
    when Time
      data_type = TimestampDataType.new(:nano)
      builder = TimestampArrayBuilder.new(data_type)
      return builder.build(values)
    when DateTime
      return Date64Array.new(values)
    when Date
      return Date32Array.new(values)
    else
      return StringArray.new(values)
    end
  end
  if builder_class
    builder_class.new.build(values)
  else
    Arrow::StringArray.new(values)
  end
end

.buildable?(args) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/arrow/array-builder.rb', line 66

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

Instance Method Details

#append(*values) ⇒ Object

Since:

  • 0.12.0



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/arrow/array-builder.rb', line 77

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



126
127
128
129
130
# File 'lib/arrow/array-builder.rb', line 126

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

#build(values) ⇒ Object



71
72
73
74
# File 'lib/arrow/array-builder.rb', line 71

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