[ 
https://issues.apache.org/jira/browse/ARROW-1487?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16276102#comment-16276102
 ] 

ASF GitHub Bot commented on ARROW-1487:
---------------------------------------

wesm commented on a change in pull request #1383: ARROW-1487: [C++] Implement 
casts from List<A> to List<B>, where a cast function is defined from any A to B
URL: https://github.com/apache/arrow/pull/1383#discussion_r154537350
 
 

 ##########
 File path: cpp/src/arrow/compute/kernels/cast.cc
 ##########
 @@ -460,6 +460,29 @@ struct CastFunctor<Date32Type, Date64Type> {
   }
 };
 
+// ----------------------------------------------------------------------
+// List to List
+
+template <>
+struct CastFunctor<ListType, ListType> {
+  void operator()(FunctionContext* ctx, const CastOptions& options,
+                  const ArrayData& input, ArrayData* output) {
+    Datum datum_out;
+    ListArray input_array(input.Copy());
+
+    const ListType& type = static_cast<const ListType&>(*output->type);
+
+    FUNC_RETURN_NOT_OK(
+        Cast(ctx, Datum(input_array.values()), type.value_type(), options, 
&datum_out));
+
+    FUNC_RETURN_NOT_OK(
+        input.buffers[0]->Copy(0, input.buffers[0]->size(), 
&output->buffers[0]));
+    FUNC_RETURN_NOT_OK(
+        input.buffers[1]->Copy(0, input.buffers[1]->size(), 
&output->buffers[1]));
+    output->child_data.emplace_back(datum_out.array());
 
 Review comment:
   There's a couple issues with this:
   
   a) We should not perform any additional copying or allocation beyond what is 
required to perform the cast on the child, i.e. we should simply reuse the 
buffers from the input array without copying
   
   b) It would be better to resolve the cast kernel for the child data when the 
kernel is resolved in `GetCastFunction`. Instead of defining a functor for 
list, instead create an alternative implementation of `UnaryKernel` that has 
the child cast kernel as a member variable. This is what I meant in 
https://issues.apache.org/jira/browse/ARROW-1487 by "If a cast rule for the 
child type is not implemented, the failure should occur during kernel selection 
rather than at kernel evaluation time."

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [C++] Implement casts from List<A> to List<B>, where a cast function is 
> defined from any A to B
> -----------------------------------------------------------------------------------------------
>
>                 Key: ARROW-1487
>                 URL: https://issues.apache.org/jira/browse/ARROW-1487
>             Project: Apache Arrow
>          Issue Type: New Feature
>          Components: C++
>            Reporter: Wes McKinney
>            Assignee: Licht Takeuchi
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> If a cast rule for the child type is not implemented, the failure should 
> occur during kernel selection rather than at kernel evaluation time. 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to