red-arrow 11.0.0 → 12.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/ext/arrow/converters.hpp +12 -27
  4. data/lib/arrow/array-computable.rb +13 -0
  5. data/lib/arrow/data-type.rb +9 -0
  6. data/lib/arrow/dense-union-array-builder.rb +49 -0
  7. data/lib/arrow/dense-union-array.rb +26 -0
  8. data/lib/arrow/loader.rb +5 -0
  9. data/lib/arrow/record-batch-file-reader.rb +2 -0
  10. data/lib/arrow/record-batch-stream-reader.rb +2 -0
  11. data/lib/arrow/scalar.rb +67 -0
  12. data/lib/arrow/slicer.rb +61 -0
  13. data/lib/arrow/sparse-union-array-builder.rb +56 -0
  14. data/lib/arrow/sparse-union-array.rb +26 -0
  15. data/lib/arrow/struct-array-builder.rb +0 -5
  16. data/lib/arrow/table.rb +130 -10
  17. data/lib/arrow/union-array-builder.rb +59 -0
  18. data/lib/arrow/version.rb +1 -1
  19. data/test/raw-records/test-dense-union-array.rb +90 -45
  20. data/test/raw-records/test-list-array.rb +28 -10
  21. data/test/raw-records/test-map-array.rb +39 -10
  22. data/test/raw-records/test-sparse-union-array.rb +86 -41
  23. data/test/raw-records/test-struct-array.rb +22 -8
  24. data/test/test-array.rb +7 -0
  25. data/test/test-chunked-array.rb +9 -0
  26. data/test/test-dense-union-array.rb +42 -0
  27. data/test/test-dense-union-data-type.rb +1 -1
  28. data/test/test-function.rb +7 -7
  29. data/test/test-group.rb +58 -58
  30. data/test/test-record-batch-file-reader.rb +21 -0
  31. data/test/test-record-batch-stream-reader.rb +129 -0
  32. data/test/test-scalar.rb +65 -0
  33. data/test/test-slicer.rb +194 -129
  34. data/test/test-sparse-union-array.rb +38 -0
  35. data/test/test-table.rb +200 -38
  36. data/test/values/test-dense-union-array.rb +88 -45
  37. data/test/values/test-list-array.rb +26 -10
  38. data/test/values/test-map-array.rb +33 -10
  39. data/test/values/test-sparse-union-array.rb +84 -41
  40. data/test/values/test-struct-array.rb +20 -8
  41. metadata +20 -7
@@ -509,13 +509,31 @@ module RawRecordsListArrayTests
509
509
  assert_equal(records, target.raw_records)
510
510
  end
511
511
 
512
- def test_sparse
513
- omit("Need to add support for SparseUnionArrayBuilder")
512
+ def remove_union_field_names(records)
513
+ records.collect do |record|
514
+ record.collect do |column|
515
+ if column.nil?
516
+ column
517
+ else
518
+ column.collect do |value|
519
+ if value.nil?
520
+ value
521
+ else
522
+ value.values[0]
523
+ end
524
+ end
525
+ end
526
+ end
527
+ end
528
+ end
529
+
530
+ def test_sparse_union
514
531
  records = [
515
532
  [
516
533
  [
517
534
  {"field1" => true},
518
535
  nil,
536
+ {"field2" => 29},
519
537
  {"field2" => nil},
520
538
  ],
521
539
  ],
@@ -536,16 +554,17 @@ module RawRecordsListArrayTests
536
554
  type_codes: [0, 1],
537
555
  },
538
556
  records)
539
- assert_equal(records, target.raw_records)
557
+ assert_equal(remove_union_field_names(records),
558
+ target.raw_records)
540
559
  end
541
560
 
542
- def test_dense
543
- omit("Need to add support for DenseUnionArrayBuilder")
561
+ def test_dense_union
544
562
  records = [
545
563
  [
546
564
  [
547
565
  {"field1" => true},
548
566
  nil,
567
+ {"field2" => 29},
549
568
  {"field2" => nil},
550
569
  ],
551
570
  ],
@@ -566,11 +585,11 @@ module RawRecordsListArrayTests
566
585
  type_codes: [0, 1],
567
586
  },
568
587
  records)
569
- assert_equal(records, target.raw_records)
588
+ assert_equal(remove_union_field_names(records),
589
+ target.raw_records)
570
590
  end
571
591
 
572
592
  def test_dictionary
