red-arrow 8.0.0 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -7
  3. data/ext/arrow/arrow.cpp +67 -0
  4. data/ext/arrow/converters.cpp +10 -0
  5. data/ext/arrow/converters.hpp +310 -46
  6. data/ext/arrow/extconf.rb +41 -22
  7. data/ext/arrow/raw-records.cpp +165 -2
  8. data/ext/arrow/red-arrow.hpp +2 -0
  9. data/ext/arrow/values.cpp +6 -2
  10. data/lib/arrow/array-builder.rb +89 -14
  11. data/{test/test-time32-data-type.rb → lib/arrow/array-computable.rb} +24 -16
  12. data/{test/test-buffer.rb → lib/arrow/array-statistics.rb} +19 -24
  13. data/lib/arrow/array.rb +40 -4
  14. data/lib/arrow/chunked-array.rb +56 -1
  15. data/lib/arrow/column-containable.rb +9 -0
  16. data/lib/arrow/column.rb +49 -4
  17. data/{test/test-tensor.rb → lib/arrow/csv-write-options.rb} +28 -31
  18. data/lib/arrow/data-type.rb +17 -3
  19. data/lib/arrow/decimal128-array-builder.rb +16 -6
  20. data/lib/arrow/decimal128.rb +14 -0
  21. data/lib/arrow/decimal256-array-builder.rb +16 -6
  22. data/lib/arrow/decimal256.rb +14 -0
  23. data/{test/test-float-scalar.rb → lib/arrow/dense-union-array-builder.rb} +27 -24
  24. data/{test/test-boolean-scalar.rb → lib/arrow/dense-union-array.rb} +7 -7
  25. data/lib/arrow/duration-array-builder.rb +27 -0
  26. data/lib/arrow/duration-array.rb +24 -0
  27. data/lib/arrow/duration-data-type.rb +32 -0
  28. data/lib/arrow/expression.rb +6 -2
  29. data/lib/arrow/field-containable.rb +1 -1
  30. data/lib/arrow/field.rb +44 -3
  31. data/lib/arrow/fixed-size-list-array-builder.rb +29 -0
  32. data/lib/arrow/fixed-size-list-data-type.rb +118 -0
  33. data/lib/arrow/function.rb +0 -1
  34. data/lib/arrow/half-float-array-builder.rb +32 -0
  35. data/lib/arrow/half-float-array.rb +24 -0
  36. data/lib/arrow/half-float.rb +118 -0
  37. data/{test/helper/fixture.rb → lib/arrow/input-referable.rb} +7 -6
  38. data/lib/arrow/jruby/array-builder.rb +114 -0
  39. data/lib/arrow/jruby/array.rb +109 -0
  40. data/lib/arrow/jruby/chunked-array.rb +36 -0
  41. data/lib/arrow/jruby/compression-type.rb +26 -0
  42. data/lib/arrow/jruby/csv-read-options.rb +32 -0
  43. data/{test/test-map-data-type.rb → lib/arrow/jruby/data-type.rb} +24 -12
  44. data/lib/arrow/jruby/decimal128.rb +28 -0
  45. data/lib/arrow/jruby/decimal256.rb +28 -0
  46. data/{test/fixture/float-integer.csv → lib/arrow/jruby/error.rb} +7 -4
  47. data/lib/arrow/jruby/file-system.rb +24 -0
  48. data/{test/test-null-array.rb → lib/arrow/jruby/function.rb} +5 -4
  49. data/lib/arrow/jruby/record-batch-iterator.rb +24 -0
  50. data/{test/fixture/null-with-double-quote.csv → lib/arrow/jruby/record-batch.rb} +8 -4
  51. data/{test/fixture/integer-float.csv → lib/arrow/jruby/sort-key.rb} +8 -4
  52. data/lib/arrow/jruby/sort-options.rb +24 -0
  53. data/lib/arrow/jruby/stream-listener-raw.rb +25 -0
  54. data/{test/test-rolling-window.rb → lib/arrow/jruby/table.rb} +19 -19
  55. data/lib/arrow/jruby/writable.rb +24 -0
  56. data/lib/arrow/jruby.rb +52 -0
  57. data/{test/test-date32-array.rb → lib/arrow/large-list-array-builder.rb} +10 -5
  58. data/lib/arrow/large-list-data-type.rb +83 -0
  59. data/lib/arrow/libraries.rb +140 -0
  60. data/lib/arrow/list-array-builder.rb +1 -68
  61. data/lib/arrow/list-data-type.rb +3 -38
  62. data/{test/test-dictionary-array.rb → lib/arrow/list-field-resolvable.rb} +26 -17
  63. data/lib/arrow/list-slice-options.rb +76 -0
  64. data/lib/arrow/list-values-appendable.rb +88 -0
  65. data/lib/arrow/loader.rb +15 -96
  66. data/{test/test-decimal128-array.rb → lib/arrow/make-struct-options.rb} +18 -18
  67. data/lib/arrow/raw-table-converter.rb +10 -3
  68. data/lib/arrow/raw-tensor-converter.rb +89 -0
  69. data/lib/arrow/record-batch-file-reader.rb +2 -0
  70. data/lib/arrow/record-batch-stream-reader.rb +2 -0
  71. data/lib/arrow/record-batch.rb +6 -2
  72. data/{test/fixture/null-without-double-quote.csv → lib/arrow/ruby.rb} +5 -4
  73. data/lib/arrow/scalar.rb +67 -0
  74. data/lib/arrow/slicer.rb +61 -0
  75. data/lib/arrow/sort-key.rb +3 -3
  76. data/lib/arrow/sparse-union-array-builder.rb +56 -0
  77. data/lib/arrow/sparse-union-array.rb +26 -0
  78. data/lib/arrow/stream-decoder.rb +29 -0
  79. data/{test/test-decimal256-data-type.rb → lib/arrow/stream-listener.rb} +25 -9
  80. data/lib/arrow/string-array-builder.rb +30 -0
  81. data/lib/arrow/struct-array-builder.rb +0 -5
  82. data/lib/arrow/table-formatter.rb +38 -8
  83. data/lib/arrow/table-list-formatter.rb +3 -3
  84. data/lib/arrow/table-loader.rb +11 -5
  85. data/lib/arrow/table-saver.rb +4 -3
  86. data/lib/arrow/table-table-formatter.rb +7 -0
  87. data/lib/arrow/table.rb +180 -33
  88. data/lib/arrow/tensor.rb +144 -0
  89. data/lib/arrow/time-unit.rb +31 -0
  90. data/lib/arrow/time32-array-builder.rb +2 -14
  91. data/lib/arrow/time32-data-type.rb +9 -38
  92. data/lib/arrow/time64-array-builder.rb +2 -14
  93. data/lib/arrow/time64-data-type.rb +9 -38
  94. data/lib/arrow/timestamp-array-builder.rb +3 -15
  95. data/lib/arrow/timestamp-data-type.rb +9 -34
  96. data/{test/test-date64-array.rb → lib/arrow/timestamp-parser.rb} +14 -6
  97. data/lib/arrow/union-array-builder.rb +59 -0
  98. data/lib/arrow/union-array.rb +26 -0
  99. data/lib/arrow/version.rb +1 -1
  100. data/lib/arrow.rb +2 -7
  101. data/red-arrow.gemspec +74 -11
  102. metadata +85 -210
  103. data/test/fixture/TestOrcFile.test1.orc +0 -0
  104. data/test/fixture/with-header-float.csv +0 -20
  105. data/test/fixture/with-header.csv +0 -20
  106. data/test/fixture/without-header-float.csv +0 -19
  107. data/test/fixture/without-header.csv +0 -19
  108. data/test/helper/omittable.rb +0 -36
  109. data/test/helper.rb +0 -30
  110. data/test/raw-records/test-basic-arrays.rb +0 -395
  111. data/test/raw-records/test-dense-union-array.rb +0 -521
  112. data/test/raw-records/test-list-array.rb +0 -610
  113. data/test/raw-records/test-map-array.rb +0 -478
  114. data/test/raw-records/test-multiple-columns.rb +0 -65
  115. data/test/raw-records/test-sparse-union-array.rb +0 -511
  116. data/test/raw-records/test-struct-array.rb +0 -515
  117. data/test/raw-records/test-table.rb +0 -47
  118. data/test/run-test.rb +0 -71
  119. data/test/test-array-builder.rb +0 -136
  120. data/test/test-array.rb +0 -325
  121. data/test/test-bigdecimal.rb +0 -40
  122. data/test/test-binary-dictionary-array-builder.rb +0 -103
  123. data/test/test-chunked-array.rb +0 -183
  124. data/test/test-column.rb +0 -92
  125. data/test/test-csv-loader.rb +0 -250
  126. data/test/test-data-type.rb +0 -83
  127. data/test/test-decimal128-array-builder.rb +0 -112
  128. data/test/test-decimal128-data-type.rb +0 -31
  129. data/test/test-decimal128.rb +0 -102
  130. data/test/test-decimal256-array-builder.rb +0 -112
  131. data/test/test-decimal256-array.rb +0 -38
  132. data/test/test-decimal256.rb +0 -102
  133. data/test/test-dense-union-data-type.rb +0 -41
  134. data/test/test-dictionary-data-type.rb +0 -40
  135. data/test/test-expression.rb +0 -40
  136. data/test/test-feather.rb +0 -49
  137. data/test/test-field.rb +0 -91
  138. data/test/test-file-output-stream.rb +0 -54
  139. data/test/test-fixed-size-binary-array-builder.rb +0 -92
  140. data/test/test-fixed-size-binary-array.rb +0 -36
  141. data/test/test-function.rb +0 -210
  142. data/test/test-group.rb +0 -180
  143. data/test/test-list-array-builder.rb +0 -79
  144. data/test/test-list-array.rb +0 -32
  145. data/test/test-list-data-type.rb +0 -69
  146. data/test/test-map-array-builder.rb +0 -110
  147. data/test/test-map-array.rb +0 -33
  148. data/test/test-memory-view.rb +0 -434
  149. data/test/test-orc.rb +0 -173
  150. data/test/test-record-batch-builder.rb +0 -125
  151. data/test/test-record-batch-file-reader.rb +0 -115
  152. data/test/test-record-batch-iterator.rb +0 -37
  153. data/test/test-record-batch-reader.rb +0 -46
  154. data/test/test-record-batch.rb +0 -182
  155. data/test/test-schema.rb +0 -134
  156. data/test/test-slicer.rb +0 -487
  157. data/test/test-sort-indices.rb +0 -40
  158. data/test/test-sort-key.rb +0 -81
  159. data/test/test-sort-options.rb +0 -58
  160. data/test/test-sparse-union-data-type.rb +0 -41
  161. data/test/test-string-dictionary-array-builder.rb +0 -103
  162. data/test/test-struct-array-builder.rb +0 -184
  163. data/test/test-struct-array.rb +0 -94
  164. data/test/test-struct-data-type.rb +0 -112
  165. data/test/test-table.rb +0 -1123
  166. data/test/test-time.rb +0 -288
  167. data/test/test-time32-array.rb +0 -81
  168. data/test/test-time64-array.rb +0 -81
  169. data/test/test-time64-data-type.rb +0 -42
  170. data/test/test-timestamp-array.rb +0 -45
  171. data/test/test-timestamp-data-type.rb +0 -42
  172. data/test/values/test-basic-arrays.rb +0 -325
  173. data/test/values/test-dense-union-array.rb +0 -509
  174. data/test/values/test-dictionary-array.rb +0 -295
  175. data/test/values/test-list-array.rb +0 -571
  176. data/test/values/test-map-array.rb +0 -466
  177. data/test/values/test-sparse-union-array.rb +0 -500
  178. data/test/values/test-struct-array.rb +0 -512
