MCPcopy Create free account
hub / github.com/apache/arrow / CheckStructToStructSubset

Function CheckStructToStructSubset

cpp/src/arrow/compute/kernels/scalar_cast_test.cc:3814–4227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3812}
3813
3814static void CheckStructToStructSubset(
3815 const std::vector<std::shared_ptr<DataType>>& value_types) {
3816 for (const auto& src_value_type : value_types) {
3817 ARROW_SCOPED_TRACE("From type: ", src_value_type->ToString());
3818 for (const auto& dest_value_type : value_types) {
3819 ARROW_SCOPED_TRACE("To type: ", dest_value_type->ToString());
3820
3821 std::vector<std::string> field_names = {"a", "b", "c", "d", "e"};
3822
3823 std::shared_ptr<Array> a1, b1, c1, d1, e1;
3824 a1 = ArrayFromJSON(src_value_type, "[1, 2, 5]");
3825 b1 = ArrayFromJSON(src_value_type, "[3, 4, 7]");
3826 c1 = ArrayFromJSON(src_value_type, "[9, 11, 44]");
3827 d1 = ArrayFromJSON(src_value_type, "[6, 51, 49]");
3828 e1 = ArrayFromJSON(src_value_type, "[19, 17, 74]");
3829
3830 std::shared_ptr<Array> a2, b2, c2, d2, e2;
3831 a2 = ArrayFromJSON(dest_value_type, "[1, 2, 5]");
3832 b2 = ArrayFromJSON(dest_value_type, "[3, 4, 7]");
3833 c2 = ArrayFromJSON(dest_value_type, "[9, 11, 44]");
3834 d2 = ArrayFromJSON(dest_value_type, "[6, 51, 49]");
3835 e2 = ArrayFromJSON(dest_value_type, "[19, 17, 74]");
3836
3837 auto nulls = ArrayFromJSON(dest_value_type, "[null, null, null]");
3838
3839 ASSERT_OK_AND_ASSIGN(auto src,
3840 StructArray::Make({a1, b1, c1, d1, e1}, field_names));
3841 ASSERT_OK_AND_ASSIGN(auto dest1,
3842 StructArray::Make({a2}, std::vector<std::string>{"a"}));
3843 CheckCast(src, dest1);
3844
3845 ASSERT_OK_AND_ASSIGN(
3846 auto dest2, StructArray::Make({b2, c2}, std::vector<std::string>{"b", "c"}));
3847 CheckCast(src, dest2);
3848
3849 ASSERT_OK_AND_ASSIGN(
3850 auto dest3,
3851 StructArray::Make({c2, d2, e2}, std::vector<std::string>{"c", "d", "e"}));
3852 CheckCast(src, dest3);
3853
3854 ASSERT_OK_AND_ASSIGN(
3855 auto dest4, StructArray::Make({a2, b2, c2, e2},
3856 std::vector<std::string>{"a", "b", "c", "e"}));
3857 CheckCast(src, dest4);
3858
3859 ASSERT_OK_AND_ASSIGN(
3860 auto dest5, StructArray::Make({a2, b2, c2, d2, e2}, {"a", "b", "c", "d", "e"}));
3861 CheckCast(src, dest5);
3862
3863 // field does not exist
3864 ASSERT_OK_AND_ASSIGN(auto dest6,
3865 StructArray::Make({a2, d2, nulls}, {"a", "d", "f"}));
3866 CheckCast(src, dest6);
3867
3868 const auto dest7 = arrow::struct_(
3869 {std::make_shared<Field>("a", int8()), std::make_shared<Field>("d", int16()),
3870 std::make_shared<Field>("f", int64(), /*nullable=*/false)});
3871 const auto options7 = CastOptions::Safe(dest7);

Callers

nothing calls this directly

Calls 11

ArrayFromJSONFunction · 0.85
struct_Function · 0.85
SafeFunction · 0.85
CastFunction · 0.85
CheckCastFunction · 0.85
CheckStructToStructFunction · 0.85
ASSERT_OK_AND_ASSIGNFunction · 0.70
TESTFunction · 0.70
MakeFunction · 0.50
ToStringMethod · 0.45
SliceMethod · 0.45

Tested by

no test coverage detected