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

Function TEST

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

Source from the content-addressed store, hash-verified

161}
162
163TEST(Cast, CanCast) {
164 auto ExpectCanCast = [](std::shared_ptr<DataType> from,
165 std::vector<std::shared_ptr<DataType>> to_set,
166 bool expected = true) {
167 for (auto to : to_set) {
168 EXPECT_EQ(CanCast(*from, *to), expected) << " from: " << from->ToString() << "\n"
169 << " to: " << to->ToString();
170 }
171 };
172
173 auto ExpectCannotCast = [ExpectCanCast](std::shared_ptr<DataType> from,
174 std::vector<std::shared_ptr<DataType>> to_set) {
175 ExpectCanCast(from, to_set, /*expected=*/false);
176 };
177
178 ExpectCanCast(null(), {boolean()});
179 ExpectCanCast(null(), kNumericTypes);
180 ExpectCanCast(null(), kBaseBinaryAndViewTypes);
181 ExpectCanCast(
182 null(), {date32(), date64(), time32(TimeUnit::MILLI), timestamp(TimeUnit::SECOND)});
183 ExpectCanCast(dictionary(uint16(), null()), {null()});
184
185 ExpectCanCast(boolean(), {boolean()});
186 ExpectCanCast(boolean(), kNumericTypes);
187 ExpectCanCast(boolean(), {utf8(), utf8_view(), large_utf8()});
188 ExpectCanCast(dictionary(int32(), boolean()), {boolean()});
189
190 ExpectCannotCast(boolean(), {null()});
191 ExpectCannotCast(boolean(), {binary(), large_binary()});
192 ExpectCannotCast(boolean(), {date32(), date64(), time32(TimeUnit::MILLI),
193 timestamp(TimeUnit::SECOND)});
194
195 for (auto from_numeric : kNumericTypes) {
196 ExpectCanCast(from_numeric, {boolean()});
197 ExpectCanCast(from_numeric, kNumericTypes);
198 ExpectCanCast(from_numeric, {utf8(), large_utf8()});
199 ExpectCanCast(dictionary(int32(), from_numeric), {from_numeric});
200
201 ExpectCannotCast(from_numeric, {null()});
202 }
203
204 for (auto from_base_binary : kBaseBinaryAndViewTypes) {
205 ExpectCanCast(from_base_binary, {boolean()});
206 ExpectCanCast(from_base_binary, kNumericTypes);
207 ExpectCanCast(from_base_binary, kBaseBinaryTypes);
208 // TODO(GH-43010): include is_binary_view_like() types here once array_take
209 // can handle string-views
210 if (!is_binary_view_like(*from_base_binary)) {
211 ExpectCanCast(dictionary(int64(), from_base_binary), {from_base_binary});
212 }
213
214 // any cast which is valid for the dictionary is valid for the DictionaryArray
215 ExpectCanCast(dictionary(uint32(), from_base_binary), kBaseBinaryTypes);
216 ExpectCanCast(dictionary(int16(), from_base_binary), kNumericTypes);
217
218 ExpectCannotCast(from_base_binary, {null()});
219 }
220

Callers 1

Calls 15

CanCastFunction · 0.85
is_binary_view_likeFunction · 0.85
fixed_size_binaryFunction · 0.85
smallintFunction · 0.85
tinyintFunction · 0.85
ArrayFromJSONFunction · 0.85
CastFunction · 0.85
AssertBufferSameFunction · 0.85
AssertChunkedEqualFunction · 0.85
CallFunctionFunction · 0.85
CheckCastFunction · 0.85
MaskArrayWithNullsAtFunction · 0.85

Tested by

no test coverage detected