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

Function TEST

cpp/src/arrow/array/array_struct_test.cc:80–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80TEST(StructArray, FromFieldNames) {
81 std::shared_ptr<Array> a, b, c, array, expected;
82 a = ArrayFromJSON(int32(), "[4, null]");
83 b = ArrayFromJSON(utf8(), R"([null, "foo"])");
84 std::vector<std::string> field_names = {"a", "b"};
85
86 auto res = StructArray::Make({a, b}, field_names);
87 ASSERT_OK(res);
88 array = *res;
89 expected = ArrayFromJSON(struct_({field("a", int32()), field("b", utf8())}),
90 R"([{"a": 4, "b": null}, {"a": null, "b": "foo"}])");
91 AssertArraysEqual(*array, *expected);
92
93 // With non-zero offsets
94 res =
95 StructArray::Make({a, b}, field_names, /*null_bitmap =*/nullptr, /*null_count =*/0,
96 /*offset =*/1);
97 ASSERT_OK(res);
98 array = *res;
99 expected = ArrayFromJSON(struct_({field("a", int32()), field("b", utf8())}),
100 R"([{"a": null, "b": "foo"}])");
101 AssertArraysEqual(*array, *expected);
102
103 res =
104 StructArray::Make({a, b}, field_names, /*null_bitmap =*/nullptr, /*null_count =*/0,
105 /*offset =*/2);
106 ASSERT_OK(res);
107 array = *res;
108 expected = ArrayFromJSON(struct_({field("a", int32()), field("b", utf8())}), R"([])");
109 AssertArraysEqual(*array, *expected);
110
111 // Offset greater than length
112 res =
113 StructArray::Make({a, b}, field_names, /*null_bitmap =*/nullptr, /*null_count =*/0,
114 /*offset =*/3);
115 ASSERT_RAISES(IndexError, res);
116
117 // With null bitmap
118 std::shared_ptr<Buffer> null_bitmap;
119 BitmapFromVector<bool>({false, true}, &null_bitmap);
120 res = StructArray::Make({a, b}, field_names, null_bitmap);
121 ASSERT_OK(res);
122 array = *res;
123 expected = ArrayFromJSON(struct_({field("a", int32()), field("b", utf8())}),
124 R"([null, {"a": null, "b": "foo"}])");
125 AssertArraysEqual(*array, *expected);
126
127 // Mismatching array lengths
128 field_names = {"a", "c"};
129 c = ArrayFromJSON(int64(), "[1, 2, 3]");
130 res = StructArray::Make({a, c}, field_names);
131 ASSERT_RAISES(Invalid, res);
132
133 // Mismatching number of fields
134 field_names = {"a", "b", "c"};
135 res = StructArray::Make({a, b}, field_names);
136 ASSERT_RAISES(Invalid, res);
137

Callers

nothing calls this directly

Calls 15

ArrayFromJSONFunction · 0.85
struct_Function · 0.85
AssertArraysEqualFunction · 0.85
listFunction · 0.85
default_memory_poolFunction · 0.85
GetOneMethod · 0.80
MakeFunction · 0.70
ASSERT_OK_AND_ASSIGNFunction · 0.70
fieldFunction · 0.50
FieldRefFunction · 0.50
ValidateFullMethod · 0.45
SliceMethod · 0.45

Tested by

no test coverage detected