Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cpp/src/arrow/compute/expression_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,45 @@ TEST(Expression, BindWithImplicitCastsForCaseWhenOnDecimal) {
/*bound_out=*/nullptr, *exciting_schema);
}

TEST(Expression, BindWithImplicitCastsForIfElseOnDecimal) {
auto schema = arrow::schema({field("cond", boolean()),
field("dec128_3_2", decimal128(3, 2)),
field("dec128_4_3", decimal128(4, 3))});

ExpectBindsTo(
call("if_else",
{field_ref("cond"), field_ref("dec128_3_2"), field_ref("dec128_4_3")}),
call("if_else",
{field_ref("cond"), cast(field_ref("dec128_3_2"), decimal128(4, 3)),
field_ref("dec128_4_3")}),
/*bound_out=*/nullptr, *schema);
}

TEST(Expression, BindWithImplicitCastsForCoalesceOnDecimal) {
auto schema = arrow::schema({field("dec128_3_2", decimal128(3, 2)),
field("dec128_4_3", decimal128(4, 3))});

ExpectBindsTo(
call("coalesce", {field_ref("dec128_3_2"), field_ref("dec128_4_3")}),
call("coalesce", {cast(field_ref("dec128_3_2"), decimal128(4, 3)),
field_ref("dec128_4_3")}),
/*bound_out=*/nullptr, *schema);
}

TEST(Expression, BindWithImplicitCastsForChooseOnDecimal) {
auto schema = arrow::schema({field("indices", int64()),
field("dec128_3_2", decimal128(3, 2)),
field("dec128_4_3", decimal128(4, 3))});

ExpectBindsTo(
call("choose",
{field_ref("indices"), field_ref("dec128_3_2"), field_ref("dec128_4_3")}),
call("choose",
{field_ref("indices"), cast(field_ref("dec128_3_2"), decimal128(4, 3)),
field_ref("dec128_4_3")}),
/*bound_out=*/nullptr, *schema);
}

TEST(Expression, BindNestedCall) {
auto expr = add(field_ref("a"),
call("subtract", {call("multiply", {field_ref("b"), field_ref("c")}),
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/compute/kernels/scalar_if_else_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3651,6 +3651,8 @@ TEST(TestCoalesce, DispatchBest) {
{large_binary(), large_binary()});
CheckDispatchBest("coalesce", {int32(), decimal128(3, 2)},
{decimal128(12, 2), decimal128(12, 2)});
CheckDispatchBest("coalesce", {decimal128(3, 2), decimal128(4, 3)},
{decimal128(4, 3), decimal128(4, 3)});
CheckDispatchBest("coalesce", {float32(), decimal128(3, 2)}, {float64(), float64()});
CheckDispatchBest("coalesce", {decimal128(3, 2), decimal256(3, 2)},
{decimal256(3, 2), decimal256(3, 2)});
Expand Down Expand Up @@ -3910,6 +3912,8 @@ TEST(TestChooseKernel, DispatchBest) {
// Other arguments promoted separately from index
EXPECT_EQ((std::vector<TypeHolder>{int64(), int32(), int32()}),
Check({int8(), int32(), uint8()}));
EXPECT_EQ((std::vector<TypeHolder>{int64(), decimal128(4, 3), decimal128(4, 3)}),
Check({int8(), decimal128(3, 2), decimal128(4, 3)}));
}

TEST(TestChooseKernel, Errors) {
Expand Down
Loading