red-arrow 18.1.0 → 19.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/lib/arrow/array.rb +7 -4
  3. data/lib/arrow/column.rb +4 -4
  4. data/lib/arrow/jruby/array-builder.rb +114 -0
  5. data/lib/arrow/jruby/array.rb +109 -0
  6. data/{test/helper/fixture.rb → lib/arrow/jruby/chunked-array.rb} +14 -6
  7. data/lib/arrow/jruby/compression-type.rb +26 -0
  8. data/{test/test-boolean-scalar.rb → lib/arrow/jruby/csv-read-options.rb} +12 -6
  9. data/{test/test-map-data-type.rb → lib/arrow/jruby/data-type.rb} +24 -12
  10. data/lib/arrow/jruby/decimal128.rb +28 -0
  11. data/lib/arrow/jruby/decimal256.rb +28 -0
  12. data/{test/fixture/null-with-double-quote.csv → lib/arrow/jruby/error.rb} +7 -4
  13. data/lib/arrow/jruby/file-system.rb +24 -0
  14. data/{test/test-null-array.rb → lib/arrow/jruby/function.rb} +5 -4
  15. data/lib/arrow/jruby/record-batch-iterator.rb +24 -0
  16. data/{test/fixture/integer-float.csv → lib/arrow/jruby/record-batch.rb} +8 -4
  17. data/{test/fixture/float-integer.csv → lib/arrow/jruby/sort-key.rb} +8 -4
  18. data/lib/arrow/jruby/sort-options.rb +24 -0
  19. data/lib/arrow/jruby/stream-listener-raw.rb +25 -0
  20. data/{test/test-rolling-window.rb → lib/arrow/jruby/table.rb} +19 -19
  21. data/lib/arrow/jruby/writable.rb +24 -0
  22. data/lib/arrow/jruby.rb +52 -0
  23. data/lib/arrow/libraries.rb +126 -0
  24. data/lib/arrow/list-array-builder.rb +1 -0
  25. data/lib/arrow/loader.rb +3 -111
  26. data/{test/fixture/null-without-double-quote.csv → lib/arrow/ruby.rb} +6 -4
  27. data/lib/arrow/version.rb +1 -1
  28. data/lib/arrow.rb +2 -7
  29. data/red-arrow.gemspec +15 -6
  30. metadata +26 -229
  31. data/test/each-raw-record/test-basic-arrays.rb +0 -411
  32. data/test/each-raw-record/test-dense-union-array.rb +0 -566
  33. data/test/each-raw-record/test-dictionary-array.rb +0 -341
  34. data/test/each-raw-record/test-list-array.rb +0 -628
  35. data/test/each-raw-record/test-map-array.rb +0 -507
  36. data/test/each-raw-record/test-multiple-columns.rb +0 -72
  37. data/test/each-raw-record/test-sparse-union-array.rb +0 -528
  38. data/test/each-raw-record/test-struct-array.rb +0 -529
  39. data/test/each-raw-record/test-table.rb +0 -47
  40. data/test/fixture/TestOrcFile.test1.orc +0 -0
  41. data/test/fixture/with-header-float.csv +0 -20
  42. data/test/fixture/with-header.csv +0 -20
  43. data/test/fixture/without-header-float.csv +0 -19
  44. data/test/fixture/without-header.csv +0 -19
  45. data/test/helper/omittable.rb +0 -49
  46. data/test/helper.rb +0 -31
  47. data/test/raw-records/test-basic-arrays.rb +0 -405
  48. data/test/raw-records/test-dense-union-array.rb +0 -566
  49. data/test/raw-records/test-dictionary-array.rb +0 -341
  50. data/test/raw-records/test-list-array.rb +0 -628
  51. data/test/raw-records/test-map-array.rb +0 -507
  52. data/test/raw-records/test-multiple-columns.rb +0 -65
  53. data/test/raw-records/test-sparse-union-array.rb +0 -556
  54. data/test/raw-records/test-struct-array.rb +0 -529
  55. data/test/raw-records/test-table.rb +0 -47
  56. data/test/run-test.rb +0 -71
  57. data/test/test-array-builder.rb +0 -198
  58. data/test/test-array.rb +0 -332
  59. data/test/test-bigdecimal.rb +0 -40
  60. data/test/test-binary-dictionary-array-builder.rb +0 -103
  61. data/test/test-buffer.rb +0 -49
  62. data/test/test-chunked-array.rb +0 -198
  63. data/test/test-column.rb +0 -123
  64. data/test/test-csv-loader.rb +0 -297
  65. data/test/test-data-type.rb +0 -84
  66. data/test/test-date32-array.rb +0 -24
  67. data/test/test-date64-array.rb +0 -25
  68. data/test/test-decimal128-array-builder.rb +0 -126
  69. data/test/test-decimal128-array.rb +0 -47
  70. data/test/test-decimal128-data-type.rb +0 -31
  71. data/test/test-decimal128.rb +0 -126
  72. data/test/test-decimal256-array-builder.rb +0 -126
  73. data/test/test-decimal256-array.rb +0 -47
  74. data/test/test-decimal256-data-type.rb +0 -31
  75. data/test/test-decimal256.rb +0 -126
  76. data/test/test-dense-union-array.rb +0 -42
  77. data/test/test-dense-union-data-type.rb +0 -41
  78. data/test/test-dictionary-array.rb +0 -41
  79. data/test/test-dictionary-data-type.rb +0 -40
  80. data/test/test-expression.rb +0 -51
  81. data/test/test-feather.rb +0 -49
  82. data/test/test-field.rb +0 -117
  83. data/test/test-file-output-stream.rb +0 -54
  84. data/test/test-fixed-size-binary-array-builder.rb +0 -92
  85. data/test/test-fixed-size-binary-array.rb +0 -36
  86. data/test/test-float-scalar.rb +0 -46
  87. data/test/test-function.rb +0 -210
  88. data/test/test-group.rb +0 -193
  89. data/test/test-half-float-array.rb +0 -43
  90. data/test/test-half-float.rb +0 -130
  91. data/test/test-list-array-builder.rb +0 -79
  92. data/test/test-list-array.rb +0 -32
  93. data/test/test-list-data-type.rb +0 -69
  94. data/test/test-map-array-builder.rb +0 -110
  95. data/test/test-map-array.rb +0 -33
  96. data/test/test-memory-view.rb +0 -434
  97. data/test/test-orc.rb +0 -173
  98. data/test/test-ractor.rb +0 -34
  99. data/test/test-record-batch-builder.rb +0 -125
  100. data/test/test-record-batch-file-reader.rb +0 -136
  101. data/test/test-record-batch-iterator.rb +0 -37
  102. data/test/test-record-batch-reader.rb +0 -46
  103. data/test/test-record-batch-stream-reader.rb +0 -129
  104. data/test/test-record-batch.rb +0 -182
  105. data/test/test-scalar.rb +0 -65
  106. data/test/test-schema.rb +0 -134
  107. data/test/test-slicer.rb +0 -589
  108. data/test/test-sort-indices.rb +0 -40
  109. data/test/test-sort-key.rb +0 -81
  110. data/test/test-sort-options.rb +0 -58
  111. data/test/test-sparse-union-array.rb +0 -38
  112. data/test/test-sparse-union-data-type.rb +0 -41
  113. data/test/test-stream-listener.rb +0 -60
  114. data/test/test-string-dictionary-array-builder.rb +0 -103
  115. data/test/test-struct-array-builder.rb +0 -184
  116. data/test/test-struct-array.rb +0 -94
  117. data/test/test-struct-data-type.rb +0 -112
  118. data/test/test-table.rb +0 -1530
  119. data/test/test-tensor.rb +0 -297
  120. data/test/test-time.rb +0 -288
  121. data/test/test-time32-array.rb +0 -81
  122. data/test/test-time32-data-type.rb +0 -42
  123. data/test/test-time64-array.rb +0 -81
  124. data/test/test-time64-data-type.rb +0 -42
  125. data/test/test-timestamp-array.rb +0 -45
  126. data/test/test-timestamp-data-type.rb +0 -42
  127. data/test/values/test-basic-arrays.rb +0 -335
  128. data/test/values/test-dense-union-array.rb +0 -552
  129. data/test/values/test-dictionary-array.rb +0 -325
  130. data/test/values/test-list-array.rb +0 -587
  131. data/test/values/test-map-array.rb +0 -489
  132. data/test/values/test-sparse-union-array.rb +0 -543
  133. data/test/values/test-struct-array.rb +0 -524
