Skip to content

Commit

Permalink
[hotfix][table-common] Support negative decimal scale in fromValues
Browse files Browse the repository at this point in the history
  • Loading branch information
twalthr committed Apr 12, 2021
1 parent a3be1cc commit 496c7e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ private static DataType convertToBinaryType(byte[] bytes) {
}

private static DataType convertToDecimalType(BigDecimal decimal) {
final int precision = decimal.precision();
final int scale = decimal.scale();
// let underlying layers check if precision and scale are supported
return DataTypes.DECIMAL(decimal.precision(), decimal.scale());
if (scale < 0) {
// negative scale is not supported, normalize it
return DataTypes.DECIMAL(precision - scale, 0);
}
return DataTypes.DECIMAL(precision, scale);
}

private static DataType convertToTimeType(java.time.LocalTime time) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static List<Object[]> testData() {
{new byte[0], new AtomicDataType(BinaryType.ofEmptyLiteral())},
{BigDecimal.ZERO, DataTypes.DECIMAL(1, 0)},
{new BigDecimal("12.123"), DataTypes.DECIMAL(5, 3)},
{new BigDecimal("1E+36"), DataTypes.DECIMAL(37, 0)},
{12, DataTypes.INT()},
{LocalTime.of(13, 24, 25, 1000), DataTypes.TIME(6)},
{LocalTime.of(13, 24, 25, 0), DataTypes.TIME(0)},
Expand Down

0 comments on commit 496c7e9

Please sign in to comment.