protected BigDecimal convertDecimal(Object value, DecimalType type) {
    BigDecimal bigDecimal;
    if (value instanceof BigDecimal) {
      bigDecimal = (BigDecimal) value;
    } else if (value instanceof Number) {
      Number num = (Number) value;
      Double dbl = num.doubleValue();
      if (dbl.equals(Math.floor(dbl))) {
        bigDecimal = BigDecimal.valueOf(num.longValue());
      } else {
        bigDecimal = BigDecimal.valueOf(dbl);
      }
    } else if (value instanceof String) {
      bigDecimal = new BigDecimal((String) value);
    } else {
      throw new IllegalArgumentException(
          "Cannot convert to BigDecimal: " + value.getClass().getName());
    }
    return bigDecimal.setScale(type.scale(), RoundingMode.HALF_UP);
  }
@Test
  public void testDecimalConversion() {
    Table table = mock(Table.class);
    when(table.schema()).thenReturn(SIMPLE_SCHEMA);

    RecordConverter converter = new RecordConverter(table, config);

    BigDecimal expected = new BigDecimal("123.45");

    ImmutableList.of("123.45", 123.45d, expected)
        .forEach(
            input -> {
              BigDecimal decimal = converter.convertDecimal(input, DecimalType.of(10, 2));
              assertThat(decimal).isEqualTo(expected);
            });

    BigDecimal expected2 = new BigDecimal(123);

    ImmutableList.of("123", 123, expected2)
        .forEach(
            input -> {
              BigDecimal decimal = converter.convertDecimal(input, DecimalType.of(10, 0));
              assertThat(decimal).isEqualTo(expected2);
            });
  }