milesgranger commented on code in PR #14106:
URL: https://github.com/apache/arrow/pull/14106#discussion_r983200733


##########
cpp/src/arrow/compute/kernels/scalar_cast_extension.cc:
##########
@@ -0,0 +1,74 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Implementation of casting to extension types
+#include "arrow/compute/kernels/common.h"
+#include "arrow/compute/kernels/scalar_cast_internal.h"
+#include "arrow/scalar.h"
+
+namespace arrow {
+namespace compute {
+namespace internal {
+
+namespace {
+Status CastToExtension(KernelContext* ctx, const ExecSpan& batch, ExecResult* 
out) {
+  const CastOptions& options = checked_cast<const 
CastState*>(ctx->state())->options;
+  auto out_ty = static_cast<const 
ExtensionType&>(*options.to_type.type).storage_type();
+
+  DCHECK(batch[0].is_array());
+  std::shared_ptr<Array> array = batch[0].array.ToArray();
+
+  // Try to prevent user errors by preventing casting between extensions w/
+  // different storage types. Provide a tip on how to accomplish same outcome.
+  if (array->type()->id() == Type::EXTENSION) {
+    const auto& ext_arr = checked_cast<const ExtensionArray&>(*array);
+    if (out_ty->id() != ext_arr.extension_type()->storage_id()) {

Review Comment:
   Ah okay.. then it's updated, and also does not cast unless it's needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to