@@ -0,0 +1,118 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class FixedSizeListDataType
20
+ include ListFieldResolvable
21
+
22
+ alias_method :initialize_raw, :initialize
23
+ private :initialize_raw
24
+
25
+ # Creates a new {Arrow::FixedSizeListDataType}.
26
+ #
27
+ # @overload initialize(field, size)
28
+ #
29
+ # @param field [Arrow::Field, Hash] The field of the fixed size
30
+ # list data type. You can also specify field description by
31
+ # `Hash`.
32
+ #
33
+ # See {Arrow::Field.new} how to specify field description.
34
+ #
35
+ # @param size [Integer] The number of values in each element.
36
+ #
37
+ # @example Create a fixed size list data type with {Arrow::Field}
38
+ # visible_field = Arrow::Field.new("visible", :boolean)
39
+ # size = 2
40
+ # Arrow::FixedSizeListDataType.new(visible_field, size)
41
+ #
42
+ # @example Create a list data type with field description
43
+ # description = {name: "visible", type: :boolean}
44
+ # size = 2
45
+ # Arrow::FixedSizeListDataType.new(description, size)
46
+ #
47
+ # @overload initialize(description)
48
+ #
49
+ # @param description [Hash] The description of the fixed size
50
+ # list data type. It must have `:field` value and `:size`
51
+ # value.
52
+ #
53
+ # @option description [Arrow::Field, Hash] :field The field of
54
+ # the list data type. You can also specify field description
55
+ # by `Hash`.
56
+ #
57
+ # See {Arrow::Field.new} how to specify field description.
58
+ #
59
+ # @option description [Integer] :size The number of values of
60
+ # each element of the fixed size list data type.
61
+ #
62
+ # @example Create a fixed size list data type with {Arrow::Field}
63
+ # visible_field = Arrow::Field.new("visible", :boolean)
64
+ # Arrow::FixedSizeListDataType.new(field: visible_field, size: 2)
65
+ #
66
+ # @example Create a fixed size list data type with field description
67
+ # Arrow::FixedSizeListDataType.new(field: {
68
+ # name: "visible",
69
+ # type: :boolean,
70
+ # },
71
+ # size: 2)
72
+ #
73
+ # @overload initialize(data_type, size)
74
+ #
75
+ # @param data_type [Arrow::DataType, String, Symbol,
76
+ # ::Array<String>, ::Array<Symbol>, Hash] The element data
77
+ # type of the fixed size list data type. A field is created
78
+ # with the default name `"item"` from the data type
79
+ # automatically.
80
+ #
81
+ # See {Arrow::DataType.resolve} how to specify data type.
82
+ #
83
+ # @param size [Integer] The number of values in each
84
+ # element.
85
+ #
86
+ # @example Create a fixed size list data type with {Arrow::DataType}
87
+ # size = 2
88
+ # Arrow::FixedSizeListDataType.new(Arrow::BooleanDataType.new,
89
+ # size)
90
+ #
91
+ # @example Create a fixed size list data type with data type name as String
92
+ # size = 2
93
+ # Arrow::FixedSizeListDataType.new("boolean", size)
94
+ #
95
+ # @example Create a fixed size list data type with data type name as Symbol
96
+ # size = 2
97
+ # Arrow::FixedSizeListDataType.new(:boolean, size)
98
+ #
99
+ # @example Create a fixed size list data type with data type as Array
100
+ # size = 2
101
+ # Arrow::FixedSizeListDataType.new([:time32, :milli], size)
102
+ def initialize(*args)
103
+ n_args = args.size
104
+ case n_args
105
+ when 1
106
+ description = args[0]
107
+ size = description.delete(:size)
108
+ initialize_raw(resolve_field(description), size)
109
+ when 2
110
+ field, size = args
111
+ initialize_raw(resolve_field(field), size)
112
+ else
113
+ message = "wrong number of arguments (given #{n_args}, expected 1..2)"
114
+ raise ArgumentError, message
115
+ end
116
+ end
117
+ end
118
+ end
@@ -24,7 +24,6 @@ module Arrow
24
24
  end
