red-arrow 8.0.0 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/arrow/converters.hpp +3 -0
- data/ext/arrow/extconf.rb +6 -4
- data/lib/arrow/array-builder.rb +40 -6
- data/lib/arrow/array-computable.rb +37 -0
- data/lib/arrow/array.rb +16 -0
- data/lib/arrow/chunked-array.rb +21 -0
- data/lib/arrow/column.rb +28 -0
- data/lib/arrow/data-type.rb +2 -1
- data/lib/arrow/decimal128-array-builder.rb +16 -6
- data/lib/arrow/decimal128.rb +14 -0
- data/lib/arrow/decimal256-array-builder.rb +16 -6
- data/lib/arrow/decimal256.rb +14 -0
- data/lib/arrow/field.rb +44 -3
- data/lib/arrow/list-data-type.rb +1 -6
- data/lib/arrow/loader.rb +3 -0
- data/lib/arrow/string-array-builder.rb +30 -0
- data/lib/arrow/time-unit.rb +31 -0
- data/lib/arrow/time32-array-builder.rb +2 -14
- data/lib/arrow/time32-data-type.rb +9 -38
- data/lib/arrow/time64-array-builder.rb +2 -14
- data/lib/arrow/time64-data-type.rb +9 -38
- data/lib/arrow/timestamp-array-builder.rb +2 -14
- data/lib/arrow/timestamp-data-type.rb +9 -34
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +1 -1
- data/test/raw-records/test-dictionary-array.rb +341 -0
- data/test/test-array-builder.rb +62 -0
- data/test/test-chunked-array.rb +6 -0
- data/test/test-column.rb +31 -0
- data/test/test-decimal128-array-builder.rb +14 -0
- data/test/test-decimal128-array.rb +5 -2
- data/test/test-decimal128.rb +26 -2
- data/test/test-decimal256-array-builder.rb +14 -0
- data/test/test-decimal256-array.rb +5 -2
- data/test/test-decimal256.rb +26 -2
- data/test/test-field.rb +26 -0
- data/test/values/test-dictionary-array.rb +30 -0
- metadata +11 -6
@@ -18,24 +18,12 @@
|
|
18
18
|
module Arrow
|
19
19
|
class Time64ArrayBuilder
|
20
20
|
class << self
|
21
|
-
def build(
|
22
|
-
builder = new(
|
21
|
+
def build(data_type, values)
|
22
|
+
builder = new(data_type)
|
23
23
|
builder.build(values)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
alias_method :initialize_raw, :initialize
|
28
|
-
def initialize(unit_or_data_type)
|
29
|
-
case unit_or_data_type
|
30
|
-
when DataType
|
31
|
-
data_type = unit_or_data_type
|
32
|
-
else
|
33
|
-
unit = unit_or_data_type
|
34
|
-
data_type = Time64DataType.new(unit)
|
35
|
-
end
|
36
|
-
initialize_raw(data_type)
|
37
|
-
end
|
38
|
-
|
39
27
|
def unit
|
40
28
|
@unit ||= value_data_type.unit
|
41
29
|
end
|
@@ -17,45 +17,16 @@
|
|
17
17
|
|
18
18
|
module Arrow
|
19
19
|
class Time64DataType
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
# The unit must be microsecond or nanosecond.
|
31
|
-
#
|
32
|
-
# @example Create a time64 data type with Arrow::TimeUnit
|
33
|
-
# Arrow::Time64DataType.new(Arrow::TimeUnit::NANO)
|
34
|
-
#
|
35
|
-
# @example Create a time64 data type with Symbol
|
36
|
-
# Arrow::Time64DataType.new(:nano)
|
37
|
-
#
|
38
|
-
# @overload initialize(description)
|
39
|
-
#
|
40
|
-
# @param description [Hash] The description of the time64 data
|
41
|
-
# type. It must have `:unit` value.
|
42
|
-
#
|
43
|
-
# @option description [Arrow::TimeUnit, Symbol] :unit The unit of
|
44
|
-
# the time64 data type.
|
45
|
-
#
|
46
|
-
# The unit must be microsecond or nanosecond.
|
47
|
-
#
|
48
|
-
# @example Create a time64 data type with Arrow::TimeUnit
|
49
|
-
# Arrow::Time64DataType.new(unit: Arrow::TimeUnit::NANO)
|
50
|
-
#
|
51
|
-
# @example Create a time64 data type with Symbol
|
52
|
-
# Arrow::Time64DataType.new(unit: :nano)
|
53
|
-
def initialize(unit)
|
54
|
-
if unit.is_a?(Hash)
|
55
|
-
description = unit
|
56
|
-
unit = description[:unit]
|
20
|
+
class << self
|
21
|
+
# @api private
|
22
|
+
def try_convert(value)
|
23
|
+
case value
|
24
|
+
when Symbol, Arrow::TimeUnit
|
25
|
+
new(value)
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
57
29
|
end
|
58
|
-
initialize_raw(unit)
|
59
30
|
end
|
60
31
|
end
|
61
32
|
end
|
@@ -18,24 +18,12 @@
|
|
18
18
|
module Arrow
|
19
19
|
class TimestampArrayBuilder
|
20
20
|
class << self
|
21
|
-
def build(
|
22
|
-
builder = new(
|
21
|
+
def build(data_type, values)
|
22
|
+
builder = new(data_type)
|
23
23
|
builder.build(values)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
alias_method :initialize_raw, :initialize
|
28
|
-
def initialize(unit_or_data_type)
|
29
|
-
case unit_or_data_type
|
30
|
-
when DataType
|
31
|
-
data_type = unit_or_data_type
|
32
|
-
else
|
33
|
-
unit = unit_or_data_type
|
34
|
-
data_type = TimestampDataType.new(unit)
|
35
|
-
end
|
36
|
-
initialize_raw(data_type)
|
37
|
-
end
|
38
|
-
|
39
27
|
private
|
40
28
|
def unit_id
|
41
29
|
@unit_id ||= value_data_type.unit.nick.to_sym
|
@@ -17,41 +17,16 @@
|
|
17
17
|
|
18
18
|
module Arrow
|
19
19
|
class TimestampDataType
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
# @example Create a timestamp data type with Arrow::TimeUnit
|
31
|
-
# Arrow::TimestampDataType.new(Arrow::TimeUnit::MILLI)
|
32
|
-
#
|
33
|
-
# @example Create a timestamp data type with Symbol
|
34
|
-
# Arrow::TimestampDataType.new(:milli)
|
35
|
-
#
|
36
|
-
# @overload initialize(description)
|
37
|
-
#
|
38
|
-
# @param description [Hash] The description of the timestamp data
|
39
|
-
# type. It must have `:unit` value.
|
40
|
-
#
|
41
|
-
# @option description [Arrow::TimeUnit, Symbol] :unit The unit of
|
42
|
-
# the timestamp data type.
|
43
|
-
#
|
44
|
-
# @example Create a timestamp data type with Arrow::TimeUnit
|
45
|
-
# Arrow::TimestampDataType.new(unit: Arrow::TimeUnit::MILLI)
|
46
|
-
#
|
47
|
-
# @example Create a timestamp data type with Symbol
|
48
|
-
# Arrow::TimestampDataType.new(unit: :milli)
|
49
|
-
def initialize(unit)
|
50
|
-
if unit.is_a?(Hash)
|
51
|
-
description = unit
|
52
|
-
unit = description[:unit]
|
20
|
+
class << self
|
21
|
+
# @api private
|
22
|
+
def try_convert(value)
|
23
|
+
case value
|
24
|
+
when Symbol, Arrow::TimeUnit
|
25
|
+
new(value)
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
53
29
|
end
|
54
|
-
initialize_raw(unit)
|
55
30
|
end
|
56
31
|
end
|
57
32
|
end
|
data/lib/arrow/version.rb
CHANGED
data/red-arrow.gemspec
CHANGED
@@ -46,7 +46,7 @@ Gem::Specification.new do |spec|
|
|
46
46
|
spec.test_files += Dir.glob("test/**/*")
|
47
47
|
spec.extensions = ["ext/arrow/extconf.rb"]
|
48
48
|
|
49
|
-
spec.add_runtime_dependency("bigdecimal", ">=
|
49
|
+
spec.add_runtime_dependency("bigdecimal", ">= 3.1.0")
|
50
50
|
spec.add_runtime_dependency("extpp", ">= 0.0.7")
|
51
51
|
spec.add_runtime_dependency("gio2", ">= 3.5.0")
|
52
52
|
spec.add_runtime_dependency("native-package-installer")
|
@@ -0,0 +1,341 @@
|
|
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 RawRecordsDictionaryArrayTests
|
19
|
+
def build_record_batch(array)
|
20
|
+
dictionary = array.dictionary_encode
|
21
|
+
schema = Arrow::Schema.new(column: dictionary.value_data_type)
|
22
|
+
Arrow::RecordBatch.new(schema, array.length, [dictionary])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_null
|
26
|
+
records = [
|
27
|
+
[nil],
|
28
|
+
[nil],
|
29
|
+
[nil],
|
30
|
+
[nil],
|
31
|
+
]
|
32
|
+
target = build(Arrow::NullArray.new(records.collect(&:first)))
|
33
|
+
assert_equal(records, target.raw_records)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_boolean
|
37
|
+
records = [
|
38
|
+
[true],
|
39
|
+
[nil],
|
40
|
+
[false],
|
41
|
+
]
|
42
|
+
target = build(Arrow::BooleanArray.new(records.collect(&:first)))
|
43
|
+
assert_equal(records, target.raw_records)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_int8
|
47
|
+
records = [
|
48
|
+
[-(2 ** 7)],
|
49
|
+
[nil],
|
50
|
+
[(2 ** 7) - 1],
|
51
|
+
]
|
52
|
+
target = build(Arrow::Int8Array.new(records.collect(&:first)))
|
53
|
+
assert_equal(records, target.raw_records)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_uint8
|
57
|
+
records = [
|
58
|
+
[0],
|
59
|
+
[nil],
|
60
|
+
[(2 ** 8) - 1],
|
61
|
+
]
|
62
|
+
target = build(Arrow::UInt8Array.new(records.collect(&:first)))
|
63
|
+
assert_equal(records, target.raw_records)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_int16
|
67
|
+
records = [
|
68
|
+
[-(2 ** 15)],
|
69
|
+
[nil],
|
70
|
+
[(2 ** 15) - 1],
|
71
|
+
]
|
72
|
+
target = build(Arrow::Int16Array.new(records.collect(&:first)))
|
73
|
+
assert_equal(records, target.raw_records)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_uint16
|
77
|
+
records = [
|
78
|
+
[0],
|
79
|
+
[nil],
|
80
|
+
[(2 ** 16) - 1],
|
81
|
+
]
|
82
|
+
target = build(Arrow::UInt16Array.new(records.collect(&:first)))
|
83
|
+
assert_equal(records, target.raw_records)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_int32
|
87
|
+
records = [
|
88
|
+
[-(2 ** 31)],
|
89
|
+
[nil],
|
90
|
+
[(2 ** 31) - 1],
|
91
|
+
]
|
92
|
+
target = build(Arrow::Int32Array.new(records.collect(&:first)))
|
93
|
+
assert_equal(records, target.raw_records)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_uint32
|
97
|
+
records = [
|
98
|
+
[0],
|
99
|
+
[nil],
|
100
|
+
[(2 ** 32) - 1],
|
101
|
+
]
|
102
|
+
target = build(Arrow::UInt32Array.new(records.collect(&:first)))
|
103
|
+
assert_equal(records, target.raw_records)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_int64
|
107
|
+
records = [
|
108
|
+
[-(2 ** 63)],
|
109
|
+
[nil],
|
110
|
+
[(2 ** 63) - 1],
|
111
|
+
]
|
112
|
+
target = build(Arrow::Int64Array.new(records.collect(&:first)))
|
113
|
+
assert_equal(records, target.raw_records)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_uint64
|
117
|
+
records = [
|
118
|
+
[0],
|
119
|
+
[nil],
|
120
|
+
[(2 ** 64) - 1],
|
121
|
+
]
|
122
|
+
target = build(Arrow::UInt64Array.new(records.collect(&:first)))
|
123
|
+
assert_equal(records, target.raw_records)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_float
|
127
|
+
records = [
|
128
|
+
[-1.0],
|
129
|
+
[nil],
|
130
|
+
[1.0],
|
131
|
+
]
|
132
|
+
target = build(Arrow::FloatArray.new(records.collect(&:first)))
|
133
|
+
assert_equal(records, target.raw_records)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_double
|
137
|
+
records = [
|
138
|
+
[-1.0],
|
139
|
+
[nil],
|
140
|
+
[1.0],
|
141
|
+
]
|
142
|
+
target = build(Arrow::DoubleArray.new(records.collect(&:first)))
|
143
|
+
assert_equal(records, target.raw_records)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_binary
|
147
|
+
records = [
|
148
|
+
["\x00".b],
|
149
|
+
[nil],
|
150
|
+
["\xff".b],
|
151
|
+
]
|
152
|
+
target = build(Arrow::BinaryArray.new(records.collect(&:first)))
|
153
|
+
assert_equal(records, target.raw_records)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_string
|
157
|
+
records = [
|
158
|
+
["Ruby"],
|
159
|
+
[nil],
|
160
|
+
["\u3042"], # U+3042 HIRAGANA LETTER A
|
161
|
+
]
|
162
|
+
target = build(Arrow::StringArray.new(records.collect(&:first)))
|
163
|
+
assert_equal(records, target.raw_records)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_date32
|
167
|
+
records = [
|
168
|
+
[Date.new(1960, 1, 1)],
|
169
|
+
[nil],
|
170
|
+
[Date.new(2017, 8, 23)],
|
171
|
+
]
|
172
|
+
target = build(Arrow::Date32Array.new(records.collect(&:first)))
|
173
|
+
assert_equal(records, target.raw_records)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_date64
|
177
|
+
records = [
|
178
|
+
[DateTime.new(1960, 1, 1, 2, 9, 30)],
|
179
|
+
[nil],
|
180
|
+
[DateTime.new(2017, 8, 23, 14, 57, 2)],
|
181
|
+
]
|
182
|
+
target = build(Arrow::Date64Array.new(records.collect(&:first)))
|
183
|
+
assert_equal(records, target.raw_records)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_timestamp_second
|
187
|
+
records = [
|
188
|
+
[Time.parse("1960-01-01T02:09:30Z")],
|
189
|
+
[nil],
|
190
|
+
[Time.parse("2017-08-23T14:57:02Z")],
|
191
|
+
]
|
192
|
+
target = build(Arrow::TimestampArray.new(:second, records.collect(&:first)))
|
193
|
+
assert_equal(records, target.raw_records)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_timestamp_milli
|
197
|
+
records = [
|
198
|
+
[Time.parse("1960-01-01T02:09:30.123Z")],
|
199
|
+
[nil],
|
200
|
+
[Time.parse("2017-08-23T14:57:02.987Z")],
|
201
|
+
]
|
202
|
+
target = build(Arrow::TimestampArray.new(:milli, records.collect(&:first)))
|
203
|
+
assert_equal(records, target.raw_records)
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_timestamp_micro
|
207
|
+
records = [
|
208
|
+
[Time.parse("1960-01-01T02:09:30.123456Z")],
|
209
|
+
[nil],
|
210
|
+
[Time.parse("2017-08-23T14:57:02.987654Z")],
|
211
|
+
]
|
212
|
+
target = build(Arrow::TimestampArray.new(:micro, records.collect(&:first)))
|
213
|
+
assert_equal(records, target.raw_records)
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_timestamp_nano
|
217
|
+
records = [
|
218
|
+
[Time.parse("1960-01-01T02:09:30.123456789Z")],
|
219
|
+
[nil],
|
220
|
+
[Time.parse("2017-08-23T14:57:02.987654321Z")],
|
221
|
+
]
|
222
|
+
target = build(Arrow::TimestampArray.new(:nano, records.collect(&:first)))
|
223
|
+
assert_equal(records, target.raw_records)
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_time32_second
|
227
|
+
unit = Arrow::TimeUnit::SECOND
|
228
|
+
records = [
|
229
|
+
[Arrow::Time.new(unit, 60 * 10)], # 00:10:00
|
230
|
+
[nil],
|
231
|
+
[Arrow::Time.new(unit, 60 * 60 * 2 + 9)], # 02:00:09
|
232
|
+
]
|
233
|
+
target = build(Arrow::Time32Array.new(unit, records.collect(&:first)))
|
234
|
+
assert_equal(records, target.raw_records)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_time32_milli
|
238
|
+
unit = Arrow::TimeUnit::MILLI
|
239
|
+
records = [
|
240
|
+
[Arrow::Time.new(unit, (60 * 10) * 1000 + 123)], # 00:10:00.123
|
241
|
+
[nil],
|
242
|
+
[Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1000 + 987)], # 02:00:09.987
|
243
|
+
]
|
244
|
+
target = build(Arrow::Time32Array.new(unit, records.collect(&:first)))
|
245
|
+
assert_equal(records, target.raw_records)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_time64_micro
|
249
|
+
unit = Arrow::TimeUnit::MICRO
|
250
|
+
records = [
|
251
|
+
# 00:10:00.123456
|
252
|
+
[Arrow::Time.new(unit, (60 * 10) * 1_000_000 + 123_456)],
|
253
|
+
[nil],
|
254
|
+
# 02:00:09.987654
|
255
|
+
[Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000 + 987_654)],
|
256
|
+
]
|
257
|
+
target = build(Arrow::Time64Array.new(unit, records.collect(&:first)))
|
258
|
+
assert_equal(records, target.raw_records)
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_time64_nano
|
262
|
+
unit = Arrow::TimeUnit::NANO
|
263
|
+
records = [
|
264
|
+
# 00:10:00.123456789
|
265
|
+
[Arrow::Time.new(unit, (60 * 10) * 1_000_000_000 + 123_456_789)],
|
266
|
+
[nil],
|
267
|
+
# 02:00:09.987654321
|
268
|
+
[Arrow::Time.new(unit, (60 * 60 * 2 + 9) * 1_000_000_000 + 987_654_321)],
|
269
|
+
]
|
270
|
+
target = build(Arrow::Time64Array.new(unit, records.collect(&:first)))
|
271
|
+
assert_equal(records, target.raw_records)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_decimal128
|
275
|
+
records = [
|
276
|
+
[BigDecimal("92.92")],
|
277
|
+
[nil],
|
278
|
+
[BigDecimal("29.29")],
|
279
|
+
]
|
280
|
+
data_type = Arrow::Decimal128DataType.new(8, 2)
|
281
|
+
target = build(Arrow::Decimal128Array.new(data_type, records.collect(&:first)))
|
282
|
+
assert_equal(records, target.raw_records)
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_decimal256
|
286
|
+
records = [
|
287
|
+
[BigDecimal("92.92")],
|
288
|
+
[nil],
|
289
|
+
[BigDecimal("29.29")],
|
290
|
+
]
|
291
|
+
data_type = Arrow::Decimal256DataType.new(38, 2)
|
292
|
+
target = build(Arrow::Decimal256Array.new(data_type, records.collect(&:first)))
|
293
|
+
assert_equal(records, target.raw_records)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_month_interval
|
297
|
+
records = [
|
298
|
+
[1],
|
299
|
+
[nil],
|
300
|
+
[12],
|
301
|
+
]
|
302
|
+
target = build(Arrow::MonthIntervalArray.new(records.collect(&:first)))
|
303
|
+
assert_equal(records, target.raw_records)
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_day_time_interval
|
307
|
+
records = [
|
308
|
+
[{day: 1, millisecond: 100}],
|
309
|
+
[nil],
|
310
|
+
[{day: 2, millisecond: 300}],
|
311
|
+
]
|
312
|
+
target = build(Arrow::DayTimeIntervalArray.new(records.collect(&:first)))
|
313
|
+
assert_equal(records, target.raw_records)
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_month_day_nano_interval
|
317
|
+
records = [
|
318
|
+
[{month: 1, day: 1, nanosecond: 100}],
|
319
|
+
[nil],
|
320
|
+
[{month: 2, day: 3, nanosecond: 400}],
|
321
|
+
]
|
322
|
+
target = build(Arrow::MonthDayNanoIntervalArray.new(records.collect(&:first)))
|
323
|
+
assert_equal(records, target.raw_records)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
class RawRecordsRecordBatchDictionaryArraysTest < Test::Unit::TestCase
|
328
|
+
include RawRecordsDictionaryArrayTests
|
329
|
+
|
330
|
+
def build(array)
|
331
|
+
build_record_batch(array)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
class RawRecordsTableDictionaryArraysTest < Test::Unit::TestCase
|
336
|
+
include RawRecordsDictionaryArrayTests
|
337
|
+
|
338
|
+
def build(array)
|
339
|
+
build_record_batch(array).to_table
|
340
|
+
end
|
341
|
+
end
|
data/test/test-array-builder.rb
CHANGED
@@ -68,6 +68,68 @@ class ArrayBuilderTest < Test::Unit::TestCase
|
|
68
68
|
])
|
69
69
|
end
|
70
70
|
|
71
|
+
test("decimal + string") do
|
72
|
+
raw_array = [BigDecimal("10.1"), "10.1"]
|
73
|
+
array = Arrow::ArrayBuilder.build(raw_array)
|
74
|
+
assert_equal(raw_array.collect(&:to_s), array.to_a)
|
75
|
+
end
|
76
|
+
|
77
|
+
test("NaN") do
|
78
|
+
raw_array = [BigDecimal("10.1"), BigDecimal::NAN]
|
79
|
+
array = Arrow::ArrayBuilder.build(raw_array)
|
80
|
+
assert_equal(raw_array.collect(&:to_s), array.to_a)
|
81
|
+
end
|
82
|
+
|
83
|
+
test("Infinity") do
|
84
|
+
raw_array = [BigDecimal("10.1"), BigDecimal::INFINITY]
|
85
|
+
array = Arrow::ArrayBuilder.build(raw_array)
|
86
|
+
assert_equal(raw_array.collect(&:to_s), array.to_a)
|
87
|
+
end
|
88
|
+
|
89
|
+
test("decimal128") do
|
90
|
+
values = [
|
91
|
+
BigDecimal("10.1"),
|
92
|
+
BigDecimal("1.11"),
|
93
|
+
BigDecimal("1"),
|
94
|
+
]
|
95
|
+
array = Arrow::Array.new(values)
|
96
|
+
data_type = Arrow::Decimal128DataType.new(3, 2)
|
97
|
+
assert_equal({
|
98
|
+
data_type: data_type,
|
99
|
+
values: [
|
100
|
+
BigDecimal("10.1"),
|
101
|
+
BigDecimal("1.11"),
|
102
|
+
BigDecimal("1"),
|
103
|
+
],
|
104
|
+
},
|
105
|
+
{
|
106
|
+
data_type: array.value_data_type,
|
107
|
+
values: array.to_a,
|
108
|
+
})
|
109
|
+
end
|
110
|
+
|
111
|
+
test("decimal256") do
|
112
|
+
values = [
|
113
|
+
BigDecimal("1" * 40 + ".1"),
|
114
|
+
BigDecimal("1" * 38 + ".11"),
|
115
|
+
BigDecimal("1" * 37),
|
116
|
+
]
|
117
|
+
array = Arrow::Array.new(values)
|
118
|
+
data_type = Arrow::Decimal256DataType.new(41, 2)
|
119
|
+
assert_equal({
|
120
|
+
data_type: data_type,
|
121
|
+
values: [
|
122
|
+
BigDecimal("1" * 40 + ".1"),
|
123
|
+
BigDecimal("1" * 38 + ".11"),
|
124
|
+
BigDecimal("1" * 37),
|
125
|
+
],
|
126
|
+
},
|
127
|
+
{
|
128
|
+
data_type: array.value_data_type,
|
129
|
+
values: array.to_a,
|
130
|
+
})
|
131
|
+
end
|
132
|
+
|
71
133
|
test("list<boolean>s") do
|
72
134
|
assert_build(Arrow::ArrayBuilder,
|
73
135
|
[
|
data/test/test-chunked-array.rb
CHANGED
@@ -180,4 +180,10 @@ class ChunkedArrayTest < Test::Unit::TestCase
|
|
180
180
|
@chunked_array.take(indices))
|
181
181
|
end
|
182
182
|
end
|
183
|
+
|
184
|
+
test("#cast") do
|
185
|
+
chunked_array = Arrow::ChunkedArray.new([[1, nil, 3]])
|
186
|
+
assert_equal(Arrow::ChunkedArray.new([["1", nil, "3"]]),
|
187
|
+
chunked_array.cast(:string))
|
188
|
+
end
|
183
189
|
end
|
data/test/test-column.rb
CHANGED
@@ -89,4 +89,35 @@ class ColumnTest < Test::Unit::TestCase
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
test("#count") do
|
94
|
+
table = Arrow::Table.new("revenue" => [1, nil, 3])
|
95
|
+
assert_equal(2, table["revenue"].count)
|
96
|
+
end
|
97
|
+
|
98
|
+
test("#min") do
|
99
|
+
table = Arrow::Table.new("revenue" => [1, 2, 3])
|
100
|
+
assert_equal(1, table["revenue"].min)
|
101
|
+
end
|
102
|
+
|
103
|
+
test("#max") do
|
104
|
+
table = Arrow::Table.new("revenue" => [1, 2, 3])
|
105
|
+
assert_equal(3, table["revenue"].max)
|
106
|
+
end
|
107
|
+
|
108
|
+
test("#sum") do
|
109
|
+
table = Arrow::Table.new("revenue" => [1, 2, 3])
|
110
|
+
assert_equal(6, table["revenue"].sum)
|
111
|
+
end
|
112
|
+
|
113
|
+
test("#uniq") do
|
114
|
+
table = Arrow::Table.new("revenue" => [1, 2, 2])
|
115
|
+
assert_equal([1, 2], table["revenue"].uniq)
|
116
|
+
end
|
117
|
+
|
118
|
+
test("#cast") do
|
119
|
+
table = Arrow::Table.new("revenue" => [1, nil, 3])
|
120
|
+
assert_equal(Arrow::ChunkedArray.new([["1", nil, "3"]]),
|
121
|
+
table["revenue"].cast(:string))
|
122
|
+
end
|
92
123
|
end
|
@@ -55,6 +55,20 @@ class Decimal128ArrayBuilderTest < Test::Unit::TestCase
|
|
55
55
|
assert_equal(BigDecimal("10.1"),
|
56
56
|
array[0])
|
57
57
|
end
|
58
|
+
|
59
|
+
test("BigDecimal::NAN") do
|
60
|
+
message = "can't use NaN as an Arrow::Decimal128Array value"
|
61
|
+
assert_raise(FloatDomainError.new(message)) do
|
62
|
+
@builder.append_value(BigDecimal::NAN)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test("BigDecimal::INFINITY") do
|
67
|
+
message = "can't use Infinity as an Arrow::Decimal128Array value"
|
68
|
+
assert_raise(FloatDomainError.new(message)) do
|
69
|
+
@builder.append_value(BigDecimal::INFINITY)
|
70
|
+
end
|
71
|
+
end
|
58
72
|
end
|
59
73
|
|
60
74
|
sub_test_case("#append_values") do
|
@@ -18,19 +18,22 @@
|
|
18
18
|
class Decimal128ArrayTest < Test::Unit::TestCase
|
19
19
|
sub_test_case(".new") do
|
20
20
|
test("build") do
|
21
|
-
data_type = Arrow::Decimal128DataType.new(3, 1)
|
22
21
|
values = [
|
23
22
|
10.1,
|
24
23
|
nil,
|
25
24
|
"10.1",
|
26
25
|
BigDecimal("10.1"),
|
26
|
+
BigDecimal("1.11"),
|
27
|
+
BigDecimal("1"),
|
27
28
|
]
|
28
|
-
array = Arrow::Decimal128Array.new(
|
29
|
+
array = Arrow::Decimal128Array.new({precision: 3, scale: 1}, values)
|
29
30
|
assert_equal([
|
30
31
|
BigDecimal("10.1"),
|
31
32
|
nil,
|
32
33
|
BigDecimal("10.1"),
|
33
34
|
BigDecimal("10.1"),
|
35
|
+
BigDecimal("1.1"),
|
36
|
+
BigDecimal("1"),
|
34
37
|
],
|
35
38
|
array.to_a)
|
36
39
|
end
|