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
@@ -1,125 +0,0 @@
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
- class RecordBatchBuilderTest < Test::Unit::TestCase
19
- sub_test_case(".new") do
20
- test("Schema") do
21
- schema = Arrow::Schema.new(visible: :boolean,
22
- count: :uint32)
23
- builder = Arrow::RecordBatchBuilder.new(schema)
24
- assert_equal(schema,
25
- builder.schema)
26
- end
27
-
28
- test("Hash") do
29
- builder = Arrow::RecordBatchBuilder.new(visible: :boolean,
30
- count: :uint32)
31
- assert_equal(Arrow::Schema.new(visible: :boolean,
32
- count: :uint32),
33
- builder.schema)
34
- end
35
- end
36
-
37
- sub_test_case("instance methods") do
38
- def setup
39
- @schema = Arrow::Schema.new(visible: :boolean,
40
- count: :uint32)
41
- @builder = Arrow::RecordBatchBuilder.new(@schema)
42
- end
43
-
44
- sub_test_case("#[]") do
45
- test("String") do
46
- assert_equal(Arrow::BooleanDataType.new,
47
- @builder["visible"].value_data_type)
48
- end
49
-
50
- test("Symbol") do
51
- assert_equal(Arrow::BooleanDataType.new,
52
- @builder[:visible].value_data_type)
53
- end
54
-
55
- test("Integer") do
56
- assert_equal(Arrow::UInt32DataType.new,
57
- @builder[1].value_data_type)
58
- end
59
- end
60
-
61
- test("#append") do
62
- records = [
63
- {visible: true, count: 1},
64
- ]
65
- columns = {
66
- visible: [false],
67
- count: [2],
68
- }
69
- arrays = [
70
- Arrow::BooleanArray.new([true, false]),
71
- Arrow::UInt32Array.new([1, 2]),
72
- ]
73
- @builder.append(records, columns)
74
- assert_equal(Arrow::RecordBatch.new(@schema,
75
- arrays[0].length,
76
- arrays),
77
- @builder.flush)
78
- end
79
-
80
- test("#append_records") do
81
- records = [
82
- {visible: true, count: 1},
83
- {visible: true, count: 2, garbage: "garbage"},
84
- {visible: true},
85
- [false, 4],
86
- nil,
87
- [true],
88
- ]
89
- arrays = [
90
- Arrow::BooleanArray.new([true, true, true, false, nil, true]),
91
- Arrow::UInt32Array.new([1, 2, nil, 4, nil, nil]),
92
- ]
93
- @builder.append_records(records)
94
- assert_equal(Arrow::RecordBatch.new(@schema,
95
- arrays[0].length,
96
- arrays),
97
- @builder.flush)
98
- end
99
-
100
- test("#append_columns") do
101
- columns = {
102
- visible: [true, true, true, false, nil, true],
103
- count: [1, 2, nil, 4, nil, nil],
104
- }
105
- arrays = [
106
- Arrow::BooleanArray.new(columns[:visible]),
107
- Arrow::UInt32Array.new(columns[:count]),
108
- ]
109
- @builder.append_columns(columns)
110
- assert_equal(Arrow::RecordBatch.new(@schema,
111
- arrays[0].length,
112
- arrays),
113
- @builder.flush)
114
- end
115
-
116
- test("#column_builders") do
117
- column_builders = [
118
- @builder.get_column_builder(0),
119
- @builder.get_column_builder(1),
120
- ]
121
- assert_equal(column_builders,
122
- @builder.column_builders)
123
- end
124
- end
125
- end
@@ -1,115 +0,0 @@
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
- class RecordBatchFileReaderTest < Test::Unit::TestCase
19
- test("write/read") do
20
- fields = [
21
- Arrow::Field.new("uint8", :uint8),
22
- Arrow::Field.new("uint16", :uint16),
23
- Arrow::Field.new("uint32", :uint32),
24
- Arrow::Field.new("uint64", :uint64),
25
- Arrow::Field.new("int8", :int8),
26
- Arrow::Field.new("int16", :int16),
27
- Arrow::Field.new("int32", :int32),
28
- Arrow::Field.new("int64", :int64),
29
- Arrow::Field.new("float", :float),
30
- Arrow::Field.new("double", :double),
31
- ]
32
- schema = Arrow::Schema.new(fields)
33
-
34
- tempfile = Tempfile.new(["batch", ".arrow"])
35
- Arrow::FileOutputStream.open(tempfile.path, false) do |output|
36
- Arrow::RecordBatchFileWriter.open(output, schema) do |writer|
37
- uints = [1, 2, 4, 8]
38
- ints = [1, -2, 4, -8]
39
- floats = [1.1, -2.2, 4.4, -8.8]
40
- columns = [
41
- Arrow::UInt8Array.new(uints),
42
- Arrow::UInt16Array.new(uints),
43
- Arrow::UInt32Array.new(uints),
44
- Arrow::UInt64Array.new(uints),
45
- Arrow::Int8Array.new(ints),
46
- Arrow::Int16Array.new(ints),
47
- Arrow::Int32Array.new(ints),
48
- Arrow::Int64Array.new(ints),
49
- Arrow::FloatArray.new(floats),
50
- Arrow::DoubleArray.new(floats),
51
- ]
52
-
53
- record_batch = Arrow::RecordBatch.new(schema, 4, columns)
54
- writer.write_record_batch(record_batch)
55
- end
56
- end
57
-
58
- Arrow::MemoryMappedInputStream.open(tempfile.path) do |input|
59
- reader = Arrow::RecordBatchFileReader.new(input)
60
- reader.each do |record_batch|
61
- assert_equal([
62
- {
63
- "uint8" => 1,
64
- "uint16" => 1,
65
- "uint32" => 1,
66
- "uint64" => 1,
67
- "int8" => 1,
68
- "int16" => 1,
69
- "int32" => 1,
70
- "int64" => 1,
71
- "float" => 1.100000023841858,
72
- "double" => 1.1,
73
- },
74
- {
75
- "uint8" => 2,
76
- "uint16" => 2,
77
- "uint32" => 2,
78
- "uint64" => 2,
79
- "int8" => -2,
80
- "int16" => -2,
81
- "int32" => -2,
82
- "int64" => -2,
83
- "float" => -2.200000047683716,
84
- "double" => -2.2,
85
- },
86
- {
87
- "uint8" => 4,
88
- "uint16" => 4,
89
- "uint32" => 4,
90
- "uint64" => 4,
91
- "int8" => 4,
92
- "int16" => 4,
93
- "int32" => 4,
94
- "int64" => 4,
95
- "float" => 4.400000095367432,
96
- "double" => 4.4,
97
- },
98
- {
99
- "uint8" => 8,
100
- "uint16" => 8,
101
- "uint32" => 8,
102
- "uint64" => 8,
103
- "int8" => -8,
104
- "int16" => -8,
105
- "int32" => -8,
106
- "int64" => -8,
107
- "float" => -8.800000190734863,
108
- "double" => -8.8,
109
- },
110
- ],
111
- record_batch.collect(&:to_h))
112
- end
113
- end
114
- end
115
- end
@@ -1,37 +0,0 @@
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
- class RecordBatchIteratorTest < Test::Unit::TestCase
19
- def setup
20
- @schema = Arrow::Schema.new(visible: :boolean,
21
- count: :uint32)
22
- @record_batches = [
23
- Arrow::RecordBatch.new(@schema,
24
- visible: [true],
25
- count: [1]),
26
- Arrow::RecordBatch.new(@schema,
27
- visible: [false, nil],
28
- count: [nil, 3]),
29
- ]
30
- @iterator = Arrow::RecordBatchIterator.new(@record_batches)
31
- end
32
-
33
- def test_to_a
34
- assert_equal(@record_batches,
35
- @iterator.to_a)
36
- end
37
- end
@@ -1,46 +0,0 @@
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
- class TestRecordBatchReader < Test::Unit::TestCase
19
- sub_test_case(".try_convert") do
20
- test("Arrow::RecordBatch") do
21
- record_batch =
22
- Arrow::RecordBatch.new("count" => [1, 2, 3],
23
- "private" => [true, false, true])
24
- reader = Arrow::RecordBatchReader.try_convert(record_batch)
25
- assert_equal(record_batch,
26
- reader.read_next)
27
- end
28
-
29
- test("[Arrow::RecordBatch]") do
30
- record_batch =
31
- Arrow::RecordBatch.new("count" => [1, 2, 3],
32
- "private" => [true, false, true])
33
- reader = Arrow::RecordBatchReader.try_convert([record_batch])
34
- assert_equal(record_batch,
35
- reader.read_next)
36
- end
37
-
38
- test("Arrow::Table") do
39
- table = Arrow::Table.new("count" => [1, 2, 3],
40
- "private" => [true, false, true])
41
- reader = Arrow::RecordBatchReader.try_convert(table)
42
- assert_equal(table,
43
- reader.read_all)
44
- end
45
- end
46
- end
@@ -1,182 +0,0 @@
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
- class RecordBatchTest < Test::Unit::TestCase
19
- sub_test_case(".new") do
20
- def setup
21
- @schema = Arrow::Schema.new(visible: :boolean,
22
- count: :uint32)
23
- end
24
-
25
- test("[raw_table]") do
26
- raw_table = {
27
- visible: [true, nil, false],
28
- count: [1, nil, 3],
29
- }
30
- record_batch = Arrow::RecordBatch.new(raw_table)
31
- assert_equal([
32
- {"visible" => true, "count" => 1},
33
- {"visible" => nil, "count" => nil},
34
- {"visible" => false, "count" => 3},
35
- ],
36
- record_batch.each_record.collect(&:to_h))
37
- end
38
-
39
- test("[Schema, records]") do
40
- records = [
41
- {visible: true, count: 1},
42
- nil,
43
- [false, 3],
44
- ]
45
- record_batch = Arrow::RecordBatch.new(@schema, records)
46
- assert_equal([
47
- {"visible" => true, "count" => 1},
48
- {"visible" => nil, "count" => nil},
49
- {"visible" => false, "count" => 3},
50
- ],
51
- record_batch.each_record.collect(&:to_h))
52
- end
53
-
54
- test("[Schema, columns]") do
55
- columns = {
56
- visible: [true, nil, false],
57
- count: [1, 2, nil],
58
- }
59
- record_batch = Arrow::RecordBatch.new(@schema, columns)
60
- assert_equal([
61
- {"visible" => true, "count" => 1},
62
- {"visible" => nil, "count" => 2},
63
- {"visible" => false, "count" => nil},
64
- ],
65
- record_batch.each_record.collect(&:to_h))
66
- end
67
-
68
- test("[Schema, n_rows, columns]") do
69
- columns = [
70
- Arrow::BooleanArray.new([true, nil, false]),
71
- Arrow::UInt32Array.new([1, 2, nil]),
72
- ]
73
- n_rows = columns[0].length
74
- record_batch = Arrow::RecordBatch.new(@schema, n_rows, columns)
75
- assert_equal([
76
- {"visible" => true, "count" => 1},
77
- {"visible" => nil, "count" => 2},
78
- {"visible" => false, "count" => nil},
79
- ],
80
- record_batch.each_record.collect(&:to_h))
81
- end
82
- end
83
-
84
- sub_test_case("instance methods") do
85
- def setup
86
- @schema = Arrow::Schema.new(count: :uint32)
87
- @counts = Arrow::UInt32Array.new([1, 2, 4, 8])
88
- @record_batch = Arrow::RecordBatch.new(@schema, @counts.length, [@counts])
89
- end
90
-
91
- sub_test_case("#each") do
92
- test("default") do
93
- records = []
94
- @record_batch.each do |record|
95
- records << [record, record.index]
96
- end
97
- assert_equal([
98
- [0, 0],
99
- [1, 1],
100
- [2, 2],
101
- [3, 3],
102
- ],
103
- records.collect {|record, i| [record.index, i]})
104
- end
105
-
106
- test("reuse_record: true") do
107
- records = []
108
- @record_batch.each(reuse_record: true) do |record|
109
- records << [record, record.index]
110
- end
111
- assert_equal([
112
- [3, 0],
113
- [3, 1],
114
- [3, 2],
115
- [3, 3],
116
- ],
117
- records.collect {|record, i| [record.index, i]})
118
- end
119
- end
120
-
121
- test("#to_table") do
122
- assert_equal(Arrow::Table.new(@schema, [@counts]),
123
- @record_batch.to_table)
124
- end
125
-
126
- sub_test_case("#==") do
127
- test("Arrow::RecordBatch") do
128
- assert do
129
- @record_batch == @record_batch
130
- end
131
- end
132
-
133
- test("not Arrow::RecordBatch") do
134
- assert do
135
- not (@record_batch == 29)
136
- end
137
- end
138
- end
139
-
140
- sub_test_case("#[]") do
141
- def setup
142
- @record_batch = Arrow::RecordBatch.new(a: [true],
143
- b: [true],
144
- c: [true],
145
- d: [true],
146
- e: [true],
147
- f: [true],
148
- g: [true])
149
- end
150
-
151
- test("[String]") do
152
- assert_equal(Arrow::Column.new(@record_batch, 0),
153
- @record_batch["a"])
154
- end
155
-
156
- test("[Symbol]") do
157
- assert_equal(Arrow::Column.new(@record_batch, 1),
158
- @record_batch[:b])
159
- end
160
-
161
- test("[Integer]") do
162
- assert_equal(Arrow::Column.new(@record_batch, 6),
163
- @record_batch[-1])
164
- end
165
-
166
- test("[Range]") do
167
- assert_equal(Arrow::RecordBatch.new(d: [true],
168
- e: [true]),
169
- @record_batch[3..4])
170
- end
171
-
172
- test("[[Symbol, String, Integer, Range]]") do
173
- assert_equal(Arrow::RecordBatch.new(c: [true],
174
- a: [true],
175
- g: [true],
176
- d: [true],
177
- e: [true]),
178
- @record_batch[[:c, "a", -1, 3..4]])
179
- end
180
- end
181
- end
182
- end
data/test/test-schema.rb DELETED
@@ -1,134 +0,0 @@
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
- class SchemaTest < Test::Unit::TestCase
19
- include Helper::Omittable
20
-
21
- def setup
22
- @count_field = Arrow::Field.new("count", :uint32)
23
- @visible_field = Arrow::Field.new("visible", :boolean)
24
- end
25
-
26
- sub_test_case(".new") do
27
- test("[Arrow::Field]") do
28
- fields = [
29
- @count_field,
30
- @visible_field,
31
- ]
32
- assert_equal("count: uint32\n" +
33
- "visible: bool",
34
- Arrow::Schema.new(fields).to_s)
35
- end
36
-
37
- test("[Arrow::Field, Hash]") do
38
- fields = [
39
- @count_field,
40
- {name: "visible", type: :boolean},
41
- ]
42
- assert_equal("count: uint32\n" +
43
- "visible: bool",
44
- Arrow::Schema.new(fields).to_s)
45
- end
46
-
47
- test("{String, Symbol => Arrow::DataType}") do
48
- fields = {
49
- "count" => Arrow::UInt32DataType.new,
50
- :visible => :boolean,
51
- }
52
- assert_equal("count: uint32\n" +
53
- "visible: bool",
54
- Arrow::Schema.new(fields).to_s)
55
- end
56
-
57
- test("{String, Symbol => Hash}") do
58
- fields = {
59
- "count" => {type: :uint32},
60
- :tags => {
61
- type: :list,
62
- field: {
63
- name: "tag",
64
- type: :string,
65
- },
66
- },
67
- }
68
- assert_equal("count: uint32\n" +
69
- "tags: list<tag: string>",
70
- Arrow::Schema.new(fields).to_s)
71
- end
72
- end
73
-
74
- sub_test_case("instance methods") do
75
- def setup
76
- super
77
- @schema = Arrow::Schema.new([@count_field, @visible_field])
78
- end
79
-
80
- sub_test_case("#[]") do
81
- test("[String]") do
82
- assert_equal([@count_field, @visible_field],
83
- [@schema["count"], @schema["visible"]])
84
- end
85
-
86
- test("[Symbol]") do
87
- assert_equal([@count_field, @visible_field],
88
- [@schema[:count], @schema[:visible]])
89
- end
90
-
91
- test("[Integer]") do
92
- assert_equal([@count_field, @visible_field],
93
- [@schema[0], @schema[1]])
94
- end
95
-
96
- test("[invalid]") do
97
- invalid = []
98
- message = "field name or index must be String, Symbol or Integer"
99
- message << ": <#{invalid.inspect}>"
100
- assert_raise(ArgumentError.new(message)) do
101
- @schema[invalid]
102
- end
103
- end
104
- end
105
-
106
- sub_test_case("#==") do
107
- test("Arrow::Schema") do
108
- assert do
109
- @schema == @schema
110
- end
111
- end
112
-
113
- test("not Arrow::Schema") do
114
- assert do
115
- not (@schema == 29)
116
- end
117
- end
118
- end
119
-
120
- sub_test_case("#to_s") do
121
- test("show_metadata") do
122
- require_gi_bindings(3, 4, 2)
123
-
124
- schema = @schema.with_metadata("key" => "value")
125
- assert_equal(<<-SCHEMA.chomp, schema.to_s(show_metadata: true))
126
- count: uint32
127
- visible: bool
128
- -- metadata --
129
- key: value
130
- SCHEMA
131
- end
132
- end
133
- end
134
- end