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
@@ -17,6 +17,8 @@
17
17
 
18
18
  module Arrow
19
19
  class ListDataType
20
+ include ListFieldResolvable
21
+
20
22
  alias_method :initialize_raw, :initialize
21
23
  private :initialize_raw
22
24
 
@@ -75,44 +77,7 @@ module Arrow
75
77
  # @example Create a list data type with data type as Array
76
78
  # Arrow::ListDataType.new([:time32, :milli])
77
79
  def initialize(arg)
78
- data_type = resolve_data_type(arg)
79
- if data_type
80
- field = Field.new(default_field_name, data_type)
81
- else
82
- field = resolve_field(arg)
83
- end
84
- initialize_raw(field)
85
- end
86
-
87
- private
88
- def resolve_data_type(arg)
89
- case arg
90
- when DataType, String, Symbol, ::Array
91
- DataType.resolve(arg)
92
- when Hash
93
- return nil if arg[:name]
94
- return nil unless arg[:type]
95
- DataType.resolve(arg)
96
- else
97
- nil
98
- end
99
- end
100
-
101
- def default_field_name
102
- "item"
103
- end
104
-
105
- def resolve_field(arg)
106
- if arg.is_a?(Hash) and arg.key?(:field)
107
- description = arg
108
- arg = description[:field]
109
- end
110
- if arg.is_a?(Hash)
111
- field_description = arg
112
- Field.new(field_description)
113
- else
114
- arg
115
- end
80
+ initialize_raw(resolve_field(arg))
116
81
  end
117
82
  end
118
83
  end
@@ -15,27 +15,36 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- class DictionaryArrayTest < Test::Unit::TestCase
19
- sub_test_case("instance methods") do
20
- def setup
21
- @values = ["a", "b", "c", "b", "a"]
22
- @string_array = Arrow::StringArray.new(@values)
23
- @array = @string_array.dictionary_encode
18
+ module Arrow
19
+ module ListFieldResolvable
20
+ private
21
+ def resolve_data_type(arg)
22
+ case arg
23
+ when DataType, String, Symbol, ::Array
24
+ DataType.resolve(arg)
25
+ when Hash
26
+ return nil if arg[:name]
27
+ return nil unless arg[:type]
28
+ DataType.resolve(arg)
29
+ else
30
+ nil
31
+ end
24
32
  end
25
33
 
26
- test("#[]") do
27
- assert_equal(@values, @array.to_a)
34
+ def default_field_name
35
+ "item"
28
36
  end
29
37
 
30
- test("#get_value") do
31
- assert_equal([
32
- @values[0],
33
- @values[3],
34
- ],
35
- [
36
- @array.get_value(0),
37
- @array.get_value(3),
38
- ])
38
+ def resolve_field(arg)
39
+ data_type = resolve_data_type(arg)
40
+ if data_type
41
+ Field.new(default_field_name, data_type)
42
+ elsif arg.is_a?(Hash) and arg.key?(:field)
43
+ description = arg
44
+ description[:field]
45
+ else
46
+ arg
47
+ end
39
48
  end
40
49
  end
41
50
  end
