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

Function TEST

cpp/src/arrow/compute/kernels/codegen_internal_test.cc:30–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28namespace internal {
29
30TEST(TestDispatchBest, CastBinaryDecimalArgs) {
31 std::vector<TypeHolder> args;
32 std::vector<DecimalPromotion> modes = {
33 DecimalPromotion::kAdd, DecimalPromotion::kMultiply, DecimalPromotion::kDivide};
34
35 // Any float -> all float
36 for (auto mode : modes) {
37 args = {decimal128(3, 2), float32(), float64()};
38 ASSERT_OK(CastBinaryDecimalArgs(mode, &args));
39 AssertTypeEqual(*args[0], *float64());
40 AssertTypeEqual(*args[1], *float64());
41 }
42
43 // Integer -> decimal with common scale
44 args = {decimal128(1, 0), int64()};
45 ASSERT_OK(CastBinaryDecimalArgs(DecimalPromotion::kAdd, &args));
46 AssertTypeEqual(*args[0], *decimal128(1, 0));
47 AssertTypeEqual(*args[1], *decimal128(19, 0));
48
49 // Add: rescale so all have common scale
50 args = {decimal128(3, 2), decimal128(3, -2)};
51 EXPECT_RAISES_WITH_MESSAGE_THAT(
52 NotImplemented, ::testing::HasSubstr("Decimals with negative scales not supported"),
53 CastBinaryDecimalArgs(DecimalPromotion::kAdd, &args));
54
55 // Non-castable -> unchanged
56 for (const auto promotion :
57 {DecimalPromotion::kAdd, DecimalPromotion::kMultiply, DecimalPromotion::kDivide}) {
58 for (const auto& args : std::vector<std::vector<TypeHolder>>{
59 {decimal128(3, 2), boolean()},
60 {boolean(), decimal128(3, 2)},
61 {decimal128(3, 2), utf8()},
62 {utf8(), decimal128(3, 2)},
63 }) {
64 auto args_copy = args;
65 ASSERT_OK(CastBinaryDecimalArgs(promotion, &args_copy));
66 AssertTypeEqual(*args_copy[0], *args[0]);
67 AssertTypeEqual(*args_copy[1], *args[1]);
68 }
69 }
70}
71
72TEST(TestDispatchBest, CastDecimalArgs) {
73 std::vector<TypeHolder> args;

Callers

nothing calls this directly

Calls 15

CastBinaryDecimalArgsFunction · 0.85
CastDecimalArgsFunction · 0.85
decimal256Function · 0.85
decimal32Function · 0.85
decimal64Function · 0.85
CommonTemporalFunction · 0.85
CommonTemporalResolutionFunction · 0.85
ReplaceTemporalTypesFunction · 0.85
ASSERT_OK_AND_ASSIGNFunction · 0.70
decimal128Function · 0.50
timestampFunction · 0.50

Tested by

no test coverage detected