25
25
  alias_method :call, :execute
26
26
 
27
- private
28
27
  def resolve_options(options)
29
28
  return nil if options.nil?
30
29
  return options if options.is_a?(FunctionOptions)
@@ -0,0 +1,32 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class HalfFloatArrayBuilder
20
+ private
21
+ def convert_to_arrow_value(value)
22
+ case value
23
+ when Float
24
+ HalfFloat.new(value).to_uint16
25
+ when HalfFloat
26
+ value.to_uint16
27
+ else
28
+ value
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class HalfFloatArray
20
+ def get_value(i)
21
+ HalfFloat.new(get_raw_value(i)).to_f
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,118 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class HalfFloat
20
+ MAX = 65504
21
+ MIN = -65504
22
+ EXPONENT_N_BITS = 5
23
+ EXPONENT_MASK = (2 ** EXPONENT_N_BITS) - 1
24
+ EXPONENT_BIAS = 15
25
+ FRACTION_N_BITS = 10
26
+ FRACTION_MASK = (2 ** FRACTION_N_BITS) - 1
27
+ FRACTION_DENOMINATOR = 2.0 ** FRACTION_N_BITS
28
+
29
+ attr_reader :sign
30
+ attr_reader :exponent
31
+ attr_reader :fraction
32
+ def initialize(*args)
33
+ n_args = args.size
34
+ case n_args
35
+ when 1
36
+ if args[0].is_a?(Float)
37
+ @sign, @exponent, @fraction = deconstruct_float(args[0])
38
+ else
39
+ @sign, @exponent, @fraction = deconstruct_uint16(args[0])
40
+ end
41
+ when 3
42
+ @sign, @exponent, @fraction = *args
43
+ else
44
+ message = "wrong number of arguments (given #{n_args}, expected 1 or 3)"
45
+ raise ArgumentError, message
46
+ end
47
+ end
48
+
49
+ def to_f
50
+ if @exponent == EXPONENT_MASK
51
+ if @sign.zero?
52
+ Float::INFINITY
53
+ else
54
+ -Float::INFINITY
55
+ end
56
+ else
57
+ if @exponent.zero?
58
+ implicit_fraction = 0
59
+ else
60
+ implicit_fraction = 1
61
+ end
62
+ ((-1) ** @sign) *
63
+ (2 ** (@exponent - EXPONENT_BIAS)) *
64
+ (implicit_fraction + @fraction / FRACTION_DENOMINATOR)
65
+ end
66
+ end
67
+
68
+ def to_uint16
69
+ (@sign << (EXPONENT_N_BITS + FRACTION_N_BITS)) ^
70
+ (@exponent << FRACTION_N_BITS) ^
71
+ @fraction
72
+ end
73
+
74
+ def pack
75
+ [to_uint16].pack("S")
76
+ end
77
+
78
+ private
79
+ def deconstruct_float(float)
80
+ if float > MAX
81
+ float = Float::INFINITY
82
+ elsif float < MIN
83
+ float = -Float::INFINITY
84
+ end
85
+ is_infinite = float.infinite?
86
+ if is_infinite
87
+ sign = (is_infinite == 1) ? 0 : 1
88
+ exponent = EXPONENT_MASK
89
+ fraction = 0
90
+ elsif float.zero?
91
+ sign = 0
92
+ exponent = 0
93
+ fraction = 0
94
+ else
95
+ sign = (float.positive? ? 0 : 1)
96
+ float_abs = float.abs
97
+ 1.upto(EXPONENT_MASK) do |e|
98
+ next_exponent_value = 2 ** (e + 1 - EXPONENT_BIAS)
99
+ next if float_abs > next_exponent_value
100
+ exponent = e
101
+ exponent_value = 2 ** (e - EXPONENT_BIAS)
102
+ fraction =
103
+ ((float_abs / exponent_value - 1) * FRACTION_DENOMINATOR).round
104
+ break
105
+ end
106
+ end
107
+ [sign, exponent, fraction]
108
+ end
109
+
110
+ def deconstruct_uint16(uint16)
111
+ # | sign (1 bit) | exponent (5 bit) | fraction (10 bit) |
112
+ sign = (uint16 >> (EXPONENT_N_BITS + FRACTION_N_BITS))
113
+ exponent = ((uint16 >> FRACTION_N_BITS) & EXPONENT_MASK)
114
+ fraction = (uint16 & FRACTION_MASK)
115
+ [sign, exponent, fraction]
116
+ end
117
+ end
118
+ end
@@ -15,14 +15,15 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- module Helper
19
- module Fixture
20
- def fixture_dir
21
- Pathname.new(__dir__).join("..", "fixture").expand_path
18
+ module Arrow
19
+ module InputReferable
20
+ def refer_input(input)
21
+ @input = input
22
22
  end
