Skip to content

Commit

Permalink
Adding test case when scale is null
Browse files Browse the repository at this point in the history
  • Loading branch information
minurajeeve committed Oct 6, 2023
1 parent ad3f91b commit 540dba4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static Schema getSchemaForType(String type, Integer scale) throws Directi
if (type.equals(ColumnTypeNames.DECIMAL)) {
// TODO make set-type support setting decimal precision
scale = scale != null ? scale : 38;
typeSchema = Schema.nullableOf(Schema.decimalOf(76, scale));
typeSchema = Schema.nullableOf(Schema.decimalOf(77, scale));
} else {
if (!SCHEMA_TYPE_MAP.containsKey(type)) {
throw new DirectiveParseException(String.format("'%s' is an unsupported type. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ public void testToDecimalInvalidRoundingMode() throws Exception {
TestingRig.execute(directives, rows);
}

@Test
public void testToDecimalScaleIsNull() throws Exception {
List<Row> rows = Collections.singletonList(new Row("scale_2", "125.45"));
String[] directives = new String[] {"set-type scale_2 decimal"};
List<Row> results = TestingRig.execute(directives, rows);
Row row = results.get(0);

Assert.assertTrue(row.getValue(0) instanceof BigDecimal);
Assert.assertEquals(row.getValue(0), new BigDecimal("125.45"));
}

@Test
public void testToBoolean() throws Exception {
List<Row> trueRows = Collections.singletonList(
Expand Down

0 comments on commit 540dba4

Please sign in to comment.