Skip to content

Commit

Permalink
Fix casting from map to fixed size list
Browse files Browse the repository at this point in the history
  • Loading branch information
llama90 committed Dec 23, 2023
1 parent 3c455cc commit 886b76e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
21 changes: 3 additions & 18 deletions cpp/src/arrow/compute/kernels/scalar_cast_nested.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,6 @@ struct CastMap {

static Status Exec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) {
const CastOptions& options = CastState::Get(ctx);
// Validate if output is fixed size list
if (out->type()->id() == Type::FIXED_SIZE_LIST) {
const auto& in_type = checked_cast<const MapType&>(*batch[0].type());
const auto& out_type = checked_cast<const FixedSizeListType&>(*out->type());
const auto in_size = batch[0].array.child_data[0].ToArrayData()->length;
const auto out_size = out_type.list_size();
if (in_size != out_size) {
return Status::TypeError("Size of FixedSizeList is not the same.",
" input type: ", in_type.ToString(),
" output type: ", out_type.ToString());
}
}

std::shared_ptr<DataType> entry_type =
checked_cast<const DestType&>(*out->type()).value_type();
Expand All @@ -436,11 +424,8 @@ struct CastMap {
const ArraySpan& in_array = batch[0].array;

ArrayData* out_array = out->array_data().get();
ARROW_ASSIGN_OR_RAISE(out_array->buffers[0],
GetNullBitmapBuffer(in_array, ctx->memory_pool()));
if (in_array.GetBuffer(1) != nullptr) {
out_array->buffers[1] = in_array.GetBuffer(1);
}
out_array->buffers[0] = in_array.GetBuffer(0);
out_array->buffers[1] = in_array.GetBuffer(1);

std::shared_ptr<ArrayData> entries = in_array.child_data[0].ToArrayData();

Expand Down Expand Up @@ -526,7 +511,7 @@ std::vector<std::shared_ptr<CastFunction>> GetNestedCasts() {
AddTypeToTypeCast<CastVarToFixedList<LargeListType>, LargeListType>(cast_fsl.get());
AddTypeToTypeCast<CastVarToFixedList<LargeListViewType>, LargeListViewType>(
cast_fsl.get());
AddMapCast<FixedSizeListType>(cast_fsl.get());
AddTypeToTypeCast<CastVarToFixedList<ListType>, MapType>(cast_fsl.get());

// So is struct
auto cast_struct = std::make_shared<CastFunction>("cast_struct", Type::STRUCT);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/scalar_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ void CheckListCast(const ScalarType& scalar, const std::shared_ptr<DataType>& to
std::tuple<StatusCode, std::string> GetExpectedError(
const std::shared_ptr<DataType>& type,
const std::shared_ptr<DataType>& invalidCastType) {
if (type->id() == Type::FIXED_SIZE_LIST || type->id() == Type::MAP) {
if (type->id() == Type::FIXED_SIZE_LIST) {
return std::make_tuple(
StatusCode::TypeError,
"Size of FixedSizeList is not the same. input type: " + type->ToString() +
Expand Down

0 comments on commit 886b76e

Please sign in to comment.