2828
2929namespace red_arrow {
3030 class ListArrayValueConverter ;
31+ class LargeListArrayValueConverter ;
3132 class StructArrayValueConverter ;
3233 class MapArrayValueConverter ;
3334 class UnionArrayValueConverter ;
@@ -38,18 +39,21 @@ namespace red_arrow {
3839 ArrayValueConverter ()
3940 : decimal_buffer_(),
4041 list_array_value_converter_ (nullptr ),
42+ large_list_array_value_converter_(nullptr ),
4143 struct_array_value_converter_(nullptr ),
4244 map_array_value_converter_(nullptr ),
4345 union_array_value_converter_(nullptr ),
4446 dictionary_array_value_converter_(nullptr ) {
4547 }
4648
4749 inline void set_sub_value_converters (ListArrayValueConverter* list_array_value_converter,
50+ LargeListArrayValueConverter* large_list_array_value_converter,
4851 StructArrayValueConverter* struct_array_value_converter,
4952 MapArrayValueConverter* map_array_value_converter,
5053 UnionArrayValueConverter* union_array_value_converter,
5154 DictionaryArrayValueConverter* dictionary_array_value_converter) {
5255 list_array_value_converter_ = list_array_value_converter;
56+ large_list_array_value_converter_ = large_list_array_value_converter;
5357 struct_array_value_converter_ = struct_array_value_converter;
5458 map_array_value_converter_ = map_array_value_converter;
5559 union_array_value_converter_ = union_array_value_converter;
@@ -263,6 +267,9 @@ namespace red_arrow {
263267 VALUE convert (const arrow::ListArray& array,
264268 const int64_t i);
265269
270+ VALUE convert (const arrow::LargeListArray& array,
271+ const int64_t i);
272+
266273 VALUE convert (const arrow::StructArray& array,
267274 const int64_t i);
268275
@@ -298,6 +305,7 @@ namespace red_arrow {
298305
299306 std::string decimal_buffer_;
300307 ListArrayValueConverter* list_array_value_converter_;
308+ LargeListArrayValueConverter* large_list_array_value_converter_;
301309 StructArrayValueConverter* struct_array_value_converter_;
302310 MapArrayValueConverter* map_array_value_converter_;
303311 UnionArrayValueConverter* union_array_value_converter_;
@@ -359,6 +367,106 @@ namespace red_arrow {
359367 VISIT (DayTimeInterval)
360368 VISIT (MonthDayNanoInterval)
361369 VISIT (List)
370+ VISIT (LargeList)
371+ VISIT (Struct)
372+ VISIT (Map)
373+ VISIT (SparseUnion)
374+ VISIT (DenseUnion)
375+ VISIT (Dictionary)
376+ VISIT (Decimal128)
377+ VISIT (Decimal256)
378+ // TODO
379+ // VISIT(Extension)
380+
381+ #undef VISIT
382+
383+ private:
384+ template <typename ArrayType>
385+ inline VALUE convert_value (const ArrayType& array,
386+ const int64_t i) {
387+ return array_value_converter_->convert (array, i);
388+ }
389+
390+ template <typename ArrayType>
391+ arrow::Status visit_value (const ArrayType& array) {
392+ if (array.null_count () > 0 ) {
393+ for (int64_t i = 0 ; i < length_; ++i) {
394+ auto value = Qnil;
395+ if (!array.IsNull (i + offset_)) {
396+ value = convert_value (array, i + offset_);
397+ }
398+ rb_ary_push (result_, value);
399+ }
400+ } else {
401+ for (int64_t i = 0 ; i < length_; ++i) {
402+ rb_ary_push (result_, convert_value (array, i + offset_));
403+ }
404+ }
405+ return arrow::Status::OK ();
406+ }
407+
408+ ArrayValueConverter* array_value_converter_;
409+ int32_t offset_;
410+ int32_t length_;
411+ VALUE result_;
412+ };
413+
414+ class LargeListArrayValueConverter : public arrow ::ArrayVisitor {
415+ public:
416+ explicit LargeListArrayValueConverter (ArrayValueConverter* converter)
417+ : array_value_converter_(converter),
418+ offset_(0 ),
419+ length_(0 ),
420+ result_(Qnil) {}
421+
422+ VALUE convert (const arrow::LargeListArray& array, const int64_t index) {
423+ auto values = array.values ().get ();
424+ auto offset_keep = offset_;
425+ auto length_keep = length_;
426+ offset_ = array.value_offset (index);
427+ length_ = array.value_length (index);
428+ auto result_keep = result_;
429+ result_ = rb_ary_new_capa (length_);
430+ check_status (values->Accept (this ),
431+ " [raw-records][large-list-array]" );
432+ offset_ = offset_keep;
433+ length_ = length_keep;
434+ auto result_return = result_;
435+ result_ = result_keep;
436+ return result_return;
437+ }
438+
439+ #define VISIT (TYPE ) \
440+ arrow::Status Visit (const arrow::TYPE ## Array& array) override { \
441+ return visit_value (array); \
442+ }
443+
444+ VISIT (Null)
445+ VISIT (Boolean)
446+ VISIT (Int8)
447+ VISIT (Int16)
448+ VISIT (Int32)
449+ VISIT (Int64)
450+ VISIT (UInt8)
451+ VISIT (UInt16)
452+ VISIT (UInt32)
453+ VISIT (UInt64)
454+ VISIT (HalfFloat)
455+ VISIT (Float)
456+ VISIT (Double)
457+ VISIT (Binary)
458+ VISIT (String)
459+ VISIT (FixedSizeBinary)
460+ VISIT (Date32)
461+ VISIT (Date64)
462+ VISIT (Time32)
463+ VISIT (Time64)
464+ VISIT (Timestamp)
465+ VISIT (MonthInterval)
466+ VISIT (DayTimeInterval)
467+ VISIT (MonthDayNanoInterval)
468+ VISIT (List)
469+ VISIT (LargeList)
362470 VISIT (Struct)
363471 VISIT (Map)
364472 VISIT (SparseUnion)
@@ -465,6 +573,7 @@ namespace red_arrow {
465573 VISIT (DayTimeInterval)
466574 VISIT (MonthDayNanoInterval)
467575 VISIT (List)
576+ VISIT (LargeList)
468577 VISIT (Struct)
469578 VISIT (Map)
470579 VISIT (SparseUnion)
@@ -567,6 +676,7 @@ namespace red_arrow {
567676 VISIT (DayTimeInterval)
568677 VISIT (MonthDayNanoInterval)
569678 VISIT (List)
679+ VISIT (LargeList)
570680 VISIT (Struct)
571681 VISIT (Map)
572682 VISIT (SparseUnion)
@@ -670,6 +780,7 @@ namespace red_arrow {
670780 VISIT (DayTimeInterval)
671781 VISIT (MonthDayNanoInterval)
672782 VISIT (List)
783+ VISIT (LargeList)
673784 VISIT (Struct)
674785 VISIT (Map)
675786 VISIT (SparseUnion)
@@ -781,6 +892,7 @@ namespace red_arrow {
781892 VISIT (DayTimeInterval)
782893 VISIT (MonthDayNanoInterval)
783894 VISIT (List)
895+ VISIT (LargeList)
784896 VISIT (Struct)
785897 VISIT (Map)
786898 VISIT (SparseUnion)
@@ -810,12 +922,14 @@ namespace red_arrow {
810922 explicit Converter ()
811923 : array_value_converter_(),
812924 list_array_value_converter_(&array_value_converter_),
925+ large_list_array_value_converter_(&array_value_converter_),
813926 struct_array_value_converter_(&array_value_converter_),
814927 map_array_value_converter_(&array_value_converter_),
815928 union_array_value_converter_(&array_value_converter_),
816929 dictionary_array_value_converter_(&array_value_converter_) {
817930 array_value_converter_.
818931 set_sub_value_converters (&list_array_value_converter_,
932+ &large_list_array_value_converter_,
819933 &struct_array_value_converter_,
820934 &map_array_value_converter_,
821935 &union_array_value_converter_,
@@ -830,6 +944,7 @@ namespace red_arrow {
830944
831945 ArrayValueConverter array_value_converter_;
832946 ListArrayValueConverter list_array_value_converter_;
947+ LargeListArrayValueConverter large_list_array_value_converter_;
833948 StructArrayValueConverter struct_array_value_converter_;
834949 MapArrayValueConverter map_array_value_converter_;
835950 UnionArrayValueConverter union_array_value_converter_;
0 commit comments