Repository: apache/arrow
File: cpp/src/arrow/compute/expression_test.cc (C++)

Code before:
    ExpectBindsTo(cmp(field_ref("dec128_3_2"), field_ref("i64")),
                  cmp(field_ref("dec128_3_2"), cast(field_ref("i64"), decimal128(21, 2))),
                  /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(cmp(field_ref("i64"), field_ref("dec128_3_2")),
                  cmp(cast(field_ref("i64"), decimal128(21, 2)), field_ref("dec128_3_2")),
                  /*bound_out=*/nullptr, *exciting_schema);

    // decimal128 decimal256 with different scales
    ExpectBindsTo(
        cmp(field_ref("dec128_3_2"), field_ref("dec256_5_3")),
        cmp(cast(field_ref("dec128_3_2"), decimal256(4, 3)), field_ref("dec256_5_3")),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(
        cmp(field_ref("dec256_5_3"), field_ref("dec128_3_2")),
        cmp(field_ref("dec256_5_3"), cast(field_ref("dec128_3_2"), decimal256(4, 3))),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(cmp(field_ref("dec128_5_3"), field_ref("dec256_3_2")),
                  cmp(cast(field_ref("dec128_5_3"), decimal256(5, 3)),
                      cast(field_ref("dec256_3_2"), decimal256(4, 3))),
                  /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(cmp(field_ref("dec256_3_2"), field_ref("dec128_5_3")),
                  cmp(cast(field_ref("dec256_3_2"), decimal256(4, 3)),
                      cast(field_ref("dec128_5_3"), decimal256(5, 3))),
                  /*bound_out=*/nullptr, *exciting_schema);

    // decimal decimal with different scales
    ExpectBindsTo(
        cmp(field_ref("dec128_3_2"), field_ref("dec128_5_3")),
        cmp(cast(field_ref("dec128_3_2"), decimal128(4, 3)), field_ref("dec128_5_3")),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(
        cmp(field_ref("dec128_5_3"), field_ref("dec128_3_2")),
        cmp(field_ref("dec128_5_3"), cast(field_ref("dec128_3_2"), decimal128(4, 3))),
        /*bound_out=*/nullptr, *exciting_schema);
  }

  compute::SetLookupOptions in_a{ArrayFromJSON(utf8(), R"(["a"])")};

  // cast dictionary to value type
  ExpectBindsTo(call("is_in", {field_ref("dict_str")}, in_a),
                call("is_in", {cast(field_ref("dict_str"), utf8())}, in_a));
}

TEST(Expression, BindWithImplicitCastsForCaseWhenOnDecimal) {
  auto exciting_schema = schema(
      {field("a", struct_({field("", boolean())})),
       field("dec128_20_3", decimal128(20, 3)), field("dec128_21_3", decimal128(21, 3)),
       field("dec128_20_1", decimal128(20, 1)), field("dec128_21_1", decimal128(21, 1)),
       field("dec256_20_3", decimal256(20, 3)), field("dec256_21_3", decimal256(21, 3)),
       field("dec256_20_1", decimal256(20, 1)), field("dec256_21_1", decimal256(21, 1))});
  ExpectBindsTo(call("case_when", {field_ref("a"), field_ref("dec128_20_3"),

Review comment (suggestion):
```suggestion
    // decimal decimal with same width but different scales
```

Code after:
    // decimal int
    ExpectBindsTo(cmp(field_ref("dec128_3_2"), field_ref("i64")),
                  cmp(field_ref("dec128_3_2"), cast(field_ref("i64"), decimal128(21, 2))),
                  /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(cmp(field_ref("i64"), field_ref("dec128_3_2")),
                  cmp(cast(field_ref("i64"), decimal128(21, 2)), field_ref("dec128_3_2")),
                  /*bound_out=*/nullptr, *exciting_schema);

    // decimal decimal with different widths different precisions but same scale
    ExpectBindsTo(
        cmp(field_ref("dec128_3_2"), field_ref("dec256_4_2")),
        cmp(cast(field_ref("dec128_3_2"), decimal256(3, 2)), field_ref("dec256_4_2")),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(
        cmp(field_ref("dec256_4_2"), field_ref("dec128_3_2")),
        cmp(field_ref("dec256_4_2"), cast(field_ref("dec128_3_2"), decimal256(3, 2))),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(
        cmp(field_ref("dec128_4_2"), field_ref("dec256_3_2")),
        cmp(cast(field_ref("dec128_4_2"), decimal256(4, 2)), field_ref("dec256_3_2")),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(
        cmp(field_ref("dec256_3_2"), field_ref("dec128_4_2")),
        cmp(field_ref("dec256_3_2"), cast(field_ref("dec128_4_2"), decimal256(4, 2))),
        /*bound_out=*/nullptr, *exciting_schema);

    // decimal decimal with different widths different scales
    ExpectBindsTo(
        cmp(field_ref("dec128_3_2"), field_ref("dec256_5_3")),
        cmp(cast(field_ref("dec128_3_2"), decimal256(4, 3)), field_ref("dec256_5_3")),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(
        cmp(field_ref("dec256_5_3"), field_ref("dec128_3_2")),
        cmp(field_ref("dec256_5_3"), cast(field_ref("dec128_3_2"), decimal256(4, 3))),
        /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(cmp(field_ref("dec128_5_3"), field_ref("dec256_3_2")),
                  cmp(cast(field_ref("dec128_5_3"), decimal256(5, 3)),
                      cast(field_ref("dec256_3_2"), decimal256(4, 3))),
                  /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(cmp(field_ref("dec256_3_2"), field_ref("dec128_5_3")),
                  cmp(cast(field_ref("dec256_3_2"), decimal256(4, 3)),
                      cast(field_ref("dec128_5_3"), decimal256(5, 3))),
                  /*bound_out=*/nullptr, *exciting_schema);

    // decimal decimal with same width same precision but different scales (no cast)
    ExpectBindsTo(cmp(field_ref("dec128_3_2"), field_ref("dec128_4_2")),
                  cmp(field_ref("dec128_3_2"), field_ref("dec128_4_2")),
                  /*bound_out=*/nullptr, *exciting_schema);
    ExpectBindsTo(cmp(field_ref("dec128_4_2"), field_ref("dec128_3_2")),
                  cmp(field_ref("dec128_4_2"), field_ref("dec128_3_2")),
                  /*bound_out=*/nullptr, *exciting_schema);