red-arrow 23.0.1 → 25.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/arrow/arrow.cpp +36 -0
- data/ext/arrow/converters.cpp +5 -0
- data/ext/arrow/converters.hpp +148 -6
- data/ext/arrow/memory-view.cpp +3 -6
- data/ext/arrow/raw-records.cpp +10 -0
- data/ext/arrow/values.cpp +4 -0
- data/lib/arrow/column-containable.rb +65 -0
- data/lib/arrow/column.rb +4 -0
- data/lib/arrow/dense-union-array.rb +1 -1
- data/lib/arrow/fixed-size-list-data-type.rb +118 -0
- data/lib/arrow/libraries.rb +2 -0
- data/lib/arrow/record-batch.rb +27 -1
- data/lib/arrow/sort-key.rb +121 -45
- data/lib/arrow/sort-options.rb +2 -2
- data/lib/arrow/sparse-union-array.rb +1 -1
- data/lib/arrow/table-formatter.rb +5 -1
- data/lib/arrow/table-saver.rb +3 -3
- data/lib/arrow/table.rb +0 -54
- data/lib/arrow/union-array.rb +26 -0
- data/lib/arrow/version.rb +1 -1
- data/red-arrow.gemspec +3 -1
- metadata +21 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3bcc0a7ed27a0a90f4a3675b42017107c61d4d5bdb95967accc6f10369bfc288
|
|
4
|
+
data.tar.gz: 73c43b33827350528691b2619574e943a6a56a9c643c4407b8bc25285fb2353f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 371fd9f9865dbe7977fbdd2efa2ca0b7dacd22bcb78cc8fd37c2609a5d8843a7335a5ef873caaadfac205ed56fd6eef8ffbee61499a22cd6a3ec16682d82029e
|
|
7
|
+
data.tar.gz: dc3a6e2e97b9c63af48663dd6d8ee0e8d73348a148c02ae66746dbda93cc2983cd5a97b84c88c784dc7ca513d6e918d3dccf9a13a3a15aabf12c7e8cc4f00acc
|
data/ext/arrow/arrow.cpp
CHANGED
|
@@ -63,6 +63,36 @@ namespace red_arrow {
|
|
|
63
63
|
rbgobj_gc_mark_instance(node->data);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
void
|
|
68
|
+
call_expression_mark(gpointer object)
|
|
69
|
+
{
|
|
70
|
+
auto expression = GARROW_CALL_EXPRESSION(object);
|
|
71
|
+
auto arguments = garrow_call_expression_get_arguments(expression);
|
|
72
|
+
for (auto argument = arguments; argument; argument = g_list_next(argument)) {
|
|
73
|
+
rbgobj_gc_mark_instance(argument->data);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
void
|
|
78
|
+
aggregate_node_options_mark(gpointer object)
|
|
79
|
+
{
|
|
80
|
+
auto options = GARROW_AGGREGATE_NODE_OPTIONS(object);
|
|
81
|
+
auto aggregations = garrow_aggregate_node_options_get_aggregations(options);
|
|
82
|
+
for (auto aggregation = aggregations; aggregation; aggregation = g_list_next(aggregation)) {
|
|
83
|
+
rbgobj_gc_mark_instance(aggregation->data);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void
|
|
88
|
+
project_node_options_mark(gpointer object)
|
|
89
|
+
{
|
|
90
|
+
auto options = GARROW_PROJECT_NODE_OPTIONS(object);
|
|
91
|
+
auto expressions = garrow_project_node_options_get_expressions(options);
|
|
92
|
+
for (auto expression = expressions; expression; expression = g_list_next(expression)) {
|
|
93
|
+
rbgobj_gc_mark_instance(expression->data);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
66
96
|
}
|
|
67
97
|
|
|
68
98
|
extern "C" void Init_arrow() {
|
|
@@ -124,4 +154,10 @@ extern "C" void Init_arrow() {
|
|
|
124
154
|
red_arrow::record_batch_reader_mark);
|
|
125
155
|
rbgobj_register_mark_func(GARROW_TYPE_EXECUTE_PLAN,
|
|
126
156
|
red_arrow::execute_plan_mark);
|
|
157
|
+
rbgobj_register_mark_func(GARROW_TYPE_CALL_EXPRESSION,
|
|
158
|
+
red_arrow::call_expression_mark);
|
|
159
|
+
rbgobj_register_mark_func(GARROW_TYPE_AGGREGATE_NODE_OPTIONS,
|
|
160
|
+
red_arrow::aggregate_node_options_mark);
|
|
161
|
+
rbgobj_register_mark_func(GARROW_TYPE_PROJECT_NODE_OPTIONS,
|
|
162
|
+
red_arrow::project_node_options_mark);
|
|
127
163
|
}
|
data/ext/arrow/converters.cpp
CHANGED
|
@@ -30,6 +30,11 @@ namespace red_arrow {
|
|
|
30
30
|
return large_list_array_value_converter_->convert(array, i);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
VALUE ArrayValueConverter::convert(const arrow::FixedSizeListArray& array,
|
|
34
|
+
const int64_t i) {
|
|
35
|
+
return fixed_size_list_array_value_converter_->convert(array, i);
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
VALUE ArrayValueConverter::convert(const arrow::StructArray& array,
|
|
34
39
|
const int64_t i) {
|
|
35
40
|
return struct_array_value_converter_->convert(array, i);
|
data/ext/arrow/converters.hpp
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
namespace red_arrow {
|
|
30
30
|
class ListArrayValueConverter;
|
|
31
31
|
class LargeListArrayValueConverter;
|
|
32
|
+
class FixedSizeListArrayValueConverter;
|
|
32
33
|
class StructArrayValueConverter;
|
|
33
34
|
class MapArrayValueConverter;
|
|
34
35
|
class UnionArrayValueConverter;
|
|
@@ -40,6 +41,7 @@ namespace red_arrow {
|
|
|
40
41
|
: decimal_buffer_(),
|
|
41
42
|
list_array_value_converter_(nullptr),
|
|
42
43
|
large_list_array_value_converter_(nullptr),
|
|
44
|
+
fixed_size_list_array_value_converter_(nullptr),
|
|
43
45
|
struct_array_value_converter_(nullptr),
|
|
44
46
|
map_array_value_converter_(nullptr),
|
|
45
47
|
union_array_value_converter_(nullptr),
|
|
@@ -48,12 +50,14 @@ namespace red_arrow {
|
|
|
48
50
|
|
|
49
51
|
inline void set_sub_value_converters(ListArrayValueConverter* list_array_value_converter,
|
|
50
52
|
LargeListArrayValueConverter* large_list_array_value_converter,
|
|
53
|
+
FixedSizeListArrayValueConverter* fixed_size_list_array_value_converter,
|
|
51
54
|
StructArrayValueConverter* struct_array_value_converter,
|
|
52
55
|
MapArrayValueConverter* map_array_value_converter,
|
|
53
56
|
UnionArrayValueConverter* union_array_value_converter,
|
|
54
57
|
DictionaryArrayValueConverter* dictionary_array_value_converter) {
|
|
55
58
|
list_array_value_converter_ = list_array_value_converter;
|
|
56
59
|
large_list_array_value_converter_ = large_list_array_value_converter;
|
|
60
|
+
fixed_size_list_array_value_converter_ = fixed_size_list_array_value_converter;
|
|
57
61
|
struct_array_value_converter_ = struct_array_value_converter;
|
|
58
62
|
map_array_value_converter_ = map_array_value_converter;
|
|
59
63
|
union_array_value_converter_ = union_array_value_converter;
|
|
@@ -153,7 +157,15 @@ namespace red_arrow {
|
|
|
153
157
|
const int64_t i) {
|
|
154
158
|
int32_t length;
|
|
155
159
|
const auto value = array.GetValue(i, &length);
|
|
156
|
-
|
|
160
|
+
return rb_enc_str_new(reinterpret_cast<const char*>(value),
|
|
161
|
+
length,
|
|
162
|
+
rb_ascii8bit_encoding());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
inline VALUE convert(const arrow::LargeBinaryArray& array,
|
|
166
|
+
const int64_t i) {
|
|
167
|
+
int64_t length;
|
|
168
|
+
const auto value = array.GetValue(i, &length);
|
|
157
169
|
return rb_enc_str_new(reinterpret_cast<const char*>(value),
|
|
158
170
|
length,
|
|
159
171
|
rb_ascii8bit_encoding());
|
|
@@ -167,6 +179,14 @@ namespace red_arrow {
|
|
|
167
179
|
length);
|
|
168
180
|
}
|
|
169
181
|
|
|
182
|
+
inline VALUE convert(const arrow::LargeStringArray& array,
|
|
183
|
+
const int64_t i) {
|
|
184
|
+
int64_t length;
|
|
185
|
+
const auto value = array.GetValue(i, &length);
|
|
186
|
+
return rb_utf8_str_new(reinterpret_cast<const char*>(value),
|
|
187
|
+
length);
|
|
188
|
+
}
|
|
189
|
+
|
|
170
190
|
inline VALUE convert(const arrow::FixedSizeBinaryArray& array,
|
|
171
191
|
const int64_t i) {
|
|
172
192
|
return rb_enc_str_new(reinterpret_cast<const char*>(array.Value(i)),
|
|
@@ -225,11 +245,6 @@ namespace red_arrow {
|
|
|
225
245
|
return rb_time_num_new(sec, Qnil);
|
|
226
246
|
}
|
|
227
247
|
|
|
228
|
-
// TODO
|
|
229
|
-
// inline VALUE convert(const arrow::IntervalArray& array,
|
|
230
|
-
// const int64_t i) {
|
|
231
|
-
// };
|
|
232
|
-
|
|
233
248
|
inline VALUE convert(const arrow::MonthIntervalArray& array,
|
|
234
249
|
const int64_t i) {
|
|
235
250
|
return INT2NUM(array.Value(i));
|
|
@@ -264,12 +279,20 @@ namespace red_arrow {
|
|
|
264
279
|
return value;
|
|
265
280
|
}
|
|
266
281
|
|
|
282
|
+
inline VALUE convert(const arrow::DurationArray& array,
|
|
283
|
+
const int64_t i) {
|
|
284
|
+
return LL2NUM(array.Value(i));
|
|
285
|
+
}
|
|
286
|
+
|
|
267
287
|
VALUE convert(const arrow::ListArray& array,
|
|
268
288
|
const int64_t i);
|
|
269
289
|
|
|
270
290
|
VALUE convert(const arrow::LargeListArray& array,
|
|
271
291
|
const int64_t i);
|
|
272
292
|
|
|
293
|
+
VALUE convert(const arrow::FixedSizeListArray& array,
|
|
294
|
+
const int64_t i);
|
|
295
|
+
|
|
273
296
|
VALUE convert(const arrow::StructArray& array,
|
|
274
297
|
const int64_t i);
|
|
275
298
|
|
|
@@ -306,6 +329,7 @@ namespace red_arrow {
|
|
|
306
329
|
std::string decimal_buffer_;
|
|
307
330
|
ListArrayValueConverter* list_array_value_converter_;
|
|
308
331
|
LargeListArrayValueConverter* large_list_array_value_converter_;
|
|
332
|
+
FixedSizeListArrayValueConverter* fixed_size_list_array_value_converter_;
|
|
309
333
|
StructArrayValueConverter* struct_array_value_converter_;
|
|
310
334
|
MapArrayValueConverter* map_array_value_converter_;
|
|
311
335
|
UnionArrayValueConverter* union_array_value_converter_;
|
|
@@ -366,8 +390,10 @@ namespace red_arrow {
|
|
|
366
390
|
VISIT(MonthInterval)
|
|
367
391
|
VISIT(DayTimeInterval)
|
|
368
392
|
VISIT(MonthDayNanoInterval)
|
|
393
|
+
VISIT(Duration)
|
|
369
394
|
VISIT(List)
|
|
370
395
|
VISIT(LargeList)
|
|
396
|
+
VISIT(FixedSizeList)
|
|
371
397
|
VISIT(Struct)
|
|
372
398
|
VISIT(Map)
|
|
373
399
|
VISIT(SparseUnion)
|
|
@@ -465,8 +491,111 @@ namespace red_arrow {
|
|
|
465
491
|
VISIT(MonthInterval)
|
|
466
492
|
VISIT(DayTimeInterval)
|
|
467
493
|
VISIT(MonthDayNanoInterval)
|
|
494
|
+
VISIT(Duration)
|
|
495
|
+
VISIT(List)
|
|
496
|
+
VISIT(LargeList)
|
|
497
|
+
VISIT(FixedSizeList)
|
|
498
|
+
VISIT(Struct)
|
|
499
|
+
VISIT(Map)
|
|
500
|
+
VISIT(SparseUnion)
|
|
501
|
+
VISIT(DenseUnion)
|
|
502
|
+
VISIT(Dictionary)
|
|
503
|
+
VISIT(Decimal128)
|
|
504
|
+
VISIT(Decimal256)
|
|
505
|
+
// TODO
|
|
506
|
+
// VISIT(Extension)
|
|
507
|
+
|
|
508
|
+
#undef VISIT
|
|
509
|
+
|
|
510
|
+
private:
|
|
511
|
+
template <typename ArrayType>
|
|
512
|
+
inline VALUE convert_value(const ArrayType& array,
|
|
513
|
+
const int64_t i) {
|
|
514
|
+
return array_value_converter_->convert(array, i);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
template <typename ArrayType>
|
|
518
|
+
arrow::Status visit_value(const ArrayType& array) {
|
|
519
|
+
if (array.null_count() > 0) {
|
|
520
|
+
for (int64_t i = 0; i < length_; ++i) {
|
|
521
|
+
auto value = Qnil;
|
|
522
|
+
if (!array.IsNull(i + offset_)) {
|
|
523
|
+
value = convert_value(array, i + offset_);
|
|
524
|
+
}
|
|
525
|
+
rb_ary_push(result_, value);
|
|
526
|
+
}
|
|
527
|
+
} else {
|
|
528
|
+
for (int64_t i = 0; i < length_; ++i) {
|
|
529
|
+
rb_ary_push(result_, convert_value(array, i + offset_));
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return arrow::Status::OK();
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
ArrayValueConverter* array_value_converter_;
|
|
536
|
+
int32_t offset_;
|
|
537
|
+
int32_t length_;
|
|
538
|
+
VALUE result_;
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
class FixedSizeListArrayValueConverter : public arrow::ArrayVisitor {
|
|
542
|
+
public:
|
|
543
|
+
explicit FixedSizeListArrayValueConverter(ArrayValueConverter* converter)
|
|
544
|
+
: array_value_converter_(converter),
|
|
545
|
+
offset_(0),
|
|
546
|
+
length_(0),
|
|
547
|
+
result_(Qnil) {}
|
|
548
|
+
|
|
549
|
+
VALUE convert(const arrow::FixedSizeListArray& array, const int64_t index) {
|
|
550
|
+
auto values = array.values().get();
|
|
551
|
+
auto offset_keep = offset_;
|
|
552
|
+
auto length_keep = length_;
|
|
553
|
+
offset_ = array.value_offset(index);
|
|
554
|
+
length_ = array.value_length(index);
|
|
555
|
+
auto result_keep = result_;
|
|
556
|
+
result_ = rb_ary_new_capa(length_);
|
|
557
|
+
check_status(values->Accept(this),
|
|
558
|
+
"[raw-records][fixed-size-list-array]");
|
|
559
|
+
offset_ = offset_keep;
|
|
560
|
+
length_ = length_keep;
|
|
561
|
+
auto result_return = result_;
|
|
562
|
+
result_ = result_keep;
|
|
563
|
+
return result_return;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
#define VISIT(TYPE) \
|
|
567
|
+
arrow::Status Visit(const arrow::TYPE ## Array& array) override { \
|
|
568
|
+
return visit_value(array); \
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
VISIT(Null)
|
|
572
|
+
VISIT(Boolean)
|
|
573
|
+
VISIT(Int8)
|
|
574
|
+
VISIT(Int16)
|
|
575
|
+
VISIT(Int32)
|
|
576
|
+
VISIT(Int64)
|
|
577
|
+
VISIT(UInt8)
|
|
578
|
+
VISIT(UInt16)
|
|
579
|
+
VISIT(UInt32)
|
|
580
|
+
VISIT(UInt64)
|
|
581
|
+
VISIT(HalfFloat)
|
|
582
|
+
VISIT(Float)
|
|
583
|
+
VISIT(Double)
|
|
584
|
+
VISIT(Binary)
|
|
585
|
+
VISIT(String)
|
|
586
|
+
VISIT(FixedSizeBinary)
|
|
587
|
+
VISIT(Date32)
|
|
588
|
+
VISIT(Date64)
|
|
589
|
+
VISIT(Time32)
|
|
590
|
+
VISIT(Time64)
|
|
591
|
+
VISIT(Timestamp)
|
|
592
|
+
VISIT(MonthInterval)
|
|
593
|
+
VISIT(DayTimeInterval)
|
|
594
|
+
VISIT(MonthDayNanoInterval)
|
|
595
|
+
VISIT(Duration)
|
|
468
596
|
VISIT(List)
|
|
469
597
|
VISIT(LargeList)
|
|
598
|
+
VISIT(FixedSizeList)
|
|
470
599
|
VISIT(Struct)
|
|
471
600
|
VISIT(Map)
|
|
472
601
|
VISIT(SparseUnion)
|
|
@@ -572,8 +701,10 @@ namespace red_arrow {
|
|
|
572
701
|
VISIT(MonthInterval)
|
|
573
702
|
VISIT(DayTimeInterval)
|
|
574
703
|
VISIT(MonthDayNanoInterval)
|
|
704
|
+
VISIT(Duration)
|
|
575
705
|
VISIT(List)
|
|
576
706
|
VISIT(LargeList)
|
|
707
|
+
VISIT(FixedSizeList)
|
|
577
708
|
VISIT(Struct)
|
|
578
709
|
VISIT(Map)
|
|
579
710
|
VISIT(SparseUnion)
|
|
@@ -675,8 +806,10 @@ namespace red_arrow {
|
|
|
675
806
|
VISIT(MonthInterval)
|
|
676
807
|
VISIT(DayTimeInterval)
|
|
677
808
|
VISIT(MonthDayNanoInterval)
|
|
809
|
+
VISIT(Duration)
|
|
678
810
|
VISIT(List)
|
|
679
811
|
VISIT(LargeList)
|
|
812
|
+
VISIT(FixedSizeList)
|
|
680
813
|
VISIT(Struct)
|
|
681
814
|
VISIT(Map)
|
|
682
815
|
VISIT(SparseUnion)
|
|
@@ -779,8 +912,10 @@ namespace red_arrow {
|
|
|
779
912
|
VISIT(MonthInterval)
|
|
780
913
|
VISIT(DayTimeInterval)
|
|
781
914
|
VISIT(MonthDayNanoInterval)
|
|
915
|
+
VISIT(Duration)
|
|
782
916
|
VISIT(List)
|
|
783
917
|
VISIT(LargeList)
|
|
918
|
+
VISIT(FixedSizeList)
|
|
784
919
|
VISIT(Struct)
|
|
785
920
|
VISIT(Map)
|
|
786
921
|
VISIT(SparseUnion)
|
|
@@ -881,7 +1016,9 @@ namespace red_arrow {
|
|
|
881
1016
|
VISIT(Float)
|
|
882
1017
|
VISIT(Double)
|
|
883
1018
|
VISIT(Binary)
|
|
1019
|
+
VISIT(LargeBinary)
|
|
884
1020
|
VISIT(String)
|
|
1021
|
+
VISIT(LargeString)
|
|
885
1022
|
VISIT(FixedSizeBinary)
|
|
886
1023
|
VISIT(Date32)
|
|
887
1024
|
VISIT(Date64)
|
|
@@ -891,8 +1028,10 @@ namespace red_arrow {
|
|
|
891
1028
|
VISIT(MonthInterval)
|
|
892
1029
|
VISIT(DayTimeInterval)
|
|
893
1030
|
VISIT(MonthDayNanoInterval)
|
|
1031
|
+
VISIT(Duration)
|
|
894
1032
|
VISIT(List)
|
|
895
1033
|
VISIT(LargeList)
|
|
1034
|
+
VISIT(FixedSizeList)
|
|
896
1035
|
VISIT(Struct)
|
|
897
1036
|
VISIT(Map)
|
|
898
1037
|
VISIT(SparseUnion)
|
|
@@ -923,6 +1062,7 @@ namespace red_arrow {
|
|
|
923
1062
|
: array_value_converter_(),
|
|
924
1063
|
list_array_value_converter_(&array_value_converter_),
|
|
925
1064
|
large_list_array_value_converter_(&array_value_converter_),
|
|
1065
|
+
fixed_size_list_array_value_converter_(&array_value_converter_),
|
|
926
1066
|
struct_array_value_converter_(&array_value_converter_),
|
|
927
1067
|
map_array_value_converter_(&array_value_converter_),
|
|
928
1068
|
union_array_value_converter_(&array_value_converter_),
|
|
@@ -930,6 +1070,7 @@ namespace red_arrow {
|
|
|
930
1070
|
array_value_converter_.
|
|
931
1071
|
set_sub_value_converters(&list_array_value_converter_,
|
|
932
1072
|
&large_list_array_value_converter_,
|
|
1073
|
+
&fixed_size_list_array_value_converter_,
|
|
933
1074
|
&struct_array_value_converter_,
|
|
934
1075
|
&map_array_value_converter_,
|
|
935
1076
|
&union_array_value_converter_,
|
|
@@ -945,6 +1086,7 @@ namespace red_arrow {
|
|
|
945
1086
|
ArrayValueConverter array_value_converter_;
|
|
946
1087
|
ListArrayValueConverter list_array_value_converter_;
|
|
947
1088
|
LargeListArrayValueConverter large_list_array_value_converter_;
|
|
1089
|
+
FixedSizeListArrayValueConverter fixed_size_list_array_value_converter_;
|
|
948
1090
|
StructArrayValueConverter struct_array_value_converter_;
|
|
949
1091
|
MapArrayValueConverter map_array_value_converter_;
|
|
950
1092
|
UnionArrayValueConverter union_array_value_converter_;
|
data/ext/arrow/memory-view.cpp
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
# undef private
|
|
32
32
|
#endif
|
|
33
33
|
|
|
34
|
+
#include <cstring>
|
|
34
35
|
#include <sstream>
|
|
35
36
|
|
|
36
37
|
namespace red_arrow {
|
|
@@ -220,6 +221,7 @@ namespace red_arrow {
|
|
|
220
221
|
return false;
|
|
221
222
|
}
|
|
222
223
|
auto view_ = reinterpret_cast<memory_view *>(view);
|
|
224
|
+
memset(view_, 0, sizeof(memory_view));
|
|
223
225
|
view_->obj = obj;
|
|
224
226
|
view_->private_data = new PrivateData();
|
|
225
227
|
auto array = GARROW_ARRAY(RVAL2GOBJ(obj));
|
|
@@ -231,9 +233,6 @@ namespace red_arrow {
|
|
|
231
233
|
}
|
|
232
234
|
view_->readonly = true;
|
|
233
235
|
view_->ndim = 1;
|
|
234
|
-
view_->shape = NULL;
|
|
235
|
-
view_->strides = NULL;
|
|
236
|
-
view_->sub_offsets = NULL;
|
|
237
236
|
return true;
|
|
238
237
|
}
|
|
239
238
|
|
|
@@ -258,6 +257,7 @@ namespace red_arrow {
|
|
|
258
257
|
return false;
|
|
259
258
|
}
|
|
260
259
|
auto view_ = reinterpret_cast<memory_view *>(view);
|
|
260
|
+
memset(view_, 0, sizeof(memory_view));
|
|
261
261
|
view_->obj = obj;
|
|
262
262
|
auto buffer = GARROW_BUFFER(RVAL2GOBJ(obj));
|
|
263
263
|
auto arrow_buffer = garrow_buffer_get_raw(buffer);
|
|
@@ -275,9 +275,6 @@ namespace red_arrow {
|
|
|
275
275
|
view_->byte_size = arrow_buffer->size();
|
|
276
276
|
view_->readonly = true;
|
|
277
277
|
view_->ndim = 1;
|
|
278
|
-
view_->shape = NULL;
|
|
279
|
-
view_->strides = NULL;
|
|
280
|
-
view_->sub_offsets = NULL;
|
|
281
278
|
return true;
|
|
282
279
|
}
|
|
283
280
|
|
data/ext/arrow/raw-records.cpp
CHANGED
|
@@ -88,7 +88,9 @@ namespace red_arrow {
|
|
|
88
88
|
VISIT(Float)
|
|
89
89
|
VISIT(Double)
|
|
90
90
|
VISIT(Binary)
|
|
91
|
+
VISIT(LargeBinary)
|
|
91
92
|
VISIT(String)
|
|
93
|
+
VISIT(LargeString)
|
|
92
94
|
VISIT(FixedSizeBinary)
|
|
93
95
|
VISIT(Date32)
|
|
94
96
|
VISIT(Date64)
|
|
@@ -98,7 +100,10 @@ namespace red_arrow {
|
|
|
98
100
|
VISIT(MonthInterval)
|
|
99
101
|
VISIT(DayTimeInterval)
|
|
100
102
|
VISIT(MonthDayNanoInterval)
|
|
103
|
+
VISIT(Duration)
|
|
101
104
|
VISIT(List)
|
|
105
|
+
VISIT(LargeList)
|
|
106
|
+
VISIT(FixedSizeList)
|
|
102
107
|
VISIT(Struct)
|
|
103
108
|
VISIT(Map)
|
|
104
109
|
VISIT(SparseUnion)
|
|
@@ -224,7 +229,9 @@ namespace red_arrow {
|
|
|
224
229
|
VISIT(Float)
|
|
225
230
|
VISIT(Double)
|
|
226
231
|
VISIT(Binary)
|
|
232
|
+
VISIT(LargeBinary)
|
|
227
233
|
VISIT(String)
|
|
234
|
+
VISIT(LargeString)
|
|
228
235
|
VISIT(FixedSizeBinary)
|
|
229
236
|
VISIT(Date32)
|
|
230
237
|
VISIT(Date64)
|
|
@@ -234,7 +241,10 @@ namespace red_arrow {
|
|
|
234
241
|
VISIT(MonthInterval)
|
|
235
242
|
VISIT(DayTimeInterval)
|
|
236
243
|
VISIT(MonthDayNanoInterval)
|
|
244
|
+
VISIT(Duration)
|
|
237
245
|
VISIT(List)
|
|
246
|
+
VISIT(LargeList)
|
|
247
|
+
VISIT(FixedSizeList)
|
|
238
248
|
VISIT(Struct)
|
|
239
249
|
VISIT(Map)
|
|
240
250
|
VISIT(SparseUnion)
|
data/ext/arrow/values.cpp
CHANGED
|
@@ -69,7 +69,9 @@ namespace red_arrow {
|
|
|
69
69
|
VISIT(Float)
|
|
70
70
|
VISIT(Double)
|
|
71
71
|
VISIT(Binary)
|
|
72
|
+
VISIT(LargeBinary)
|
|
72
73
|
VISIT(String)
|
|
74
|
+
VISIT(LargeString)
|
|
73
75
|
VISIT(FixedSizeBinary)
|
|
74
76
|
VISIT(Date32)
|
|
75
77
|
VISIT(Date64)
|
|
@@ -79,8 +81,10 @@ namespace red_arrow {
|
|
|
79
81
|
VISIT(MonthInterval)
|
|
80
82
|
VISIT(DayTimeInterval)
|
|
81
83
|
VISIT(MonthDayNanoInterval)
|
|
84
|
+
VISIT(Duration)
|
|
82
85
|
VISIT(List)
|
|
83
86
|
VISIT(LargeList)
|
|
87
|
+
VISIT(FixedSizeList)
|
|
84
88
|
VISIT(Struct)
|
|
85
89
|
VISIT(Map)
|
|
86
90
|
VISIT(SparseUnion)
|
|
@@ -152,5 +152,70 @@ module Arrow
|
|
|
152
152
|
def column_names
|
|
153
153
|
@column_names ||= columns.collect(&:name)
|
|
154
154
|
end
|
|
155
|
+
|
|
156
|
+
# Merges columns from the given container or Hash and creates
|
|
157
|
+
# a new container.
|
|
158
|
+
#
|
|
159
|
+
# @param other [Hash, self]
|
|
160
|
+
# The columns to be merged.
|
|
161
|
+
#
|
|
162
|
+
# @return [self]
|
|
163
|
+
def merge(other)
|
|
164
|
+
added_columns = {}
|
|
165
|
+
removed_columns = {}
|
|
166
|
+
|
|
167
|
+
case other
|
|
168
|
+
when Hash
|
|
169
|
+
other.each do |name, value|
|
|
170
|
+
name = name.to_s
|
|
171
|
+
if value
|
|
172
|
+
added_columns[name] = ensure_raw_column(name, value)
|
|
173
|
+
else
|
|
174
|
+
removed_columns[name] = true
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
when self.class
|
|
178
|
+
other.columns.each do |column|
|
|
179
|
+
name = column.name
|
|
180
|
+
added_columns[name] = ensure_raw_column(name, column)
|
|
181
|
+
end
|
|
182
|
+
else
|
|
183
|
+
message = "merge target must be Hash or #{self.class}: " +
|
|
184
|
+
"<#{other.inspect}>: #{inspect}"
|
|
185
|
+
raise ArgumentError, message
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
new_columns = []
|
|
189
|
+
|
|
190
|
+
columns.each do |column|
|
|
191
|
+
column_name = column.name
|
|
192
|
+
new_column = added_columns.delete(column_name)
|
|
193
|
+
|
|
194
|
+
if new_column
|
|
195
|
+
new_columns << new_column
|
|
196
|
+
next
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
next if removed_columns.key?(column_name)
|
|
200
|
+
|
|
201
|
+
new_columns << ensure_raw_column(column_name, column)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
added_columns.each_value do |new_column|
|
|
205
|
+
new_columns << new_column
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
new_fields = []
|
|
209
|
+
new_arrays = []
|
|
210
|
+
|
|
211
|
+
new_columns.each do |new_column|
|
|
212
|
+
new_fields << new_column[:field]
|
|
213
|
+
new_arrays << new_column[:data]
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
merged = self.class.new(new_fields, new_arrays)
|
|
217
|
+
share_input(merged)
|
|
218
|
+
merged
|
|
219
|
+
end
|
|
155
220
|
end
|
|
156
221
|
end
|
data/lib/arrow/column.rb
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
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 Arrow
|
|
19
|
+
class FixedSizeListDataType
|
|
20
|
+
include ListFieldResolvable
|
|
21
|
+
|
|
22
|
+
alias_method :initialize_raw, :initialize
|
|
23
|
+
private :initialize_raw
|
|
24
|
+
|
|
25
|
+
# Creates a new {Arrow::FixedSizeListDataType}.
|
|
26
|
+
#
|
|
27
|
+
# @overload initialize(field, size)
|
|
28
|
+
#
|
|
29
|
+
# @param field [Arrow::Field, Hash] The field of the fixed size
|
|
30
|
+
# list data type. You can also specify field description by
|
|
31
|
+
# `Hash`.
|
|
32
|
+
#
|
|
33
|
+
# See {Arrow::Field.new} how to specify field description.
|
|
34
|
+
#
|
|
35
|
+
# @param size [Integer] The number of values in each element.
|
|
36
|
+
#
|
|
37
|
+
# @example Create a fixed size list data type with {Arrow::Field}
|
|
38
|
+
# visible_field = Arrow::Field.new("visible", :boolean)
|
|
39
|
+
# size = 2
|
|
40
|
+
# Arrow::FixedSizeListDataType.new(visible_field, size)
|
|
41
|
+
#
|
|
42
|
+
# @example Create a list data type with field description
|
|
43
|
+
# description = {name: "visible", type: :boolean}
|
|
44
|
+
# size = 2
|
|
45
|
+
# Arrow::FixedSizeListDataType.new(description, size)
|
|
46
|
+
#
|
|
47
|
+
# @overload initialize(description)
|
|
48
|
+
#
|
|
49
|
+
# @param description [Hash] The description of the fixed size
|
|
50
|
+
# list data type. It must have `:field` value and `:size`
|
|
51
|
+
# value.
|
|
52
|
+
#
|
|
53
|
+
# @option description [Arrow::Field, Hash] :field The field of
|
|
54
|
+
# the list data type. You can also specify field description
|
|
55
|
+
# by `Hash`.
|
|
56
|
+
#
|
|
57
|
+
# See {Arrow::Field.new} how to specify field description.
|
|
58
|
+
#
|
|
59
|
+
# @option description [Integer] :size The number of values of
|
|
60
|
+
# each element of the fixed size list data type.
|
|
61
|
+
#
|
|
62
|
+
# @example Create a fixed size list data type with {Arrow::Field}
|
|
63
|
+
# visible_field = Arrow::Field.new("visible", :boolean)
|
|
64
|
+
# Arrow::FixedSizeListDataType.new(field: visible_field, size: 2)
|
|
65
|
+
#
|
|
66
|
+
# @example Create a fixed size list data type with field description
|
|
67
|
+
# Arrow::FixedSizeListDataType.new(field: {
|
|
68
|
+
# name: "visible",
|
|
69
|
+
# type: :boolean,
|
|
70
|
+
# },
|
|
71
|
+
# size: 2)
|
|
72
|
+
#
|
|
73
|
+
# @overload initialize(data_type, size)
|
|
74
|
+
#
|
|
75
|
+
# @param data_type [Arrow::DataType, String, Symbol,
|
|
76
|
+
# ::Array<String>, ::Array<Symbol>, Hash] The element data
|
|
77
|
+
# type of the fixed size list data type. A field is created
|
|
78
|
+
# with the default name `"item"` from the data type
|
|
79
|
+
# automatically.
|
|
80
|
+
#
|
|
81
|
+
# See {Arrow::DataType.resolve} how to specify data type.
|
|
82
|
+
#
|
|
83
|
+
# @param size [Integer] The number of values in each
|
|
84
|
+
# element.
|
|
85
|
+
#
|
|
86
|
+
# @example Create a fixed size list data type with {Arrow::DataType}
|
|
87
|
+
# size = 2
|
|
88
|
+
# Arrow::FixedSizeListDataType.new(Arrow::BooleanDataType.new,
|
|
89
|
+
# size)
|
|
90
|
+
#
|
|
91
|
+
# @example Create a fixed size list data type with data type name as String
|
|
92
|
+
# size = 2
|
|
93
|
+
# Arrow::FixedSizeListDataType.new("boolean", size)
|
|
94
|
+
#
|
|
95
|
+
# @example Create a fixed size list data type with data type name as Symbol
|
|
96
|
+
# size = 2
|
|
97
|
+
# Arrow::FixedSizeListDataType.new(:boolean, size)
|
|
98
|
+
#
|
|
99
|
+
# @example Create a fixed size list data type with data type as Array
|
|
100
|
+
# size = 2
|
|
101
|
+
# Arrow::FixedSizeListDataType.new([:time32, :milli], size)
|
|
102
|
+
def initialize(*args)
|
|
103
|
+
n_args = args.size
|
|
104
|
+
case n_args
|
|
105
|
+
when 1
|
|
106
|
+
description = args[0]
|
|
107
|
+
size = description.delete(:size)
|
|
108
|
+
initialize_raw(resolve_field(description), size)
|
|
109
|
+
when 2
|
|
110
|
+
field, size = args
|
|
111
|
+
initialize_raw(resolve_field(field), size)
|
|
112
|
+
else
|
|
113
|
+
message = "wrong number of arguments (given #{n_args}, expected 1..2)"
|
|
114
|
+
raise ArgumentError, message
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
data/lib/arrow/libraries.rb
CHANGED
|
@@ -71,6 +71,7 @@ require_relative "file-system"
|
|
|
71
71
|
require_relative "fixed-size-binary-array"
|
|
72
72
|
require_relative "fixed-size-binary-array-builder"
|
|
73
73
|
require_relative "fixed-size-list-array-builder"
|
|
74
|
+
require_relative "fixed-size-list-data-type"
|
|
74
75
|
require_relative "function"
|
|
75
76
|
require_relative "group"
|
|
76
77
|
require_relative "half-float"
|
|
@@ -134,5 +135,6 @@ require_relative "timestamp-array"
|
|
|
134
135
|
require_relative "timestamp-array-builder"
|
|
135
136
|
require_relative "timestamp-data-type"
|
|
136
137
|
require_relative "timestamp-parser"
|
|
138
|
+
require_relative "union-array"
|
|
137
139
|
require_relative "union-array-builder"
|
|
138
140
|
require_relative "writable"
|
data/lib/arrow/record-batch.rb
CHANGED
|
@@ -37,7 +37,12 @@ module Arrow
|
|
|
37
37
|
super(schema, n_rows, values)
|
|
38
38
|
when 2
|
|
39
39
|
schema, data = args
|
|
40
|
-
|
|
40
|
+
schema = Schema.new(schema) unless schema.is_a?(Schema)
|
|
41
|
+
if !data.empty? and data.all? {|array| array.is_a?(Arrow::Array)}
|
|
42
|
+
super(schema, data[0].size, data)
|
|
43
|
+
else
|
|
44
|
+
RecordBatchBuilder.build(schema, data)
|
|
45
|
+
end
|
|
41
46
|
when 3
|
|
42
47
|
super
|
|
43
48
|
else
|
|
@@ -75,5 +80,26 @@ module Arrow
|
|
|
75
80
|
end
|
|
76
81
|
super
|
|
77
82
|
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
def ensure_raw_column(name, data)
|
|
87
|
+
case data
|
|
88
|
+
when Array
|
|
89
|
+
{
|
|
90
|
+
field: Field.new(name, data.value_data_type),
|
|
91
|
+
data: data,
|
|
92
|
+
}
|
|
93
|
+
when Column
|
|
94
|
+
{
|
|
95
|
+
field: data.field,
|
|
96
|
+
data: data.data,
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
message = "column must be Arrow::Array or Arrow::Column: " +
|
|
100
|
+
"<#{name}>: <#{data.inspect}>: #{inspect}"
|
|
101
|
+
raise ArgumentError, message
|
|
102
|
+
end
|
|
103
|
+
end
|
|
78
104
|
end
|
|
79
105
|
end
|
data/lib/arrow/sort-key.rb
CHANGED
|
@@ -46,16 +46,16 @@ module Arrow
|
|
|
46
46
|
# @return [Arrow::SortKey] A new suitable sort key.
|
|
47
47
|
#
|
|
48
48
|
# @since 4.0.0
|
|
49
|
-
def resolve(target, order=nil)
|
|
49
|
+
def resolve(target, order=nil, null_placement=nil)
|
|
50
50
|
return target if target.is_a?(self)
|
|
51
|
-
new(target, order)
|
|
51
|
+
new(target, order, null_placement)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# @api private
|
|
55
55
|
def try_convert(value)
|
|
56
56
|
case value
|
|
57
57
|
when Symbol, String
|
|
58
|
-
new(value.to_s, :ascending)
|
|
58
|
+
new(value.to_s, :ascending, :at_end)
|
|
59
59
|
else
|
|
60
60
|
nil
|
|
61
61
|
end
|
|
@@ -71,37 +71,46 @@ module Arrow
|
|
|
71
71
|
# @param target [Symbol, String] The name or dot path of the
|
|
72
72
|
# sort column.
|
|
73
73
|
#
|
|
74
|
-
# If `target` is a String,
|
|
75
|
-
#
|
|
76
|
-
# character is `"+"` or `"-"`, they are processed as a leading
|
|
77
|
-
# order mark. If the first character is processed as a leading
|
|
78
|
-
# order mark, the first character is removed from sort column
|
|
79
|
-
# target and corresponding order is used. `"+"` uses ascending
|
|
80
|
-
# order and `"-"` uses ascending order.
|
|
74
|
+
# If `target` is a String, it may have prefix markers that specify
|
|
75
|
+
# the sort order and null placement. The format is `[+/-][^/$]column`:
|
|
81
76
|
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
77
|
+
# - `"+"` prefix means ascending order
|
|
78
|
+
# - `"-"` prefix means descending order
|
|
79
|
+
# - `"^"` prefix means nulls at start
|
|
80
|
+
# - `"$"` prefix means nulls at end
|
|
85
81
|
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
# key.target # => "count"
|
|
89
|
-
# key.order # => Arrow::SortOrder::ASCENDING
|
|
82
|
+
# If `target` is a Symbol, it is converted to String and used as-is
|
|
83
|
+
# (no prefix processing).
|
|
90
84
|
#
|
|
91
|
-
# @example String
|
|
92
|
-
# key = Arrow::SortKey.new("
|
|
93
|
-
# key.target
|
|
94
|
-
# key.order
|
|
85
|
+
# @example String without any prefix
|
|
86
|
+
# key = Arrow::SortKey.new("count")
|
|
87
|
+
# key.target # => "count"
|
|
88
|
+
# key.order # => Arrow::SortOrder::ASCENDING
|
|
89
|
+
# key.null_placement # => Arrow::NullPlacement::AT_END
|
|
95
90
|
#
|
|
96
|
-
# @example String with
|
|
91
|
+
# @example String with order prefix only
|
|
97
92
|
# key = Arrow::SortKey.new("-count")
|
|
98
|
-
# key.target
|
|
99
|
-
# key.order
|
|
93
|
+
# key.target # => "count"
|
|
94
|
+
# key.order # => Arrow::SortOrder::DESCENDING
|
|
95
|
+
# key.null_placement # => Arrow::NullPlacement::AT_END
|
|
96
|
+
#
|
|
97
|
+
# @example String with order and null placement prefixes
|
|
98
|
+
# key = Arrow::SortKey.new("-^count")
|
|
99
|
+
# key.target # => "count"
|
|
100
|
+
# key.order # => Arrow::SortOrder::DESCENDING
|
|
101
|
+
# key.null_placement # => Arrow::NullPlacement::AT_START
|
|
100
102
|
#
|
|
101
|
-
# @example
|
|
103
|
+
# @example String with null placement prefix only
|
|
104
|
+
# key = Arrow::SortKey.new("^count")
|
|
105
|
+
# key.target # => "count"
|
|
106
|
+
# key.order # => Arrow::SortOrder::ASCENDING
|
|
107
|
+
# key.null_placement # => Arrow::NullPlacement::AT_START
|
|
108
|
+
#
|
|
109
|
+
# @example Symbol (no prefix processing)
|
|
102
110
|
# key = Arrow::SortKey.new(:"-count")
|
|
103
|
-
# key.target
|
|
104
|
-
# key.order
|
|
111
|
+
# key.target # => "-count"
|
|
112
|
+
# key.order # => Arrow::SortOrder::ASCENDING
|
|
113
|
+
# key.null_placement # => Arrow::NullPlacement::AT_END
|
|
105
114
|
#
|
|
106
115
|
# @overload initialize(target, order)
|
|
107
116
|
#
|
|
@@ -122,27 +131,54 @@ module Arrow
|
|
|
122
131
|
# key = Arrow::SortKey.new("-count", :ascending)
|
|
123
132
|
# key.target # => "-count"
|
|
124
133
|
# key.order # => Arrow::SortOrder::ASCENDING
|
|
134
|
+
# key.null_placement # => Arrow::NullPlacement::AT_END
|
|
125
135
|
#
|
|
126
136
|
# @example Order by abbreviated target with Symbol
|
|
127
137
|
# key = Arrow::SortKey.new("count", :desc)
|
|
128
138
|
# key.target # => "count"
|
|
129
139
|
# key.order # => Arrow::SortOrder::DESCENDING
|
|
140
|
+
# key.null_placement # => Arrow::NullPlacement::AT_END
|
|
130
141
|
#
|
|
131
142
|
# @example Order by String
|
|
132
143
|
# key = Arrow::SortKey.new("count", "descending")
|
|
133
144
|
# key.target # => "count"
|
|
134
145
|
# key.order # => Arrow::SortOrder::DESCENDING
|
|
146
|
+
# key.null_placement # => Arrow::NullPlacement::AT_END
|
|
135
147
|
#
|
|
136
|
-
# @example Order by Arrow::SortOrder
|
|
137
|
-
# key = Arrow::SortKey.new("count", Arrow::SortOrder::DESCENDING)
|
|
148
|
+
# @example Order by Arrow::SortOrder, give null_placement with target
|
|
149
|
+
# key = Arrow::SortKey.new("^count", Arrow::SortOrder::DESCENDING)
|
|
138
150
|
# key.target # => "count"
|
|
139
151
|
# key.order # => Arrow::SortOrder::DESCENDING
|
|
152
|
+
# key.null_placement # => Arrow::NullPlacement::AT_START
|
|
153
|
+
#
|
|
154
|
+
# @overload initialize(target, order, null_placement)
|
|
155
|
+
#
|
|
156
|
+
# @param target [Symbol, String] The name or dot path of the
|
|
157
|
+
# sort column.
|
|
158
|
+
#
|
|
159
|
+
# @param order [Symbol, String, Arrow::SortOrder] How to order
|
|
160
|
+
# by this sort key.
|
|
161
|
+
#
|
|
162
|
+
# If this is a Symbol or String, this must be `:ascending`,
|
|
163
|
+
# `"ascending"`, `:asc`, `"asc"`, `:descending`,
|
|
164
|
+
# `"descending"`, `:desc` or `"desc"`.
|
|
165
|
+
#
|
|
166
|
+
# @param null_placement [Symbol, String, Arrow::NullPlacement]
|
|
167
|
+
# Where to place nulls and NaNs. Must be `:at_start`, `"at_start"`,
|
|
168
|
+
# `:at_end`, or `"at_end"`.
|
|
169
|
+
#
|
|
170
|
+
# @example With all explicit parameters
|
|
171
|
+
# key = Arrow::SortKey.new("count", :desc, :at_start)
|
|
172
|
+
# key.target # => "count"
|
|
173
|
+
# key.order # => Arrow::SortOrder::DESCENDING
|
|
174
|
+
# key.null_placement # => Arrow::NullPlacement::AT_START
|
|
140
175
|
#
|
|
141
176
|
# @since 4.0.0
|
|
142
|
-
def initialize(target, order=nil)
|
|
143
|
-
target, order = normalize_target(target, order)
|
|
177
|
+
def initialize(target, order=nil, null_placement=nil)
|
|
178
|
+
target, order, null_placement = normalize_target(target, order, null_placement)
|
|
144
179
|
order = normalize_order(order) || :ascending
|
|
145
|
-
|
|
180
|
+
null_placement = normalize_null_placement(null_placement) || :at_end
|
|
181
|
+
initialize_raw(target, order, null_placement)
|
|
146
182
|
end
|
|
147
183
|
|
|
148
184
|
# @return [String] The string representation of this sort key. You
|
|
@@ -151,37 +187,66 @@ module Arrow
|
|
|
151
187
|
#
|
|
152
188
|
# @example Recreate Arrow::SortKey
|
|
153
189
|
# key = Arrow::SortKey.new("-count")
|
|
154
|
-
# key.to_s # => "
|
|
190
|
+
# key.to_s # => "-$count"
|
|
155
191
|
# key == Arrow::SortKey.new(key.to_s) # => true
|
|
156
192
|
#
|
|
157
193
|
# @since 4.0.0
|
|
158
194
|
def to_s
|
|
195
|
+
result = ""
|
|
159
196
|
if order == SortOrder::ASCENDING
|
|
160
|
-
"
|
|
197
|
+
result += "+"
|
|
198
|
+
else
|
|
199
|
+
result += "-"
|
|
200
|
+
end
|
|
201
|
+
if null_placement == NullPlacement::AT_START
|
|
202
|
+
result += "^"
|
|
161
203
|
else
|
|
162
|
-
"
|
|
204
|
+
result += "$"
|
|
163
205
|
end
|
|
206
|
+
result += target
|
|
207
|
+
result
|
|
164
208
|
end
|
|
165
209
|
|
|
166
210
|
# For backward compatibility
|
|
167
211
|
alias_method :name, :target
|
|
168
212
|
|
|
169
213
|
private
|
|
170
|
-
|
|
214
|
+
# Parse prefix format: [+/-][^/$]column
|
|
215
|
+
# Examples: -$column, +^column, ^column, -column
|
|
216
|
+
#
|
|
217
|
+
# Only strips prefixes if the corresponding parameter is not already set.
|
|
218
|
+
# This preserves backward compatibility where specifying order explicitly
|
|
219
|
+
# means the target is used as-is for order prefixes.
|
|
220
|
+
def normalize_target(target, order, null_placement)
|
|
171
221
|
case target
|
|
172
222
|
when Symbol
|
|
173
|
-
return target.to_s, order
|
|
223
|
+
return target.to_s, order, null_placement
|
|
174
224
|
when String
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
225
|
+
remaining = target
|
|
226
|
+
|
|
227
|
+
unless order
|
|
228
|
+
if remaining.start_with?("-")
|
|
229
|
+
order = :descending
|
|
230
|
+
remaining = remaining[1..-1]
|
|
231
|
+
elsif remaining.start_with?("+")
|
|
232
|
+
order = :ascending
|
|
233
|
+
remaining = remaining[1..-1]
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
unless null_placement
|
|
238
|
+
if remaining.start_with?("^")
|
|
239
|
+
null_placement = :at_start
|
|
240
|
+
remaining = remaining[1..-1]
|
|
241
|
+
elsif remaining.start_with?("$")
|
|
242
|
+
null_placement = :at_end
|
|
243
|
+
remaining = remaining[1..-1]
|
|
244
|
+
end
|
|
182
245
|
end
|
|
246
|
+
|
|
247
|
+
return remaining, order, null_placement
|
|
183
248
|
else
|
|
184
|
-
return target, order
|
|
249
|
+
return target, order, null_placement
|
|
185
250
|
end
|
|
186
251
|
end
|
|
187
252
|
|
|
@@ -195,5 +260,16 @@ module Arrow
|
|
|
195
260
|
order
|
|
196
261
|
end
|
|
197
262
|
end
|
|
263
|
+
|
|
264
|
+
def normalize_null_placement(null_placement)
|
|
265
|
+
case null_placement
|
|
266
|
+
when :at_end, "at_end"
|
|
267
|
+
:at_end
|
|
268
|
+
when :at_start, "at_start"
|
|
269
|
+
:at_start
|
|
270
|
+
else
|
|
271
|
+
null_placement
|
|
272
|
+
end
|
|
273
|
+
end
|
|
198
274
|
end
|
|
199
275
|
end
|
data/lib/arrow/sort-options.rb
CHANGED
|
@@ -102,8 +102,8 @@ module Arrow
|
|
|
102
102
|
# options.sort_keys.collect(&:to_s) # => ["-price"]
|
|
103
103
|
#
|
|
104
104
|
# @since 4.0.0
|
|
105
|
-
def add_sort_key(target, order=nil)
|
|
106
|
-
add_sort_key_raw(SortKey.resolve(target, order))
|
|
105
|
+
def add_sort_key(target, order=nil, null_placement=nil)
|
|
106
|
+
add_sort_key_raw(SortKey.resolve(target, order, null_placement))
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
end
|
|
@@ -80,7 +80,11 @@ module Arrow
|
|
|
80
80
|
when nil
|
|
81
81
|
"%*s" % [width, FORMATTED_NULL]
|
|
82
82
|
else
|
|
83
|
-
|
|
83
|
+
value = value.to_s
|
|
84
|
+
if value.encoding == Encoding::ASCII_8BIT
|
|
85
|
+
value = value.each_byte.collect {|byte| "%X" % byte}.join
|
|
86
|
+
end
|
|
87
|
+
"%-*s" % [width, value]
|
|
84
88
|
end
|
|
85
89
|
end
|
|
86
90
|
|
data/lib/arrow/table-saver.rb
CHANGED
|
@@ -130,9 +130,9 @@ module Arrow
|
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
def save_raw(writer_class)
|
|
133
|
+
def save_raw(writer_class, *args)
|
|
134
134
|
open_output_stream do |output|
|
|
135
|
-
writer_class.open(output, @table.schema) do |writer|
|
|
135
|
+
writer_class.open(output, @table.schema, *args) do |writer|
|
|
136
136
|
writer.write_table(@table)
|
|
137
137
|
end
|
|
138
138
|
end
|
|
@@ -144,7 +144,7 @@ module Arrow
|
|
|
144
144
|
|
|
145
145
|
# @since 1.0.0
|
|
146
146
|
def save_as_arrow_file
|
|
147
|
-
save_raw(RecordBatchFileWriter)
|
|
147
|
+
save_raw(RecordBatchFileWriter, nil, @options[:metadata])
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
# @deprecated Use `format: :arrow_batch` instead.
|
data/lib/arrow/table.rb
CHANGED
|
@@ -354,60 +354,6 @@ module Arrow
|
|
|
354
354
|
sliced_table
|
|
355
355
|
end
|
|
356
356
|
|
|
357
|
-
# TODO
|
|
358
|
-
#
|
|
359
|
-
# @return [Arrow::Table]
|
|
360
|
-
def merge(other)
|
|
361
|
-
added_columns = {}
|
|
362
|
-
removed_columns = {}
|
|
363
|
-
|
|
364
|
-
case other
|
|
365
|
-
when Hash
|
|
366
|
-
other.each do |name, value|
|
|
367
|
-
name = name.to_s
|
|
368
|
-
if value
|
|
369
|
-
added_columns[name] = ensure_raw_column(name, value)
|
|
370
|
-
else
|
|
371
|
-
removed_columns[name] = true
|
|
372
|
-
end
|
|
373
|
-
end
|
|
374
|
-
when Table
|
|
375
|
-
added_columns = {}
|
|
376
|
-
other.columns.each do |column|
|
|
377
|
-
name = column.name
|
|
378
|
-
added_columns[name] = ensure_raw_column(name, column)
|
|
379
|
-
end
|
|
380
|
-
else
|
|
381
|
-
message = "merge target must be Hash or Arrow::Table: " +
|
|
382
|
-
"<#{other.inspect}>: #{inspect}"
|
|
383
|
-
raise ArgumentError, message
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
new_columns = []
|
|
387
|
-
columns.each do |column|
|
|
388
|
-
column_name = column.name
|
|
389
|
-
new_column = added_columns.delete(column_name)
|
|
390
|
-
if new_column
|
|
391
|
-
new_columns << new_column
|
|
392
|
-
next
|
|
393
|
-
end
|
|
394
|
-
next if removed_columns.key?(column_name)
|
|
395
|
-
new_columns << ensure_raw_column(column_name, column)
|
|
396
|
-
end
|
|
397
|
-
added_columns.each do |name, new_column|
|
|
398
|
-
new_columns << new_column
|
|
399
|
-
end
|
|
400
|
-
new_fields = []
|
|
401
|
-
new_arrays = []
|
|
402
|
-
new_columns.each do |new_column|
|
|
403
|
-
new_fields << new_column[:field]
|
|
404
|
-
new_arrays << new_column[:data]
|
|
405
|
-
end
|
|
406
|
-
table = self.class.new(new_fields, new_arrays)
|
|
407
|
-
share_input(table)
|
|
408
|
-
table
|
|
409
|
-
end
|
|
410
|
-
|
|
411
357
|
alias_method :remove_column_raw, :remove_column
|
|
412
358
|
def remove_column(name_or_index)
|
|
413
359
|
case name_or_index
|
|
@@ -0,0 +1,26 @@
|
|
|
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 Arrow
|
|
19
|
+
class UnionArray
|
|
20
|
+
def fields
|
|
21
|
+
@fields ||= n_fields.times.collect do |i|
|
|
22
|
+
get_field(i)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/arrow/version.rb
CHANGED
data/red-arrow.gemspec
CHANGED
|
@@ -58,7 +58,7 @@ Gem::Specification.new do |spec|
|
|
|
58
58
|
spec.requirements << "jar org.apache.arrow, arrow-vector, #{spec.version}"
|
|
59
59
|
spec.requirements << "jar org.apache.arrow, arrow-memory-netty, #{spec.version}"
|
|
60
60
|
else
|
|
61
|
-
spec.add_runtime_dependency("extpp", ">= 0.1.
|
|
61
|
+
spec.add_runtime_dependency("extpp", ">= 0.1.2")
|
|
62
62
|
spec.add_runtime_dependency("gio2", ">= 4.2.3")
|
|
63
63
|
spec.add_runtime_dependency("pkg-config")
|
|
64
64
|
|
|
@@ -98,6 +98,8 @@ Gem::Specification.new do |spec|
|
|
|
98
98
|
|
|
99
99
|
["fedora", "libarrow-glib-devel"],
|
|
100
100
|
|
|
101
|
+
["homebrew", "apache-arrow-glib"],
|
|
102
|
+
|
|
101
103
|
# Try without additional repository
|
|
102
104
|
["rhel", "arrow-glib-devel"],
|
|
103
105
|
# Retry with additional repository
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: red-arrow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 25.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- The Apache Software Foundation
|
|
@@ -43,14 +43,14 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 0.1.
|
|
46
|
+
version: 0.1.2
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 0.1.
|
|
53
|
+
version: 0.1.2
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
55
|
name: gio2
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -155,6 +155,7 @@ files:
|
|
|
155
155
|
- lib/arrow/fixed-size-binary-array-builder.rb
|
|
156
156
|
- lib/arrow/fixed-size-binary-array.rb
|
|
157
157
|
- lib/arrow/fixed-size-list-array-builder.rb
|
|
158
|
+
- lib/arrow/fixed-size-list-data-type.rb
|
|
158
159
|
- lib/arrow/function.rb
|
|
159
160
|
- lib/arrow/generic-filterable.rb
|
|
160
161
|
- lib/arrow/generic-takeable.rb
|
|
@@ -250,6 +251,7 @@ files:
|
|
|
250
251
|
- lib/arrow/timestamp-data-type.rb
|
|
251
252
|
- lib/arrow/timestamp-parser.rb
|
|
252
253
|
- lib/arrow/union-array-builder.rb
|
|
254
|
+
- lib/arrow/union-array.rb
|
|
253
255
|
- lib/arrow/version.rb
|
|
254
256
|
- lib/arrow/writable.rb
|
|
255
257
|
- red-arrow.gemspec
|
|
@@ -257,7 +259,7 @@ homepage: https://arrow.apache.org/
|
|
|
257
259
|
licenses:
|
|
258
260
|
- Apache-2.0
|
|
259
261
|
metadata:
|
|
260
|
-
msys2_mingw_dependencies: arrow>=
|
|
262
|
+
msys2_mingw_dependencies: arrow>=25.0.0
|
|
261
263
|
rdoc_options: []
|
|
262
264
|
require_paths:
|
|
263
265
|
- lib
|
|
@@ -272,20 +274,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
272
274
|
- !ruby/object:Gem::Version
|
|
273
275
|
version: '0'
|
|
274
276
|
requirements:
|
|
275
|
-
- 'system: arrow-glib>=
|
|
276
|
-
- 'system: arrow-glib>=
|
|
277
|
-
- 'system: arrow-glib>=
|
|
278
|
-
- 'system: arrow-glib>=
|
|
279
|
-
- 'system: arrow-glib>=
|
|
280
|
-
- 'system: arrow-glib>=
|
|
281
|
-
- 'system: arrow-glib>=
|
|
282
|
-
- 'system: arrow-glib>=
|
|
283
|
-
- 'system: arrow-glib>=
|
|
284
|
-
- 'system: arrow-glib>=
|
|
285
|
-
- 'system: arrow-glib>=
|
|
286
|
-
- 'system: arrow-glib>=
|
|
287
|
-
- 'system: arrow-glib>=
|
|
288
|
-
- 'system: arrow-glib>=
|
|
277
|
+
- 'system: arrow-glib>=25.0.0: amazon_linux: arrow-glib-devel'
|
|
278
|
+
- 'system: arrow-glib>=25.0.0: amazon_linux: https://packages.apache.org/artifactory/arrow/amazon-linux/%{version}/apache-arrow-release-latest.rpm'
|
|
279
|
+
- 'system: arrow-glib>=25.0.0: amazon_linux: arrow-glib-devel'
|
|
280
|
+
- 'system: arrow-glib>=25.0.0: centos: arrow-glib-devel'
|
|
281
|
+
- 'system: arrow-glib>=25.0.0: centos: https://packages.apache.org/artifactory/arrow/centos/%{major_version}-stream/apache-arrow-release-latest.rpm'
|
|
282
|
+
- 'system: arrow-glib>=25.0.0: centos: arrow-glib-devel'
|
|
283
|
+
- 'system: arrow-glib>=25.0.0: conda: arrow-c-glib'
|
|
284
|
+
- 'system: arrow-glib>=25.0.0: debian: libarrow-glib-dev'
|
|
285
|
+
- 'system: arrow-glib>=25.0.0: debian: https://packages.apache.org/artifactory/arrow/%{distribution}/apache-arrow-apt-source-latest-%{code_name}.deb'
|
|
286
|
+
- 'system: arrow-glib>=25.0.0: debian: libarrow-glib-dev'
|
|
287
|
+
- 'system: arrow-glib>=25.0.0: fedora: libarrow-glib-devel'
|
|
288
|
+
- 'system: arrow-glib>=25.0.0: homebrew: apache-arrow-glib'
|
|
289
|
+
- 'system: arrow-glib>=25.0.0: rhel: arrow-glib-devel'
|
|
290
|
+
- 'system: arrow-glib>=25.0.0: rhel: https://packages.apache.org/artifactory/arrow/almalinux/%{major_version}/apache-arrow-release-latest.rpm'
|
|
291
|
+
- 'system: arrow-glib>=25.0.0: rhel: arrow-glib-devel'
|
|
289
292
|
rubygems_version: 3.6.7
|
|
290
293
|
specification_version: 4
|
|
291
294
|
summary: Red Arrow is the Ruby bindings of Apache Arrow
|