red-arrow 10.0.0 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/ext/arrow/arrow.cpp +31 -0
- data/ext/arrow/converters.hpp +45 -41
- data/ext/arrow/extconf.rb +16 -4
- data/ext/arrow/raw-records.cpp +155 -2
- data/ext/arrow/red-arrow.hpp +2 -0
- data/ext/arrow/values.cpp +1 -2
- data/lib/arrow/array-computable.rb +13 -0
- data/lib/arrow/array.rb +6 -1
- data/lib/arrow/chunked-array.rb +35 -1
- data/lib/arrow/column-containable.rb +9 -0
- data/lib/arrow/column.rb +1 -0
- data/lib/arrow/data-type.rb +9 -0
- data/lib/arrow/dense-union-array-builder.rb +49 -0
- data/lib/arrow/dense-union-array.rb +26 -0
- data/lib/arrow/expression.rb +6 -2
- data/lib/arrow/function.rb +0 -1
- data/lib/arrow/half-float-array-builder.rb +32 -0
- data/lib/arrow/half-float-array.rb +24 -0
- data/lib/arrow/half-float.rb +118 -0
- data/lib/arrow/input-referable.rb +29 -0
- data/lib/arrow/loader.rb +11 -0
- data/lib/arrow/raw-table-converter.rb +7 -5
- data/lib/arrow/record-batch-file-reader.rb +2 -0
- data/lib/arrow/record-batch-stream-reader.rb +2 -0
- data/lib/arrow/record-batch.rb +6 -2
- data/lib/arrow/scalar.rb +67 -0
- data/lib/arrow/slicer.rb +61 -0
- data/lib/arrow/sort-key.rb +3 -3
- data/lib/arrow/sparse-union-array-builder.rb +56 -0
- data/lib/arrow/sparse-union-array.rb +26 -0
- data/lib/arrow/struct-array-builder.rb +0 -5
- data/lib/arrow/table-loader.rb +11 -5
- data/lib/arrow/table-saver.rb +1 -0
- data/lib/arrow/table.rb +180 -33
- data/lib/arrow/tensor.rb +4 -0
- data/lib/arrow/timestamp-parser.rb +33 -0
- data/lib/arrow/union-array-builder.rb +59 -0
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +2 -1
- data/test/each-raw-record/test-basic-arrays.rb +411 -0
- data/test/each-raw-record/test-dense-union-array.rb +566 -0
- data/test/each-raw-record/test-dictionary-array.rb +341 -0
- data/test/each-raw-record/test-list-array.rb +628 -0
- data/test/each-raw-record/test-map-array.rb +507 -0
- data/test/each-raw-record/test-multiple-columns.rb +72 -0
- data/test/each-raw-record/test-sparse-union-array.rb +528 -0
- data/test/each-raw-record/test-struct-array.rb +529 -0
- data/test/each-raw-record/test-table.rb +47 -0
- data/test/helper/omittable.rb +13 -0
- data/test/helper.rb +1 -0
- data/test/raw-records/test-basic-arrays.rb +11 -1
- data/test/raw-records/test-dense-union-array.rb +90 -45
- data/test/raw-records/test-list-array.rb +28 -10
- data/test/raw-records/test-map-array.rb +39 -10
- data/test/raw-records/test-sparse-union-array.rb +86 -41
- data/test/raw-records/test-struct-array.rb +22 -8
- data/test/test-array.rb +7 -0
- data/test/test-chunked-array.rb +9 -0
- data/test/test-csv-loader.rb +39 -0
- data/test/test-data-type.rb +2 -1
- data/test/test-dense-union-array.rb +42 -0
- data/test/test-dense-union-data-type.rb +1 -1
- data/test/test-expression.rb +11 -0
- data/test/test-function.rb +7 -7
- data/test/test-group.rb +58 -58
- data/test/test-half-float-array.rb +43 -0
- data/test/test-half-float.rb +130 -0
- data/test/test-ractor.rb +34 -0
- data/test/test-record-batch-file-reader.rb +21 -0
- data/test/test-record-batch-stream-reader.rb +129 -0
- data/test/test-scalar.rb +65 -0
- data/test/test-slicer.rb +194 -129
- data/test/test-sparse-union-array.rb +38 -0
- data/test/test-table.rb +356 -40
- data/test/values/test-basic-arrays.rb +10 -0
- data/test/values/test-dense-union-array.rb +88 -45
- data/test/values/test-list-array.rb +26 -10
- data/test/values/test-map-array.rb +33 -10
- data/test/values/test-sparse-union-array.rb +84 -41
- data/test/values/test-struct-array.rb +20 -8
- metadata +62 -9
@@ -66,12 +66,25 @@ module RawRecordsSparseUnionArrayTests
|
|
66
66
|
[union_array])
|
67
67
|
end
|
68
68
|
|
69
|
+
def remove_field_names(records)
|
70
|
+
records.collect do |record|
|
71
|
+
record.collect do |column|
|
72
|
+
if column.nil?
|
73
|
+
column
|
74
|
+
else
|
75
|
+
column.values[0]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
69
81
|
def test_null
|
70
82
|
records = [
|
71
83
|
[{"0" => nil}],
|
72
84
|
]
|
73
85
|
target = build(:null, records)
|
74
|
-
assert_equal(records,
|
86
|
+
assert_equal(remove_field_names(records),
|
87
|
+
target.raw_records)
|
75
88
|
end
|
76
89
|
|
77
90
|
def test_boolean
|
@@ -80,7 +93,8 @@ module RawRecordsSparseUnionArrayTests
|
|
80
93
|
[{"1" => nil}],
|
81
94
|
]
|
82
95
|
target = build(:boolean, records)
|
83
|
-
assert_equal(records,
|
96
|
+
assert_equal(remove_field_names(records),
|
97
|
+
target.raw_records)
|
84
98
|
end
|
85
99
|
|
86
100
|
def test_int8
|
@@ -89,7 +103,8 @@ module RawRecordsSparseUnionArrayTests
|
|
89
103
|
[{"1" => nil}],
|
90
104
|
]
|
91
105
|
target = build(:int8, records)
|
92
|
-
assert_equal(records,
|
106
|
+
assert_equal(remove_field_names(records),
|
107
|
+
target.raw_records)
|
93
108
|
end
|
94
109
|
|
95
110
|
def test_uint8
|
@@ -98,7 +113,8 @@ module RawRecordsSparseUnionArrayTests
|
|
98
113
|
[{"1" => nil}],
|
99
114
|
]
|
100
115
|
target = build(:uint8, records)
|
101
|
-
assert_equal(records,
|
116
|
+
assert_equal(remove_field_names(records),
|
117
|
+
target.raw_records)
|
102
118
|
end
|
103
119
|
|
104
120
|
def test_int16
|
@@ -107,7 +123,8 @@ module RawRecordsSparseUnionArrayTests
|
|
107
123
|
[{"1" => nil}],
|
108
124
|
]
|
109
125
|
target = build(:int16, records)
|
110
|
-
assert_equal(records,
|
126
|
+
assert_equal(remove_field_names(records),
|
127
|
+
target.raw_records)
|
111
128
|
end
|
112
129
|
|
113
130
|
def test_uint16
|
@@ -116,7 +133,8 @@ module RawRecordsSparseUnionArrayTests
|
|
116
133
|
[{"1" => nil}],
|
117
134
|
]
|
118
135
|
target = build(:uint16, records)
|
119
|
-
assert_equal(records,
|
136
|
+
assert_equal(remove_field_names(records),
|
137
|
+
target.raw_records)
|
120
138
|
end
|
121
139
|
|
122
140
|
def test_int32
|
@@ -125,7 +143,8 @@ module RawRecordsSparseUnionArrayTests
|
|
125
143
|
[{"1" => nil}],
|
126
144
|
]
|
127
145
|
target = build(:int32, records)
|
128
|
-
assert_equal(records,
|
146
|
+
assert_equal(remove_field_names(records),
|
147
|
+
target.raw_records)
|
129
148
|
end
|
130
149
|
|
131
150
|
def test_uint32
|
@@ -134,7 +153,8 @@ module RawRecordsSparseUnionArrayTests
|
|
134
153
|
[{"1" => nil}],
|
135
154
|
]
|
136
155
|
target = build(:uint32, records)
|
137
|
-
assert_equal(records,
|
156
|
+
assert_equal(remove_field_names(records),
|
157
|
+
target.raw_records)
|
138
158
|
end
|
139
159
|
|
140
160
|
def test_int64
|
@@ -143,7 +163,8 @@ module RawRecordsSparseUnionArrayTests
|
|
143
163
|
[{"1" => nil}],
|
144
164
|
]
|
145
165
|
target = build(:int64, records)
|
146
|
-
assert_equal(records,
|
166
|
+
assert_equal(remove_field_names(records),
|
167
|
+
target.raw_records)
|
147
168
|
end
|
148
169
|
|
149
170
|
def test_uint64
|
@@ -152,7 +173,8 @@ module RawRecordsSparseUnionArrayTests
|
|
152
173
|
[{"1" => nil}],
|
153
174
|
]
|
154
175
|
target = build(:uint64, records)
|
155
|
-
assert_equal(records,
|
176
|
+
assert_equal(remove_field_names(records),
|
177
|
+
target.raw_records)
|
156
178
|
end
|
157
179
|
|
158
180
|
def test_float
|
@@ -161,7 +183,8 @@ module RawRecordsSparseUnionArrayTests
|
|
161
183
|
[{"1" => nil}],
|
162
184
|
]
|
163
185
|
target = build(:float, records)
|
164
|
-
assert_equal(records,
|
186
|
+
assert_equal(remove_field_names(records),
|
187
|
+
target.raw_records)
|
165
188
|
end
|
166
189
|
|
167
190
|
def test_double
|
@@ -170,7 +193,8 @@ module RawRecordsSparseUnionArrayTests
|
|
170
193
|
[{"1" => nil}],
|
171
194
|
]
|
172
195
|
target = build(:double, records)
|
173
|
-
assert_equal(records,
|
196
|
+
assert_equal(remove_field_names(records),
|
197
|
+
target.raw_records)
|
174
198
|
end
|
175
199
|
|
176
200
|
def test_binary
|
@@ -179,7 +203,8 @@ module RawRecordsSparseUnionArrayTests
|
|
179
203
|
[{"1" => nil}],
|
180
204
|
]
|
181
205
|
target = build(:binary, records)
|
182
|
-
assert_equal(records,
|
206
|
+
assert_equal(remove_field_names(records),
|
207
|
+
target.raw_records)
|
183
208
|
end
|
184
209
|
|
185
210
|
def test_string
|
@@ -188,7 +213,8 @@ module RawRecordsSparseUnionArrayTests
|
|
188
213
|
[{"1" => nil}],
|
189
214
|
]
|
190
215
|
target = build(:string, records)
|
191
|
-
assert_equal(records,
|
216
|
+
assert_equal(remove_field_names(records),
|
217
|
+
target.raw_records)
|
192
218
|
end
|
193
219
|
|
194
220
|
def test_date32
|
@@ -197,7 +223,8 @@ module RawRecordsSparseUnionArrayTests
|
|
197
223
|
[{"1" => nil}],
|
198
224
|
]
|
199
225
|
target = build(:date32, records)
|
200
|
-
assert_equal(records,
|
226
|
+
assert_equal(remove_field_names(records),
|
227
|
+
target.raw_records)
|
201
228
|
end
|
202
229
|
|
203
230
|
def test_date64
|
@@ -206,7 +233,8 @@ module RawRecordsSparseUnionArrayTests
|
|
206
233
|
[{"1" => nil}],
|
207
234
|
]
|
208
235
|
target = build(:date64, records)
|
209
|
-
assert_equal(records,
|
236
|
+
assert_equal(remove_field_names(records),
|
237
|
+
target.raw_records)
|
210
238
|
end
|
211
239
|
|
212
240
|
def test_timestamp_second
|
@@ -219,7 +247,8 @@ module RawRecordsSparseUnionArrayTests
|
|
219
247
|
unit: :second,
|
220
248
|
},
|
221
249
|
records)
|
222
|
-
assert_equal(records,
|
250
|
+
assert_equal(remove_field_names(records),
|
251
|
+
target.raw_records)
|
223
252
|
end
|
224
253
|
|
225
254
|
def test_timestamp_milli
|
@@ -232,7 +261,8 @@ module RawRecordsSparseUnionArrayTests
|
|
232
261
|
unit: :milli,
|
233
262
|
},
|
234
263
|
records)
|
235
|
-
assert_equal(records,
|
264
|
+
assert_equal(remove_field_names(records),
|
265
|
+
target.raw_records)
|
236
266
|
end
|
237
267
|
|
238
268
|
def test_timestamp_micro
|
@@ -245,7 +275,8 @@ module RawRecordsSparseUnionArrayTests
|
|
245
275
|
unit: :micro,
|
246
276
|
},
|
247
277
|
records)
|
248
|
-
assert_equal(records,
|
278
|
+
assert_equal(remove_field_names(records),
|
279
|
+
target.raw_records)
|
249
280
|
end
|
250
281
|
|
251
282
|
def test_timestamp_nano
|
@@ -258,7 +289,8 @@ module RawRecordsSparseUnionArrayTests
|
|
258
289
|
unit: :nano,
|
259
290
|
},
|
260
291
|
records)
|
261
|
-
assert_equal(records,
|
292
|
+
assert_equal(remove_field_names(records),
|
293
|
+
target.raw_records)
|
262
294
|
end
|
263
295
|
|
264
296
|
def test_time32_second
|
@@ -273,7 +305,8 @@ module RawRecordsSparseUnionArrayTests
|
|
273
305
|
unit: :second,
|
274
306
|
},
|
275
307
|
records)
|
276
|
-
assert_equal(records,
|
308
|
+
assert_equal(remove_field_names(records),
|
309
|
+
target.raw_records)
|
277
310
|
end
|
278
311
|
|
279
312
|
def test_time32_milli
|
@@ -288,7 +321,8 @@ module RawRecordsSparseUnionArrayTests
|
|
288
321
|
unit: :milli,
|
289
322
|
},
|
290
323
|
records)
|
291
|
-
assert_equal(records,
|
324
|
+
assert_equal(remove_field_names(records),
|
325
|
+
target.raw_records)
|
292
326
|
end
|
293
327
|
|
294
328
|
def test_time64_micro
|
@@ -303,7 +337,8 @@ module RawRecordsSparseUnionArrayTests
|
|
303
337
|
unit: :micro,
|
304
338
|
},
|
305
339
|
records)
|
306
|
-
assert_equal(records,
|
340
|
+
assert_equal(remove_field_names(records),
|
341
|
+
target.raw_records)
|
307
342
|
end
|
308
343
|
|
309
344
|
def test_time64_nano
|
@@ -318,7 +353,8 @@ module RawRecordsSparseUnionArrayTests
|
|
318
353
|
unit: :nano,
|
319
354
|
},
|
320
355
|
records)
|
321
|
-
assert_equal(records,
|
356
|
+
assert_equal(remove_field_names(records),
|
357
|
+
target.raw_records)
|
322
358
|
end
|
323
359
|
|
324
360
|
def test_decimal128
|
@@ -332,7 +368,8 @@ module RawRecordsSparseUnionArrayTests
|
|
332
368
|
scale: 2,
|
333
369
|
},
|
334
370
|
records)
|
335
|
-
assert_equal(records,
|
371
|
+
assert_equal(remove_field_names(records),
|
372
|
+
target.raw_records)
|
336
373
|
end
|
337
374
|
|
338
375
|
def test_decimal256
|
@@ -346,7 +383,8 @@ module RawRecordsSparseUnionArrayTests
|
|
346
383
|
scale: 2,
|
347
384
|
},
|
348
385
|
records)
|
349
|
-
assert_equal(records,
|
386
|
+
assert_equal(remove_field_names(records),
|
387
|
+
target.raw_records)
|
350
388
|
end
|
351
389
|
|
352
390
|
def test_month_interval
|
@@ -355,7 +393,8 @@ module RawRecordsSparseUnionArrayTests
|
|
355
393
|
[{"1" => nil}],
|
356
394
|
]
|
357
395
|
target = build(:month_interval, records)
|
358
|
-
assert_equal(records,
|
396
|
+
assert_equal(remove_field_names(records),
|
397
|
+
target.raw_records)
|
359
398
|
end
|
360
399
|
|
361
400
|
def test_day_time_interval
|
@@ -364,7 +403,8 @@ module RawRecordsSparseUnionArrayTests
|
|
364
403
|
[{"1" => nil}],
|
365
404
|
]
|
366
405
|
target = build(:day_time_interval, records)
|
367
|
-
assert_equal(records,
|
406
|
+
assert_equal(remove_field_names(records),
|
407
|
+
target.raw_records)
|
368
408
|
end
|
369
409
|
|
370
410
|
def test_month_day_nano_interval
|
@@ -373,7 +413,8 @@ module RawRecordsSparseUnionArrayTests
|
|
373
413
|
[{"1" => nil}],
|
374
414
|
]
|
375
415
|
target = build(:month_day_nano_interval, records)
|
376
|
-
assert_equal(records,
|
416
|
+
assert_equal(remove_field_names(records),
|
417
|
+
target.raw_records)
|
377
418
|
end
|
378
419
|
|
379
420
|
def test_list
|
@@ -389,7 +430,8 @@ module RawRecordsSparseUnionArrayTests
|
|
389
430
|
},
|
390
431
|
},
|
391
432
|
records)
|
392
|
-
assert_equal(records,
|
433
|
+
assert_equal(remove_field_names(records),
|
434
|
+
target.raw_records)
|
393
435
|
end
|
394
436
|
|
395
437
|
def test_struct
|
@@ -408,7 +450,8 @@ module RawRecordsSparseUnionArrayTests
|
|
408
450
|
],
|
409
451
|
},
|
410
452
|
records)
|
411
|
-
assert_equal(records,
|
453
|
+
assert_equal(remove_field_names(records),
|
454
|
+
target.raw_records)
|
412
455
|
end
|
413
456
|
|
414
457
|
def test_map
|
@@ -422,14 +465,15 @@ module RawRecordsSparseUnionArrayTests
|
|
422
465
|
item: :boolean,
|
423
466
|
},
|
424
467
|
records)
|
425
|
-
assert_equal(records,
|
468
|
+
assert_equal(remove_field_names(records),
|
469
|
+
target.raw_records)
|
426
470
|
end
|
427
471
|
|
428
472
|
def test_sparse_union
|
429
|
-
omit("Need to add support for SparseUnionArrayBuilder")
|
430
473
|
records = [
|
431
474
|
[{"0" => {"field1" => true}}],
|
432
475
|
[{"1" => nil}],
|
476
|
+
[{"0" => {"field2" => 29}}],
|
433
477
|
[{"0" => {"field2" => nil}}],
|
434
478
|
]
|
435
479
|
target = build({
|
@@ -447,14 +491,15 @@ module RawRecordsSparseUnionArrayTests
|
|
447
491
|
type_codes: [0, 1],
|
448
492
|
},
|
449
493
|
records)
|
450
|
-
assert_equal(records,
|
494
|
+
assert_equal(remove_field_names(remove_field_names(records)),
|
495
|
+
target.raw_records)
|
451
496
|
end
|
452
497
|
|
453
498
|
def test_dense_union
|
454
|
-
omit("Need to add support for DenseUnionArrayBuilder")
|
455
499
|
records = [
|
456
500
|
[{"0" => {"field1" => true}}],
|
457
501
|
[{"1" => nil}],
|
502
|
+
[{"0" => {"field2" => 29}}],
|
458
503
|
[{"0" => {"field2" => nil}}],
|
459
504
|
]
|
460
505
|
target = build({
|
@@ -472,25 +517,25 @@ module RawRecordsSparseUnionArrayTests
|
|
472
517
|
type_codes: [0, 1],
|
473
518
|
},
|
474
519
|
records)
|
475
|
-
assert_equal(records,
|
520
|
+
assert_equal(remove_field_names(remove_field_names(records)),
|
521
|
+
target.raw_records)
|
476
522
|
end
|
477
523
|
|
478
524
|
def test_dictionary
|
479
|
-
omit("Need to add support for DictionaryArrayBuilder")
|
480
525
|
records = [
|
481
526
|
[{"0" => "Ruby"}],
|
482
527
|
[{"1" => nil}],
|
483
528
|
[{"0" => "GLib"}],
|
484
529
|
]
|
485
|
-
dictionary = Arrow::StringArray.new(["GLib", "Ruby"])
|
486
530
|
target = build({
|
487
531
|
type: :dictionary,
|
488
532
|
index_data_type: :int8,
|
489
|
-
|
490
|
-
ordered:
|
533
|
+
value_data_type: :string,
|
534
|
+
ordered: false,
|
491
535
|
},
|
492
536
|
records)
|
493
|
-
assert_equal(records,
|
537
|
+
assert_equal(remove_field_names(records),
|
538
|
+
target.raw_records)
|
494
539
|
end
|
495
540
|
end
|
496
541
|
|
@@ -426,12 +426,26 @@ module RawRecordsStructArrayTests
|
|
426
426
|
assert_equal(records, target.raw_records)
|
427
427
|
end
|
428
428
|
|
429
|
+
def remove_union_field_names(records)
|
430
|
+
records.collect do |record|
|
431
|
+
record.collect do |column|
|
432
|
+
if column.nil?
|
433
|
+
column
|
434
|
+
else
|
435
|
+
value = column["field"]
|
436
|
+
value = value.values[0] unless value.nil?
|
437
|
+
{"field" => value}
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
429
443
|
def test_sparse_union
|
430
|
-
omit("Need to add support for SparseUnionArrayBuilder")
|
431
444
|
records = [
|
432
445
|
[{"field" => {"field1" => true}}],
|
433
446
|
[nil],
|
434
447
|
[{"field" => nil}],
|
448
|
+
[{"field" => {"field2" => 29}}],
|
435
449
|
[{"field" => {"field2" => nil}}],
|
436
450
|
]
|
437
451
|
target = build({
|
@@ -449,15 +463,16 @@ module RawRecordsStructArrayTests
|
|
449
463
|
type_codes: [0, 1],
|
450
464
|
},
|
451
465
|
records)
|
452
|
-
assert_equal(records,
|
466
|
+
assert_equal(remove_union_field_names(records),
|
467
|
+
target.raw_records)
|
453
468
|
end
|
454
469
|
|
455
470
|
def test_dense_union
|
456
|
-
omit("Need to add support for DenseUnionArrayBuilder")
|
457
471
|
records = [
|
458
472
|
[{"field" => {"field1" => true}}],
|
459
473
|
[nil],
|
460
474
|
[{"field" => nil}],
|
475
|
+
[{"field" => {"field2" => 29}}],
|
461
476
|
[{"field" => {"field2" => nil}}],
|
462
477
|
]
|
463
478
|
target = build({
|
@@ -475,23 +490,22 @@ module RawRecordsStructArrayTests
|
|
475
490
|
type_codes: [0, 1],
|
476
491
|
},
|
477
492
|
records)
|
478
|
-
assert_equal(records,
|
493
|
+
assert_equal(remove_union_field_names(records),
|
494
|
+
target.raw_records)
|
479
495
|
end
|
480
496
|
|
481
497
|
def test_dictionary
|
482
|
-
omit("Need to add support for DictionaryArrayBuilder")
|
483
498
|
records = [
|
484
499
|
[{"field" => "Ruby"}],
|
485
500
|
[nil],
|
486
501
|
[{"field" => nil}],
|
487
502
|
[{"field" => "GLib"}],
|
488
503
|
]
|
489
|
-
dictionary = Arrow::StringArray.new(["GLib", "Ruby"])
|
490
504
|
target = build({
|
491
505
|
type: :dictionary,
|
492
506
|
index_data_type: :int8,
|
493
|
-
|
494
|
-
ordered:
|
507
|
+
value_data_type: :string,
|
508
|
+
ordered: false,
|
495
509
|
},
|
496
510
|
records)
|
497
511
|
assert_equal(records, target.raw_records)
|
data/test/test-array.rb
CHANGED
data/test/test-chunked-array.rb
CHANGED
@@ -186,4 +186,13 @@ class ChunkedArrayTest < Test::Unit::TestCase
|
|
186
186
|
assert_equal(Arrow::ChunkedArray.new([["1", nil, "3"]]),
|
187
187
|
chunked_array.cast(:string))
|
188
188
|
end
|
189
|
+
|
190
|
+
test("#index") do
|
191
|
+
arrays = [
|
192
|
+
Arrow::Int32Array.new([1, 2]),
|
193
|
+
Arrow::Int32Array.new([3, 4, 5]),
|
194
|
+
]
|
195
|
+
chunked_array = Arrow::ChunkedArray.new(arrays)
|
196
|
+
assert_equal(2, chunked_array.index(3))
|
197
|
+
end
|
189
198
|
end
|
data/test/test-csv-loader.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
|
18
18
|
class CSVLoaderTest < Test::Unit::TestCase
|
19
19
|
include Helper::Fixture
|
20
|
+
include Helper::Omittable
|
20
21
|
|
21
22
|
def load_csv(input)
|
22
23
|
Arrow::CSVLoader.load(input, skip_lines: /^#/)
|
@@ -246,5 +247,43 @@ count
|
|
246
247
|
encoding: encoding,
|
247
248
|
compression: :gzip))
|
248
249
|
end
|
250
|
+
|
251
|
+
sub_test_case(":timestamp_parsers") do
|
252
|
+
test(":iso8601") do
|
253
|
+
require_glib(2, 58, 0)
|
254
|
+
data_type = Arrow::TimestampDataType.new(:second,
|
255
|
+
GLib::TimeZone.new("UTC"))
|
256
|
+
timestamps = [
|
257
|
+
Time.iso8601("2024-03-16T23:54:12Z"),
|
258
|
+
Time.iso8601("2024-03-16T23:54:13Z"),
|
259
|
+
Time.iso8601("2024-03-16T23:54:14Z"),
|
260
|
+
]
|
261
|
+
values = Arrow::TimestampArray.new(data_type, timestamps)
|
262
|
+
assert_equal(Arrow::Table.new(value: values),
|
263
|
+
load_csv(<<-CSV, headers: true, timestamp_parsers: [:iso8601]))
|
264
|
+
value
|
265
|
+
#{timestamps[0].iso8601}
|
266
|
+
#{timestamps[1].iso8601}
|
267
|
+
#{timestamps[2].iso8601}
|
268
|
+
CSV
|
269
|
+
end
|
270
|
+
|
271
|
+
test("String") do
|
272
|
+
timestamps = [
|
273
|
+
Time.iso8601("2024-03-16T23:54:12Z"),
|
274
|
+
Time.iso8601("2024-03-16T23:54:13Z"),
|
275
|
+
Time.iso8601("2024-03-16T23:54:14Z"),
|
276
|
+
]
|
277
|
+
values = Arrow::TimestampArray.new(:second, timestamps)
|
278
|
+
format = "%Y-%m-%dT%H:%M:%S"
|
279
|
+
assert_equal(Arrow::Table.new(value: values).schema,
|
280
|
+
load_csv(<<-CSV, headers: true, timestamp_parsers: [format]).schema)
|
281
|
+
value
|
282
|
+
#{timestamps[0].iso8601.chomp("Z")}
|
283
|
+
#{timestamps[1].iso8601.chomp("Z")}
|
284
|
+
#{timestamps[2].iso8601.chomp("Z")}
|
285
|
+
CSV
|
286
|
+
end
|
287
|
+
end
|
249
288
|
end
|
250
289
|
end
|
data/test/test-data-type.rb
CHANGED
@@ -54,7 +54,8 @@ class DataTypeTest < Test::Unit::TestCase
|
|
54
54
|
"abstract type: <:floating_point>: " +
|
55
55
|
"use one of not abstract type: [" +
|
56
56
|
"Arrow::DoubleDataType, " +
|
57
|
-
"Arrow::FloatDataType
|
57
|
+
"Arrow::FloatDataType, " +
|
58
|
+
"Arrow::HalfFloatDataType]"
|
58
59
|
assert_raise(ArgumentError.new(message)) do
|
59
60
|
Arrow::DataType.resolve(:floating_point)
|
60
61
|
end
|
@@ -0,0 +1,42 @@
|
|
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 DenseUnionArrayTest < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
data_type_fields = [
|
21
|
+
Arrow::Field.new("number", :int16),
|
22
|
+
Arrow::Field.new("text", :string),
|
23
|
+
]
|
24
|
+
type_codes = [11, 13]
|
25
|
+
@data_type = Arrow::DenseUnionDataType.new(data_type_fields, type_codes)
|
26
|
+
type_ids = Arrow::Int8Array.new([11, 13, 11, 13, 13])
|
27
|
+
value_offsets = Arrow::Int32Array.new([0, 0, 1, 1, 2])
|
28
|
+
fields = [
|
29
|
+
Arrow::Int16Array.new([1, nil]),
|
30
|
+
Arrow::StringArray.new(["a", "b", "c"])
|
31
|
+
]
|
32
|
+
@array = Arrow::DenseUnionArray.new(@data_type,
|
33
|
+
type_ids,
|
34
|
+
value_offsets,
|
35
|
+
fields)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_get_value
|
39
|
+
assert_equal([1, "a", nil, "b", "c"],
|
40
|
+
@array.length.times.collect {|i| @array[i]})
|
41
|
+
end
|
42
|
+
end
|
@@ -35,7 +35,7 @@ class DenseUnionDataTypeTest < Test::Unit::TestCase
|
|
35
35
|
test("description") do
|
36
36
|
assert_equal("dense_union<visible: bool=2, count: int32=9>",
|
37
37
|
Arrow::DenseUnionDataType.new(fields: @fields,
|
38
|
-
|
38
|
+
type_codes: [2, 9]).to_s)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/test/test-expression.rb
CHANGED
@@ -36,5 +36,16 @@ class TestExpression < Test::Unit::TestCase
|
|
36
36
|
assert_equal(Arrow::CallExpression.new("func", ["argument1"]),
|
37
37
|
Arrow::Expression.try_convert(["func", "argument1"]))
|
38
38
|
end
|
39
|
+
|
40
|
+
test("[Symbol, String, Hash]") do
|
41
|
+
options = Arrow::MatchSubstringOptions.new
|
42
|
+
options.pattern = "hello"
|
43
|
+
assert_equal(Arrow::CallExpression.new("match_substring",
|
44
|
+
["content"],
|
45
|
+
options),
|
46
|
+
Arrow::Expression.try_convert([:match_substring,
|
47
|
+
"content",
|
48
|
+
{pattern: "hello"}]))
|
49
|
+
end
|
39
50
|
end
|
40
51
|
end
|
data/test/test-function.rb
CHANGED
@@ -199,12 +199,12 @@ class FunctionTest < Test::Unit::TestCase
|
|
199
199
|
end
|
200
200
|
|
201
201
|
def test_call
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
202
|
+
or_function = Arrow::Function.find("or")
|
203
|
+
args = [
|
204
|
+
Arrow::BooleanArray.new([true, false, false]),
|
205
|
+
Arrow::BooleanArray.new([true, false, true]),
|
206
|
+
]
|
207
|
+
assert_equal([true, false, true],
|
208
|
+
or_function.call(args).value.to_a)
|
209
209
|
end
|
210
210
|
end
|