23
23
 
24
- def fixture_path(*components)
25
- fixture_dir.join(*components)
24
+ def share_input(other)
25
+ return unless defined?(@input)
26
+ other.refer_input(@input)
26
27
  end
27
28
  end
28
29
  end
@@ -0,0 +1,114 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require_relative "array"
19
+
20
+ module Arrow
21
+ module ArrayBuildable
22
+ ValueVector = org.apache.arrow.vector.ValueVector
23
+ def buildable?(args)
24
+ return false if args.size == 1 and args.first.is_a?(ValueVector)
25
+ super
26
+ end
27
+ end
28
+
29
+ class ArrayBuilder
30
+ class << self
31
+ prepend ArrayBuildable
32
+ end
33
+
34
+ def initialize
35
+ @vector = self.class::Array::Vector.new("", Arrow.allocator)
36
+ @vector.allocate_new
37
+ @index = 0
38
+ end
39
+
40
+ def append_value(value)
41
+ @vector.set(@index, value)
42
+ @index += 1
43
+ end
44
+
45
+ def append_values(values, is_valids=nil)
46
+ if is_valids
47
+ values.zip(is_valids) do |value, is_valid|
48
+ if is_valid
49
+ @vector.set(@index, value)
50
+ else
51
+ @vector.set_null(@index)
52
+ end
53
+ @index += 1
54
+ end
55
+ else
56
+ values.each do |value|
57
+ @vector.set(@index, value)
58
+ @index += 1
59
+ end
60
+ end
61
+ end
62
+
63
+ def append_nulls(n)
64
+ n.times do
65
+ @vector.set_null(@index)
66
+ @index += 1
67
+ end
68
+ end
69
+
70
+ def finish
71
+ @vector.set_value_count(@index)
72
+ vector, @vector = @vector, nil
73
+ self.class::Array.new(vector)
74
+ end
75
+ end
76
+
77
+ class Int8ArrayBuilder < ArrayBuilder
78
+ Array = Int8Array
79
+ end
80
+
81
+ class Int32ArrayBuilder < ArrayBuilder
82
+ Array = Int32Array
83
+ end
84
+
85
+ class FixedSizeBinaryArrayBuilder < ArrayBuilder
86
+ end
87
+
88
+ class Decimal128ArrayBuilder < FixedSizeBinaryArrayBuilder
89
+ end
90
+
91
+ class Decimal256ArrayBuilder < FixedSizeBinaryArrayBuilder
92
+ end
93
+
94
+ class ListArrayBuilder < ArrayBuilder
95
+ end
96
+
97
+ class MapArrayBuilder < ArrayBuilder
98
+ end
99
+
100
+ class StructArrayBuilder < ArrayBuilder
101
+ end
102
+
103
+ class UnionArrayBuilder < ArrayBuilder
104
+ def append_child(child, filed_name)
105
+ raise NotImplementedError
106
+ end
107
+ end
108
+
109
+ class DenseUnionArrayBuilder < UnionArrayBuilder
110
+ end
111
+
112
+ class SparseUnionArrayBuilder < UnionArrayBuilder
113
+ end
114
+ end
@@ -0,0 +1,109 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require_relative "data-type"
19
+
20
+ module Arrow
21
+ class Array
22
+ VectorAppender = org.apache.arrow.vector.util.VectorAppender
23
+ VectorEqualsVisitor = org.apache.arrow.vector.compare.VectorEqualsVisitor
24
+
25
+ attr_reader :vector
26
+
27
+ def initialize(vector)
28
+ @vector = vector
29
+ end
30
+
31
+ def ==(other_array)
32
+ return false unless other_array.is_a?(self.class)
33
+ VectorEqualsVisitor.vector_equals(@vector, other_array.vector)
34
+ end
35
+
36
+ def null?(i)
37
+ @vector.null?(i)
38
+ end
39
+
40
+ def get_value(i)
41
+ @vector.get_object(i)
42
+ end
43
+
44
+ def to_s
45
+ @vector.to_s
46
+ end
47
+
48
+ def inspect
49
+ super.sub(/>\z/) do
50
+ " #{to_s}>"
51
+ end
52
+ end
53
+
54
+ def close
55
+ @vector.close
56
+ end
57
+
58
+ def length
59
+ @vector.value_count
60
+ end
61
+
62
+ def value_data_type
63
+ self.class::ValueDataType.new
64
+ end
65
+
66
+ def values
67
+ each.to_a
68
+ end
69
+
70
+ def cast(other_value_data_type)
71
+ other_value_data_type.build_array(to_a)
72
+ end
73
+
74
+ def is_in(values)
75
+ raise NotImplementedError
76
+ end
77
+
78
+ def concatenate(other_arrays)
79
+ total_size = length + other_arrays.sum(&:length)
80
+ vector = self.class::Vector.new("", Arrow.allocator)
81
+ vector.allocate_new(total_size)
82
+ appender = VectorAppender.new(vector)
83
+ @vector.accept(appender, nil)
84
+ other_arrays.each do |other_array|
85
+ other_array.vector.accept(appender, nil)
86
+ end
87
+ self.class.new(vector)
88
+ end
89
+ end
90
+
91
+ class Int8Array < Array
92
+ Vector = org.apache.arrow.vector.SmallIntVector
93
+ ValueDataType = Int8DataType
94
+ end
95
+
96
+ class Int32Array < Array
97
+ Vector = org.apache.arrow.vector.IntVector
98
+ ValueDataType = Int32DataType
99
+ end
100
+
101
+ class FixedSizeBinaryArray < Array
102
+ end
103
+
104
+ class StructArray < Array
105
+ def fields
106
+ raise NotImplementedError
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,36 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class ChunkedArray
20
+ def initialize(arrays)
21
+ @arrays = arrays
22
+ end
23
+
24
+ def n_rows
25
+ @arrays.sum(&:size)
26
+ end
27
+
28
+ def chunks
29
+ @arrays
30
+ end
31
+
32
+ def get_chunk(i)
33
+ @arrays[i]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,26 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class CompressionType
20
+ class << self
21
+ def values
22
+ []
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class CSVReadOptions
20
+ def add_column_type(name, type)
21
+ raise NotImplementedError
22
+ end
23
+
24
+ def delimiter
25
+ raise NotImplementedError
26
+ end
27
+
28
+ def delimiter=(delimiter)
29
+ raise NotImplementedError
30
+ end
31
+ end
32
+ end
@@ -15,22 +15,34 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- class MapDataTypeTest < Test::Unit::TestCase
19
- sub_test_case(".new") do
20
- def setup
21
- @key = :int8
22
- @item = :string
18
+ module Arrow
19
+ class DataType
20
+ def initialize
21
+ @minor_type = self.class::MinorType
23
22
  end
23
+ end
24
+
25
+ class Int8DataType < DataType
26
+ MinorType = org.apache.arrow.vector.types.Types::MinorType::SMALLINT
27
+ end
24
28
 
25
- test("ordered arguments") do
26
- assert_equal("map<int8, string>",
27
- Arrow::MapDataType.new(@key, @item).to_s)
29
+ class Int32DataType < DataType
30
+ MinorType = org.apache.arrow.vector.types.Types::MinorType::INT
31
+ end
32
+
33
+ class Decimal128DataType < DataType
34
+ class << self
35
+ def max_precision
36
+ 38
37
+ end
28
38
  end
39
+ end
29
40
 
30
- test("description") do
31
- assert_equal("map<int8, string>",
32
- Arrow::MapDataType.new(key: @key,
33
- item: @item).to_s)
41
+ class Decimal256DataType < DataType
42
+ class << self
43
+ def max_precision
44
+ 76
45
+ end
34
46
  end
35
47
  end
36
48
  end