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

Function CheckStructToStructSubset

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

Source from the content-addressed store, hash-verified

3865}
3866
3867static void CheckStructToStructSubset(
3868 const std::vector<std::shared_ptr<DataType>>& value_types) {
3869 for (const auto& src_value_type : value_types) {
3870 ARROW_SCOPED_TRACE("From type: ", src_value_type->ToString());
3871 for (const auto& dest_value_type : value_types) {
3872 ARROW_SCOPED_TRACE("To type: ", dest_value_type->ToString());
3873
3874 std::vector<std::string> field_names = {"a", "b", "c", "d", "e"};
3875
3876 std::shared_ptr<Array> a1, b1, c1, d1, e1;
3877 a1 = ArrayFromJSON(src_value_type, "[1, 2, 5]");
3878 b1 = ArrayFromJSON(src_value_type, "[3, 4, 7]");
3879 c1 = ArrayFromJSON(src_value_type, "[9, 11, 44]");
3880 d1 = ArrayFromJSON(src_value_type, "[6, 51, 49]");
3881 e1 = ArrayFromJSON(src_value_type, "[19, 17, 74]");
3882
3883 std::shared_ptr<Array> a2, b2, c2, d2, e2;
3884 a2 = ArrayFromJSON(dest_value_type, "[1, 2, 5]");
3885 b2 = ArrayFromJSON(dest_value_type, "[3, 4, 7]");
3886 c2 = ArrayFromJSON(dest_value_type, "[9, 11, 44]");
3887 d2 = ArrayFromJSON(dest_value_type, "[6, 51, 49]");
3888 e2 = ArrayFromJSON(dest_value_type, "[19, 17, 74]");
3889
3890 auto nulls = ArrayFromJSON(dest_value_type, "[null, null, null]");
3891
3892 ASSERT_OK_AND_ASSIGN(auto src,
3893 StructArray::Make({a1, b1, c1, d1, e1}, field_names));
3894 ASSERT_OK_AND_ASSIGN(auto dest1,
3895 StructArray::Make({a2}, std::vector<std::string>{"a"}));
3896 CheckCast(src, dest1);
3897
3898 ASSERT_OK_AND_ASSIGN(
3899 auto dest2, StructArray::Make({b2, c2}, std::vector<std::string>{"b", "c"}));
3900 CheckCast(src, dest2);
3901
3902 ASSERT_OK_AND_ASSIGN(
3903 auto dest3,
3904 StructArray::Make({c2, d2, e2}, std::vector<std::string>{"c", "d", "e"}));
3905 CheckCast(src, dest3);
3906
3907 ASSERT_OK_AND_ASSIGN(
3908 auto dest4, StructArray::Make({a2, b2, c2, e2},
3909 std::vector<std::string>{"a", "b", "c", "e"}));
3910 CheckCast(src, dest4);
3911
3912 ASSERT_OK_AND_ASSIGN(
3913 auto dest5, StructArray::Make({a2, b2, c2, d2, e2}, {"a", "b", "c", "d", "e"}));
3914 CheckCast(src, dest5);
3915
3916 // field does not exist
3917 ASSERT_OK_AND_ASSIGN(auto dest6,
3918 StructArray::Make({a2, d2, nulls}, {"a", "d", "f"}));
3919 CheckCast(src, dest6);
3920
3921 const auto dest7 = arrow::struct_(
3922 {std::make_shared<Field>("a", int8()), std::make_shared<Field>("d", int16()),
3923 std::make_shared<Field>("f", int64(), /*nullable=*/false)});
3924 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