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

Function CheckStructToStructSubset

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

Source from the content-addressed store, hash-verified

3887}
3888
3889static void CheckStructToStructSubset(
3890 const std::vector<std::shared_ptr<DataType>>& value_types) {
3891 for (const auto& src_value_type : value_types) {
3892 ARROW_SCOPED_TRACE("From type: ", src_value_type->ToString());
3893 for (const auto& dest_value_type : value_types) {
3894 ARROW_SCOPED_TRACE("To type: ", dest_value_type->ToString());
3895
3896 std::vector<std::string> field_names = {"a", "b", "c", "d", "e"};
3897
3898 std::shared_ptr<Array> a1, b1, c1, d1, e1;
3899 a1 = ArrayFromJSON(src_value_type, "[1, 2, 5]");
3900 b1 = ArrayFromJSON(src_value_type, "[3, 4, 7]");
3901 c1 = ArrayFromJSON(src_value_type, "[9, 11, 44]");
3902 d1 = ArrayFromJSON(src_value_type, "[6, 51, 49]");
3903 e1 = ArrayFromJSON(src_value_type, "[19, 17, 74]");
3904
3905 std::shared_ptr<Array> a2, b2, c2, d2, e2;
3906 a2 = ArrayFromJSON(dest_value_type, "[1, 2, 5]");
3907 b2 = ArrayFromJSON(dest_value_type, "[3, 4, 7]");
3908 c2 = ArrayFromJSON(dest_value_type, "[9, 11, 44]");
3909 d2 = ArrayFromJSON(dest_value_type, "[6, 51, 49]");
3910 e2 = ArrayFromJSON(dest_value_type, "[19, 17, 74]");
3911
3912 auto nulls = ArrayFromJSON(dest_value_type, "[null, null, null]");
3913
3914 ASSERT_OK_AND_ASSIGN(auto src,
3915 StructArray::Make({a1, b1, c1, d1, e1}, field_names));
3916 ASSERT_OK_AND_ASSIGN(auto dest1,
3917 StructArray::Make({a2}, std::vector<std::string>{"a"}));
3918 CheckCast(src, dest1);
3919
3920 ASSERT_OK_AND_ASSIGN(
3921 auto dest2, StructArray::Make({b2, c2}, std::vector<std::string>{"b", "c"}));
3922 CheckCast(src, dest2);
3923
3924 ASSERT_OK_AND_ASSIGN(
3925 auto dest3,
3926 StructArray::Make({c2, d2, e2}, std::vector<std::string>{"c", "d", "e"}));
3927 CheckCast(src, dest3);
3928
3929 ASSERT_OK_AND_ASSIGN(
3930 auto dest4, StructArray::Make({a2, b2, c2, e2},
3931 std::vector<std::string>{"a", "b", "c", "e"}));
3932 CheckCast(src, dest4);
3933
3934 ASSERT_OK_AND_ASSIGN(
3935 auto dest5, StructArray::Make({a2, b2, c2, d2, e2}, {"a", "b", "c", "d", "e"}));
3936 CheckCast(src, dest5);
3937
3938 // field does not exist
3939 ASSERT_OK_AND_ASSIGN(auto dest6,
3940 StructArray::Make({a2, d2, nulls}, {"a", "d", "f"}));
3941 CheckCast(src, dest6);
3942
3943 const auto dest7 = arrow::struct_(
3944 {std::make_shared<Field>("a", int8()), std::make_shared<Field>("d", int16()),
3945 std::make_shared<Field>("f", int64(), /*nullable=*/false)});
3946 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