@@ -0,0 +1,76 @@
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 ListSliceOptions
20
+ alias_method :return_fixed_size_list_raw, :return_fixed_size_list
21
+ private :return_fixed_size_list_raw
22
+
23
+ RETURN_FIXED_SIZE_GLIB_TO_RUBY = {
24
+ ListSliceReturnFixedSizeList::AUTO => nil,
25
+ ListSliceReturnFixedSizeList::TRUE => true,
26
+ ListSliceReturnFixedSizeList::FALSE => false,
27
+ }.freeze
28
+
29
+ RETURN_FIXED_SIZE_RUBY_TO_GLIB = RETURN_FIXED_SIZE_GLIB_TO_RUBY.invert.freeze
30
+
31
+ # Whether to return a FixedSizeListArray. If true _and_ stop is after a
32
+ # list element’s length, nil values will be appended to create the requested
33
+ # slice size. The default of nil will return the same type which was passed in.
34
+ #
35
+ # @since 23.0.0
36
+ def return_fixed_size_list
37
+ RETURN_FIXED_SIZE_GLIB_TO_RUBY.fetch(
38
+ return_fixed_size_list_raw,
39
+ return_fixed_size_list_raw)
40
+ end
41
+
42
+ alias_method :return_fixed_size_list_raw=, :return_fixed_size_list=
43
+ private :return_fixed_size_list_raw=
44
+
45
+ # Whether to return a FixedSizeListArray. If true _and_ stop is after a
46
+ # list element’s length, nil values will be appended to create the requested
47
+ # slice size. The default of nil will return the same type which was passed in.
48
+ #
49
+ # @since 23.0.0
50
+ def return_fixed_size_list=(return_fixed_size_list)
51
+ self.return_fixed_size_list_raw = RETURN_FIXED_SIZE_RUBY_TO_GLIB.fetch(
52
+ return_fixed_size_list,
53
+ return_fixed_size_list)
54
+ end
55
+
56
+ alias_method :stop_raw, :stop
57
+ private :stop_raw
58
+
59
+ # Optional stop of list slicing. If set to nil, then slice to end.
60
+ #
61
+ # @since 23.0.0
62
+ def stop
63
+ stop_raw == LIST_SLICE_OPTIONS_STOP_UNSPECIFIED ? nil : stop_raw
64
+ end
65
+
66
+ alias_method :stop_raw=, :stop=
67
+ private :stop_raw=
68
+
69
+ # Optional stop of list slicing. If set to nil, then slice to end.
70
+ #
71
+ # @since 23.0.0
72
+ def stop=(stop)
73
+ self.stop_raw = stop.nil? ? LIST_SLICE_OPTIONS_STOP_UNSPECIFIED : stop
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,88 @@
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
+ module ListValuesAppendable
20
+ # @overload append_value
21
+ #
22
+ # Starts appending a list record. You also need to append list
23
+ # value by {#value_builder}.
24
+ #
25
+ # @overload append_value(list)
26
+ #
27
+ # Appends a list record including list value.
28
+ #
29
+ # @param value [nil, ::Array] The list value of the record.
30
+ #
31
+ # If this is `nil`, the list record is null.
32
+ #
33
+ # If this is `Array`, it's the list value of the record.
34
+ #
35
+ # @since 0.12.0
36
+ def append_value(*args)
37
+ n_args = args.size
38
+
39
+ case n_args
40
+ when 0
41
+ super()
42
+ when 1
43
+ value = args[0]
44
+ case value
45
+ when nil
46
+ append_null
47
+ when ::Array
48
+ super()
49
+ return if value.empty?
50
+ @value_builder ||= value_builder
51
+ @value_builder.append(*value)
52
+ else
53
+ message = "list value must be nil or Array: #{value.inspect}"
54
+ raise ArgumentError, message
55
+ end
56
+ else
57
+ message = "wrong number of arguments (given #{n_args}, expected 0..1)"
58
+ raise ArgumentError, message
59
+ end
60
+ end
61
+
62
+ def append_values(lists, is_valids=nil)
63
+ if is_valids
64
+ is_valids.each_with_index do |is_valid, i|
65
+ if is_valid
66
+ append_value(lists[i])
67
+ else
68
+ append_null
69
+ end
70
+ end
71
+ else
72
+ lists.each do |list|
73
+ append_value(list)
74
+ end
75
+ end
76
+ end
77
+
78
+ # @since 0.12.0
79
+ def append(*values)
80
+ if values.empty?
81
+ # For backward compatibility
82
+ append_value
83
+ else
84
+ super
85
+ end
86
+ end
87
+ end
88
+ end
data/lib/arrow/loader.rb CHANGED
@@ -15,7 +15,7 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require "arrow/block-closable"
18
+ require_relative "block-closable"
19
19
 