data/test/test-orc.rb DELETED
@@ -1,173 +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 ORCTest < Test::Unit::TestCase
19
- include Helper::Fixture
20
-
21
- def setup
22
- omit("Require Apache Arrow ORC") unless Arrow.const_defined?(:ORCFileReader)
23
- @orc_path = fixture_path("TestOrcFile.test1.orc")
24
- end
25
-
26
- def pp_values(values)
27
- "[\n " + values.collect(&:inspect).join(",\n ") + "\n]"
28
- end
29
-
30
- sub_test_case("load") do
31
- test("default") do
32
- table = Arrow::Table.load(@orc_path)
33
- dump = table.columns.collect do |column|
34
- [
35
- column.field.to_s,
36
- column.data.chunks.collect(&:to_s),
37
- ]
38
- end
39
- assert_equal([
40
- ["boolean1: bool", [pp_values([false, true])]],
41
- ["byte1: int8", [pp_values([1, 100])]],
42
- ["short1: int16", [pp_values([1024, 2048])]],
43
- ["int1: int32", [pp_values([65536, 65536])]],
44
- [
45
- "long1: int64",
46
- [pp_values([9223372036854775807, 9223372036854775807])],
47
- ],
48
- ["float1: float", [pp_values([1, 2])]],
49
- ["double1: double", [pp_values([-15, -5])]],
50
- ["bytes1: binary", ["[\n 0001020304,\n \n]"]],
51
- ["string1: string", [pp_values(["hi", "bye"])]],
52
- [
53
- "middle: " +
54
- "struct<list: " +
55
- "list<item: struct<int1: int32, string1: string>>>",
56
- [
57
- <<-STRUCT.chomp
58
- -- is_valid: all not null
59
- -- child 0 type: list<item: struct<int1: int32, string1: string>>
60
- [
61
- -- is_valid: all not null
62
- -- child 0 type: int32
63
- [
64
- 1,
65
- 2
66
- ]
67
- -- child 1 type: string
68
- [
69
- "bye",
70
- "sigh"
71
- ],
72
- -- is_valid: all not null
73
- -- child 0 type: int32
74
- [
75
- 1,
76
- 2
77
- ]
78
- -- child 1 type: string
79
- [
80
- "bye",
81
- "sigh"
82
- ]
83
- ]
84
- STRUCT
85
- ]
86
- ],
87
- [
88
- "list: list<item: struct<int1: int32, string1: string>>",
89
- [
90
- <<-LIST.chomp
91
- [
92
- -- is_valid: all not null
93
- -- child 0 type: int32
94
- [
95
- 3,
96
- 4
97
- ]
98
- -- child 1 type: string
99
- [
100
- "good",
101
- "bad"
102
- ],
103
- -- is_valid: all not null
104
- -- child 0 type: int32
105
- [
106
- 100000000,
107
- -100000,
108
- 1234
109
- ]
110
- -- child 1 type: string
111
- [
112
- "cat",
113
- "in",
114
- "hat"
115
- ]
116
- ]
117
- LIST
118
- ]
119
- ],
120
- [
121
- "map: map<string, struct<int1: int32, string1: string>>",
122
- [
123
- <<-MAP.chomp
124
- [
125
- keys:
126
- []
127
- values:
128
- -- is_valid: all not null
129
- -- child 0 type: int32
130
- []
131
- -- child 1 type: string
132
- [],
133
- keys:
134
- [
135
- "chani",
136
- "mauddib"
137
- ]
138
- values:
139
- -- is_valid: all not null
140
- -- child 0 type: int32
141
- [
142
- 5,
143
- 1
144
- ]
145
- -- child 1 type: string
146
- [
147
- "chani",
148
- "mauddib"
149
- ]
150
- ]
151
- MAP
152
- ],
153
- ],
154
- ],
155
- dump)
156
- end
157
-
158
- test(":field_indexes") do
159
- table = Arrow::Table.load(@orc_path, field_indexes: [1, 3])
160
- dump = table.columns.collect do |column|
161
- [
162
- column.field.to_s,
163
- column.data.chunks.collect(&:to_s),
164
- ]
165
- end
166
- assert_equal([
167
- ["byte1: int8", [pp_values([1, 100])]],
168
- ["int1: int32", [pp_values([65536, 65536])]],
169
- ],
170
- dump)
171
- end
172
- end
173
- end
data/test/test-ractor.rb DELETED
@@ -1,34 +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 RactorTest < Test::Unit::TestCase
19
- include Helper::Omittable
20
-
21
- ractor
22
- test("ChunkedArray") do
23
- require_ruby(3, 1, 0)
24
- array = Arrow::Array.new([1, 2, 3])
25
- chunked_array = Arrow::ChunkedArray.new([array])
26
- Ractor.make_shareable(chunked_array)
27
- ractor = Ractor.new do
28
- recived_chunked_array = Ractor.receive
29
- recived_chunked_array.chunks
30
- end
31
- ractor.send(chunked_array)
32
- assert_equal([array], ractor.take)
33
- end
34
- end
@@ -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,136 +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
-
116
- sub_test_case("#each") do
117
- test("without block") do
118
- buffer = Arrow::ResizableBuffer.new(1024)
119
- Arrow::Table.new(number: [1, 2, 3]).save(buffer)
120
- Arrow::BufferInputStream.open(buffer) do |input|
121
- reader = Arrow::RecordBatchFileReader.new(input)
122
- each = reader.each
123
- assert_equal({
124
- size: 1,
125
- to_a: [
126
- Arrow::RecordBatch.new(number: [1, 2, 3]),
127
- ],
128
- },
129
- {
130
- size: each.size,
131
- to_a: each.to_a,
132
- })
133
- end
134
- end
135
- end
136
- 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,129 +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 RecordBatchStreamReaderTest < 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", ".arrows"])
35
- Arrow::FileOutputStream.open(tempfile.path, false) do |output|
36
- Arrow::RecordBatchStreamWriter.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::RecordBatchStreamReader.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
-
116
- sub_test_case("#each") do
117
- test("without block") do
118
- buffer = Arrow::ResizableBuffer.new(1024)
119
- Arrow::Table.new(number: [1, 2, 3]).save(buffer, format: :arrows)
120
- Arrow::BufferInputStream.open(buffer) do |input|
121
- reader = Arrow::RecordBatchStreamReader.new(input)
122
- assert_equal([
123
- Arrow::RecordBatch.new(number: [1, 2, 3]),
124
- ],
125
- reader.each.to_a)
126
- end
127
- end
128
- end
129
- end