573
- omit("Need to add support for DictionaryArrayBuilder")
574
593
  records = [
575
594
  [
576
595
  [
@@ -581,12 +600,11 @@ module RawRecordsListArrayTests
581
600
  ],
582
601
  [nil],
583
602
  ]
584
- dictionary = Arrow::StringArray.new(["GLib", "Ruby"])
585
603
  target = build({
586
604
  type: :dictionary,
587
605
  index_data_type: :int8,
588
- dictionary: dictionary,
589
- ordered: true,
606
+ value_data_type: :string,
607
+ ordered: false,
590
608
  },
591
609
  records)
592
610
  assert_equal(records, target.raw_records)
@@ -395,10 +395,33 @@ module RawRecordsMapArrayTests
395
395
  assert_equal(records, target.raw_records)
396
396
  end
397
397
 
398
+ def remove_union_field_names(records)
399
+ records.collect do |record|
400
+ record.collect do |column|
401
+ if column.nil?
402
+ column
403
+ else
404
+ value = {}
405
+ column.each do |k, v|
406
+ v = v.values[0] unless v.nil?
407
+ value[k] = v
408
+ end
409
+ value
410
+ end
411
+ end
412
+ end
413
+ end
414
+
398
415
  def test_sparse_union
399
- omit("Need to add support for SparseUnionArrayBuilder")
400
416
  records = [
401
- [{"key1" => {"field" => true, "key2" => nil, "key3" => {"field" => nil}}}],
417
+ [
418
+ {
419
+ "key1" => {"field1" => true},
420
+ "key2" => nil,
421
+ "key3" => {"field2" => 29},
422
+ "key4" => {"field2" => nil},
423
+ },
424
+ ],
402
425
  [nil],
403
426
  ]
404
427
  target = build({
@@ -416,13 +439,20 @@ module RawRecordsMapArrayTests
416
439
  type_codes: [0, 1],
417
440
  },
418
441
  records)
419
- assert_equal(records, target.raw_records)
442
+ assert_equal(remove_union_field_names(records),
443
+ target.raw_records)
420
444
  end
421
445
 
422
446
  def test_dense_union
423
- omit("Need to add support for DenseUnionArrayBuilder")
424
447
  records = [
425
- [{"key1" => {"field1" => true}, "key2" => nil, "key3" => {"field2" => nil}}],
448
+ [
449
+ {
450
+ "key1" => {"field1" => true},
451
+ "key2" => nil,
452
+ "key3" => {"field2" => 29},
453
+ "key4" => {"field2" => nil},
454
+ },
455
+ ],
426
456
  [nil],
427
457
  ]
428
458
  target = build({
@@ -440,21 +470,20 @@ module RawRecordsMapArrayTests
440
470
  type_codes: [0, 1],
441
471
  },
442
472
  records)
443
- assert_equal(records, target.raw_records)
473
+ assert_equal(remove_union_field_names(records),
474
+ target.raw_records)
444
475
  end
445
476
 
446
477
  def test_dictionary
447
- omit("Need to add support for DictionaryArrayBuilder")
448
478
  records = [
449
479
  [{"key1" => "Ruby", "key2" => nil, "key3" => "GLib"}],
450
480
  [nil],
451
481
  ]
452
- dictionary = Arrow::StringArray.new(["GLib", "Ruby"])
453
482
  target = build({
454
483
  type: :dictionary,
455
484
  index_data_type: :int8,
456
- dictionary: dictionary,
457
- ordered: true,
485
+ value_data_type: :string,
486
+ ordered: false,
458
487
  },
459
488
  records)
460
489
  assert_equal(records, target.raw_records)
@@ -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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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, target.raw_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
- dictionary: dictionary,
490
- ordered: true,
533
+ value_data_type: :string,
534
+ ordered: false,
491
535
  },
492
536
  records)
493
- assert_equal(records, target.raw_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, target.raw_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, target.raw_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
- dictionary: dictionary,
494
- ordered: true,
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
@@ -322,4 +322,11 @@ class ArrayTest < Test::Unit::TestCase
322
322
  end
323
323
  end
324
324
  end
325
+
326
+ sub_test_case("#index") do
327
+ test("Integer") do
328
+ assert_equal(2,
329
+ Arrow::Int32Array.new([1, 2, 3, 4, 5]).index(3))
330
+ end
331
+ end
325
332
  end
@@ -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
@@ -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