20
20
  module Arrow
21
21
  class Loader < GObjectIntrospection::Loader
@@ -31,103 +31,11 @@ module Arrow
31
31
  require_extension_library
32
32
  gc_guard
33
33
  self.class.start_callback_dispatch_thread
34
+ @base_module.compute_initialize
34
35
  end
35
36
 
36
37
  def require_libraries
37
- require "arrow/column-containable"
38
- require "arrow/field-containable"
39
- require "arrow/generic-filterable"
40
- require "arrow/generic-takeable"
41
- require "arrow/record-containable"
42
- require "arrow/symbol-values-appendable"
43
-
44
- require "arrow/aggregate-node-options"
45
- require "arrow/aggregation"
46
- require "arrow/array"
47
- require "arrow/array-builder"
48
- require "arrow/bigdecimal-extension"
49
- require "arrow/binary-dictionary-array-builder"
50
- require "arrow/buffer"
51
- require "arrow/chunked-array"
52
- require "arrow/column"
53
- require "arrow/compression-type"
54
- require "arrow/csv-loader"
55
- require "arrow/csv-read-options"
56
- require "arrow/data-type"
57
- require "arrow/date32-array"
58
- require "arrow/date32-array-builder"
59
- require "arrow/date64-array"
60
- require "arrow/date64-array-builder"
61
- require "arrow/datum"
62
- require "arrow/day-time-interval-array-builder"
63
- require "arrow/decimal128"
64
- require "arrow/decimal128-array"
65
- require "arrow/decimal128-array-builder"
66
- require "arrow/decimal128-data-type"
67
- require "arrow/decimal256"
68
- require "arrow/decimal256-array"
69
- require "arrow/decimal256-array-builder"
70
- require "arrow/decimal256-data-type"
71
- require "arrow/dense-union-data-type"
72
- require "arrow/dictionary-array"
73
- require "arrow/dictionary-data-type"
74
- require "arrow/equal-options"
75
- require "arrow/expression"
76
- require "arrow/field"
77
- require "arrow/file-output-stream"
78
- require "arrow/file-system"
79
- require "arrow/fixed-size-binary-array"
80
- require "arrow/fixed-size-binary-array-builder"
81
- require "arrow/function"
82
- require "arrow/group"
83
- require "arrow/list-array-builder"
84
- require "arrow/list-data-type"
85
- require "arrow/map-array"
86
- require "arrow/map-array-builder"
87
- require "arrow/map-data-type"
88
- require "arrow/month-day-nano-interval-array-builder"
89
- require "arrow/null-array"
90
- require "arrow/null-array-builder"
91
- require "arrow/path-extension"
92
- require "arrow/record"
93
- require "arrow/record-batch"
94
- require "arrow/record-batch-builder"
95
- require "arrow/record-batch-file-reader"
96
- require "arrow/record-batch-iterator"
97
- require "arrow/record-batch-reader"
98
- require "arrow/record-batch-stream-reader"
99
- require "arrow/rolling-window"
100
- require "arrow/s3-global-options"
101
- require "arrow/scalar"
102
- require "arrow/schema"
103
- require "arrow/slicer"
104
- require "arrow/sort-key"
105
- require "arrow/sort-options"
106
- require "arrow/source-node-options"
107
- require "arrow/sparse-union-data-type"
108
- require "arrow/string-dictionary-array-builder"
109
- require "arrow/struct-array"
110
- require "arrow/struct-array-builder"
111
- require "arrow/struct-data-type"
112
- require "arrow/table"
113
- require "arrow/table-concatenate-options"
114
- require "arrow/table-formatter"
115
- require "arrow/table-list-formatter"
116
- require "arrow/table-table-formatter"
117
- require "arrow/table-loader"
118
- require "arrow/table-saver"
119
- require "arrow/tensor"
120
- require "arrow/time"
121
- require "arrow/time32-array"
122
- require "arrow/time32-array-builder"
123
- require "arrow/time32-data-type"
124
- require "arrow/time64-array"
125
- require "arrow/time64-array-builder"
126
- require "arrow/time64-data-type"
127
- require "arrow/timestamp-array"
128
- require "arrow/timestamp-array-builder"
129
- require "arrow/timestamp-data-type"
130
- require "arrow/writable"
38
+ require_relative "libraries"
131
39
  end
