@@ -510,13 +510,30 @@ void AddBinaryToFixedSizeBinaryCast(CastFunction* func) {
510
510
AddBinaryToFixedSizeBinaryCast<FixedSizeBinaryType>(func);
511
511
}
512
512
513
+ // ----------------------------------------------------------------------
514
+ // List-like (List, LargeList, ListView, LargeListView, FixedSizeList, Map) to string
515
+
513
516
template <typename O, typename I>
514
517
struct ListLikeToStringCastFunctor {
515
518
using BuilderType = typename TypeTraits<O>::BuilderType;
516
519
520
+ static Status AppendValue (const ArraySpan& values, std::stringstream& ss, int64_t j, int64_t start) {
521
+ if (j != start) {
522
+ ss << " , " ;
523
+ }
524
+ if (values.IsValid (j)) {
525
+ std::shared_ptr<Scalar> value_scalar;
526
+ RETURN_NOT_OK (values.ToArray ()->GetScalar (j).Value (&value_scalar));
527
+ ss << value_scalar->ToString ();
528
+ } else {
529
+ ss << " null" ;
530
+ }
531
+ return Status::OK ();
532
+ }
533
+
517
534
static Status Exec (KernelContext* ctx, const ExecSpan& batch, ExecResult* out) {
518
535
const ArraySpan& input = batch[0 ].array ;
519
-
536
+ auto type_id = input. type -> id ();
520
537
BuilderType builder (ctx->memory_pool ());
521
538
RETURN_NOT_OK (builder.Reserve (input.length ));
522
539
@@ -525,7 +542,7 @@ struct ListLikeToStringCastFunctor {
525
542
const auto * offsets = input.GetValues <typename I::offset_type>(1 );
526
543
527
544
int list_size = -1 ;
528
- if (input. type -> id () == Type::FIXED_SIZE_LIST) {
545
+ if (type_id == Type::FIXED_SIZE_LIST) {
529
546
list_size = checked_cast<const FixedSizeListType&>(*input.type ).list_size ();
530
547
}
531
548
@@ -535,34 +552,20 @@ struct ListLikeToStringCastFunctor {
535
552
continue ;
536
553
}
537
554
538
- std::ostringstream ss;
555
+ std::stringstream ss;
539
556
ss << type_info << " [" ;
540
557
541
558
int64_t start, end;
542
- if (input. type -> id () == Type::FIXED_SIZE_LIST) {
559
+ if (type_id == Type::FIXED_SIZE_LIST) {
543
560
start = i * list_size;
544
561
end = start + list_size;
545
562
} else {
546
563
start = offsets[i];
547
564
end = offsets[i + 1 ];
548
565
}
549
566
550
- auto append_value = [&](int64_t j) -> Status {
551
- if (j != start) {
552
- ss << " , " ;
553
- }
554
- if (values.IsValid (j)) {
555
- std::shared_ptr<Scalar> value_scalar;
556
- RETURN_NOT_OK (values.ToArray ()->GetScalar (j).Value (&value_scalar));
557
- ss << value_scalar->ToString ();
558
- } else {
559
- ss << " null" ;
560
- }
561
- return Status::OK ();
562
- };
563
-
564
567
for (int64_t j = start; j < end; ++j) {
565
- RETURN_NOT_OK (append_value (j ));
568
+ RETURN_NOT_OK (AppendValue (values, ss, j, start ));
566
569
}
567
570
568
571
ss << " ]" ;
0 commit comments