lidavidm commented on code in PR #14181:
URL: https://github.com/apache/arrow/pull/14181#discussion_r979928736
##########
cpp/src/arrow/compute/kernels/scalar_cast_nested.cc:
##########
@@ -140,6 +140,38 @@ void AddListCast(CastFunction* func) {
DCHECK_OK(func->AddKernel(SrcType::type_id, std::move(kernel)));
}
+struct CastFixedList {
+ static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult*
out) {
+ const CastOptions& options = CastState::Get(ctx);
+ const auto& in_type = checked_cast<const
FixedSizeListType&>(*batch[0].type());
+ const auto& out_type = checked_cast<const
FixedSizeListType&>(*out->type());
+ auto in_size = in_type.list_size();
+ auto out_size = out_type.list_size();
+
+ if (in_size != out_size) {
+ return Status::TypeError("Size of FixedSizeList is not the same.",
+ " input list: ", in_type.ToString(),
+ " output list: ", out_type.ToString());
+ }
+
+ const ArraySpan& in_array = batch[0].array;
+ std::shared_ptr<ArrayData> values = in_array.child_data[0].ToArrayData();
+ // Take care of data if input are is a view.
+ values = values->Slice(in_array.offset * in_size, in_array.length *
in_size);
+
+ ArrayData* out_array = out->array_data().get();
+ out_array->buffers[0] = in_array.GetBuffer(0);
Review Comment:
Ah, we're copying the offset below, ok
##########
cpp/src/arrow/compute/kernels/scalar_cast_test.cc:
##########
@@ -2209,6 +2209,45 @@ TEST(Cast, ListToListOptionsPassthru) {
}
}
+static void CheckFSLToFSL(const std::vector<std::shared_ptr<DataType>>&
value_types,
+ const std::string& json_data) {
+ for (const auto& src_value_type : value_types) {
+ for (const auto& dest_value_type : value_types) {
+ const auto src_type = fixed_size_list(src_value_type, 2);
+ const auto dest_type = fixed_size_list(dest_value_type, 2);
+ ARROW_SCOPED_TRACE("src_type = ", src_type->ToString(),
+ ", dest_type = ", dest_type->ToString());
+ auto src_array = ArrayFromJSON(src_type, json_data);
+ CheckCast(src_array, ArrayFromJSON(dest_type, json_data));
Review Comment:
It doesn't cover a case like this:
```cpp
auto children = ArrayFromJSON(int16(), "[1, 2, null, 4, 5, null]");
children = children->Slice(2);
// Omitting null bitmap here, but we should test that as well
auto fsl = std::make_shared<FixedSizeListArray>(fixed_size_list(int16(), 2),
2, children);
// fsl is the list [[null, 4], [5, null]]
```
e.g. in Python:
```python
>>> pyarrow.FixedSizeListArray.from_arrays(pyarrow.array([1, 2, None, 4, 5,
None]).slice(2), type=pyarrow.list_(pyarrow.int64(), 2))
<pyarrow.lib.FixedSizeListArray object at 0x7f44bc40f0a0>
[
[
null,
4
],
[
5,
null
]
]
```
--
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]