132
40
 
133
41
  def require_extension_library
@@ -135,7 +43,7 @@ module Arrow
135
43
  end
136
44
 
137
45
  def gc_guard
138
- require "arrow/constructor-arguments-gc-guardable"
46
+ require_relative "constructor-arguments-gc-guardable"
139
47
 
140
48
  [
141
49
  @base_module::BinaryScalar,
@@ -155,6 +63,16 @@ module Arrow
155
63
  end
156
64
  end
157
65
 
66
+ def rubyish_class_name(info)
67
+ name = info.name
68
+ case name
69
+ when "StreamListener"
70
+ "StreamListenerRaw"
71
+ else
72
+ super
73
+ end
74
+ end
75
+
158
76
  def load_object_info(info)
159
77
  super
160
78
 
@@ -193,6 +111,7 @@ module Arrow
193
111
  "Arrow::Date64Array",
194
112
  "Arrow::Decimal128Array",
195
113
  "Arrow::Decimal256Array",
114
+ "Arrow::HalfFloatArray",
196
115
  "Arrow::Time32Array",
197
116
  "Arrow::Time64Array",
198
117
  "Arrow::TimestampArray"
@@ -15,24 +15,24 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- class Decimal128ArrayTest < Test::Unit::TestCase
19
- sub_test_case(".new") do
20
- test("build") do
21
- data_type = Arrow::Decimal128DataType.new(3, 1)
22
- values = [
23
- 10.1,
24
- nil,
25
- "10.1",
26
- BigDecimal("10.1"),
27
- ]
28
- array = Arrow::Decimal128Array.new(data_type, values)
29
- assert_equal([
30
- BigDecimal("10.1"),
31
- nil,
32
- BigDecimal("10.1"),
33
- BigDecimal("10.1"),
34
- ],
35
- array.to_a)
18
+ module Arrow
19
+ class MakeStructOptions
20
+ class << self
21
+ def try_convert(value)
22
+ case value
23
+ when Hash
24
+ options = new
25
+ field_names = value[:field_names] || []
26
+ field_nullability = value[:field_nullability] || []
27
+ field_metadata = value[:field_metadata] || []
28
+ field_names.zip(field_nullability, field_metadata) do |name, nullability, metadata|
29
+ options.add_field(name, nullability, metadata)
30
+ end
31
+ options
32
+ else
33
+ nil
34
+ end
35
+ end
36
36
  end
37
37
  end
38
38
  end
@@ -35,9 +35,16 @@ module Arrow
35
35
  fields = []
36
36
  @values = []
37
37
  @raw_table.each do |name, array|
38
- array = ArrayBuilder.build(array) if array.is_a?(::Array)
39
- fields << Field.new(name.to_s, array.value_data_type)
40
- @values << array
38
+ if array.respond_to?(:to_arrow_chunked_array)
39
+ chunked_array = array.to_arrow_chunked_array
40
+ elsif array.respond_to?(:to_arrow_array)
41
+ chunked_array = ChunkedArray.new([array.to_arrow_array])
42
+ else
43
+ array = array.to_ary if array.respond_to?(:to_ary)
44
+ chunked_array = ChunkedArray.new([ArrayBuilder.build(array)])
45
+ end
46
+ fields << Field.new(name.to_s, chunked_array.value_data_type)
47
+ @values << chunked_array
41
48
  end
42
49
  @schema = Schema.new(fields)
43
50
  end
@@ -0,0 +1,89 @@
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 RawTensorConverter
20
+ attr_reader :data_type
21
+ attr_reader :data
22
+ attr_reader :shape
23
+ attr_reader :strides
24
+ attr_reader :dimension_names
25
+ def initialize(raw_tensor,
26
+ data_type: nil,
27
+ shape: nil,
28
+ strides: nil,
29
+ dimension_names: nil)
30
+ @raw_tensor = raw_tensor
31
+ @data_type = data_type
32
+ @data = nil
33
+ @shape = shape
34
+ @strides = strides
35
+ @dimension_names = dimension_names
36
+ convert
37
+ end
38
+
39
+ private
40
+ def convert
41
+ case @raw_tensor
42
+ when Buffer
43
+ @data = @raw_tensor
44
+ when String
45
+ unless @raw_tensor.encoding == Encoding::ASCII_8BIT
46
+ message = "raw tensor String must be an ASCII-8BIT encoded string: " +
47
+ "#{@raw_tensor.encoding.inspect}"
48
+ raise ArgumentError, message
49
+ end
50
+ @data = Arrow::Buffer.new(@raw_tensor)
51
+ else
52
+ @shape ||= guess_shape
53
+ build_buffer
54
+ unless @strides.nil?
55
+ message = "strides: is only accepted with " +
56
+ "an Arrow::Buffer or String raw tensor: #{@strides.inspect}"
57
+ raise ArgumentError, message
58
+ end
59
+ end
60
+ if @shape.nil?
61
+ raise ArgumentError, "shape: is missing: #{@raw_tensor.inspect}"
62
+ end
63
+ if @data_type.nil?
64
+ raise ArgumentError, "data_type: is missing: #{@raw_tensor.inspect}"
65
+ end
66
+ end
67
+
68
+ def guess_shape
69
+ shape = [@raw_tensor.size]
70
+ target = @raw_tensor[0]
71
+ while target.is_a?(::Array)
72
+ shape << target.size
73
+ target = target[0]
74
+ end
75
+ shape
76
+ end
77
+
78
+ def build_buffer
79
+ if @data_type
80
+ @data_type = DataType.resolve(@data_type)
81
+ array = @data_type.build_array(@raw_tensor.flatten)
82
+ else
83
+ array = Array.new(@raw_tensor.flatten)
84
+ @data_type = array.value_data_type
85
+ end
86
+ @data = array.data_buffer
87
+ end
88
+ end
89
+ end
@@ -20,6 +20,8 @@ module Arrow
20
20
  include Enumerable
21
21
 
22
22
  def each
23
+ return to_enum(__method__) {n_record_batches} unless block_given?
24
+
23
25
  n_record_batches.times do |i|
24
26
  yield(get_record_batch(i))
25
27
  end
@@ -20,6 +20,8 @@ module Arrow
20
20
  include Enumerable
21
21
 
22
22
  def each
23
+ return to_enum(__method__) unless block_given?
24
+
23
25
  loop do
24
26
  record_batch = next_record_batch
25
27
  break if record_batch.nil?
@@ -19,9 +19,11 @@ require "arrow/raw-table-converter"
19
19
 
20
20
  module Arrow
21
21
  class RecordBatch
22
+ include Enumerable
23
+
22
24
  include ColumnContainable
25
+ include InputReferable
23
26
  include RecordContainable
24
- include Enumerable
25
27
 
26
28
  class << self
27
29
  def new(*args)
@@ -56,7 +58,9 @@ module Arrow
56
58
  #
57
59
  # @since 0.12.0
58
60
  def to_table
59
- Table.new(schema, [self])
61
+ table = Table.new(schema, [self])
62
+ share_input(table)
63
+ table
60
64
  end
61
65
 
62
66
  def respond_to_missing?(name, include_private)
@@ -14,7 +14,8 @@
14
14
  # KIND, either express or implied. See the License for the
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
- name,score
18
- alice,10
19
- bob,
20
- chris,-1
17
+
18
+ require "gio2"
19
+
20
+ require_relative "loader"
21
+ Arrow::Loader.load