You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Will Ayd (Jira)" <ji...@apache.org> on 2022/01/07 02:03:00 UTC

[jira] [Commented] (ARROW-14500) [C++] Support casting from storage type to extension type

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

Will Ayd commented on ARROW-14500:
----------------------------------

Did a little research here. I see the casting from an extension type is handled here:

[https://github.com/apache/arrow/blob/e64480db51fc9622d02613f3ec60bac34d765092/cpp/src/arrow/compute/kernels/scalar_cast_internal.cc#L190]

So the other way around could be pretty similar. However, I'm wondering if a cast to an extension type is truly possible? When coming from an extension type the built-in type can be cast from the extension's physical storage. But would going the other way around would require a creation of a new ExtensionArray instance that populates some of the additional methods?

> [C++] Support casting from storage type to extension type
> ---------------------------------------------------------
>
>                 Key: ARROW-14500
>                 URL: https://issues.apache.org/jira/browse/ARROW-14500
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>            Reporter: Joris Van den Bossche
>            Priority: Major
>              Labels: good-first-issue, kernel
>
> We already support casting an extension array to its storage type (ARROW-7858):
> {code}
> >>> from pyarrow.tests.test_extension_type import IntegerType
> >>> arr = pa.array([1, 2, 3], pa.int64())
> >>> arr_ext = pa.ExtensionArray.from_storage(IntegerType(), arr)
> >>> arr_ext.cast(arr.type)
> Out[29]: 
> <pyarrow.lib.Int64Array object at 0x7f7b0d4739a0>
> [
>   1,
>   2,
>   3
> ]
> {code}
> but we don't support the cast the other way around from storage type to extension type:
> {code}
> >>> arr.cast(arr_ext.type)
> ...
> ArrowNotImplementedError: Unsupported cast from int64 to extension<arrow.py_extension_type<IntegerType>> (no available cast function for target type)
> ../src/arrow/compute/cast.cc:119  GetCastFunctionInternal(cast_options->to_type, args[0].type().get())
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)