dmitry-chirkov-dremio commented on code in PR #51647:
URL: https://github.com/apache/arrow/pull/51647#discussion_r4369396691
##########
cpp/src/arrow/util/list_util.cc:
##########
@@ -203,10 +204,16 @@ Result<std::shared_ptr<ArrayData>>
ListFromListViewImpl(const ArraySpan& list_vi
const auto& value_type = list_view_type.value_type();
// The value type is carried over, so that callers may cast the child.
auto list_type = std::make_shared<DestListType>(value_type);
+ // MakeBuilder does not support extension types, so gather the values using
+ // the storage type and restore the extension type afterwards.
+ const bool is_extension = value_type->id() == Type::EXTENSION;
+ const auto builder_value_type =
+ is_extension ? checked_cast<const
ExtensionType&>(*value_type).storage_type()
+ : value_type;
ARROW_ASSIGN_OR_RAISE(auto sum_of_sizes, SumOfLogicalListSizes(list_view));
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayBuilder> value_builder,
- MakeBuilder(value_type, pool));
+ MakeBuilder(builder_value_type, pool));
Review Comment:
Input: arrow.bool8 is inside a struct or another list? Casting
list_view<struct<e: arrow.bool8>> to list<struct<e: arrow.bool8>> still fails
in MakeBuilder. Casting the field to int8 also fails. These cases pass on the
parent. Could we preserve nested extensions too and add regression tests?
```cpp
TEST(Cast, ListViewToListWithNestedExtensionChild) {
auto extension_type = std::make_shared<SmallintType>();
ExtensionTypeGuard guard(extension_type);
auto storage = ArrayFromJSON(int16(), "[1, 2]");
auto values = ExtensionType::WrapArray(extension_type, storage);
ASSERT_OK_AND_ASSIGN(auto nested, StructArray::Make({values}, {"x"}));
ASSERT_OK_AND_ASSIGN(auto plain_nested, StructArray::Make({storage},
{"x"}));
auto offsets = ArrayFromJSON(int32(), "[0, 1, 2]");
auto sizes = ArrayFromJSON(int32(), "[1, 1]");
ASSERT_OK_AND_ASSIGN(
auto views,
ListViewArray::FromArrays(*offsets->Slice(0, 2), *sizes, *nested));
ASSERT_OK(views->ValidateFull());
for (const auto& child : ArrayVector{nested, plain_nested}) {
ASSERT_OK_AND_ASSIGN(auto expected,
ListArray::FromArrays(*offsets, *child));
CheckCast(views, expected);
}
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]