| 3664 | } |
| 3665 | |
| 3666 | static void CheckFSLToFSL(const std::vector<std::shared_ptr<DataType>>& value_types, |
| 3667 | const std::string& json_data, |
| 3668 | const std::string& tweaked_val_bit_string, |
| 3669 | bool children_nulls = true) { |
| 3670 | for (const auto& src_value_type : value_types) { |
| 3671 | for (const auto& dest_value_type : value_types) { |
| 3672 | const auto src_type = fixed_size_list(src_value_type, 2); |
| 3673 | const auto dest_type = fixed_size_list(dest_value_type, 2); |
| 3674 | ARROW_SCOPED_TRACE("src_type = ", src_type->ToString(), |
| 3675 | ", dest_type = ", dest_type->ToString()); |
| 3676 | auto src_array = ArrayFromJSON(src_type, json_data); |
| 3677 | CheckCast(src_array, ArrayFromJSON(dest_type, json_data)); |
| 3678 | { |
| 3679 | auto tweaked_array = TweakValidityBit(src_array, 1, false); |
| 3680 | CheckCast(tweaked_array, ArrayFromJSON(dest_type, tweaked_val_bit_string)); |
| 3681 | } |
| 3682 | |
| 3683 | // Sliced Children |
| 3684 | const auto child_data = |
| 3685 | children_nulls ? "[1, 2, null, 4, 5, null]" : "[1, 2, 3, 4, 5, 6]"; |
| 3686 | auto children_src = ArrayFromJSON(src_value_type, child_data); |
| 3687 | children_src = children_src->Slice(2); |
| 3688 | auto fsl = std::make_shared<FixedSizeListArray>(src_type, 2, children_src); |
| 3689 | { |
| 3690 | const auto expected_data = children_nulls ? "[null, 4, 5, null]" : "[3, 4, 5, 6]"; |
| 3691 | auto children_dst = ArrayFromJSON(dest_value_type, expected_data); |
| 3692 | auto expected = std::make_shared<FixedSizeListArray>(dest_type, 2, children_dst); |
| 3693 | CheckCast(fsl, expected); |
| 3694 | } |
| 3695 | { |
| 3696 | const auto expected_data = |
| 3697 | children_nulls ? "[[null, 4], null]" : "[[3, 4], null]"; |
| 3698 | auto tweaked_array = TweakValidityBit(fsl, 1, false); |
| 3699 | auto expected = ArrayFromJSON(dest_type, expected_data); |
| 3700 | CheckCast(tweaked_array, expected); |
| 3701 | } |
| 3702 | |
| 3703 | // Invalid fixed_size_list cast. |
| 3704 | const auto incorrect_dest_type = fixed_size_list(dest_value_type, 3); |
| 3705 | ASSERT_RAISES(TypeError, Cast(src_array, CastOptions::Safe(incorrect_dest_type))) |
| 3706 | << "Size of FixedList is not the same."; |
| 3707 | } |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | TEST(Cast, FSLToFSL) { |
| 3712 | CheckFSLToFSL({int32(), float32(), int64()}, "[[0, 1], [2, 3], [null, 5], null]", |
no test coverage detected