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 9, 2023
1 parent 540dba4 commit ab025fe
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,30 @@ public void testToDecimalInvalidRoundingMode() throws Exception {
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"};
Schema inputSchema = Schema.recordOf(
"inputSchema",
Schema.Field.of("scale_2", Schema.of(Schema.Type.DOUBLE))
);

Schema expectedSchema = Schema.recordOf(
"expectedSchema",
Schema.Field.of("scale_2", Schema.decimalOf(77, 38))
);

List<Row> results = TestingRig.execute(directives, rows);
Schema outputSchema = TestingRig.executeAndGetSchema(directives, rows, inputSchema);
Row row = results.get(0);
Schema.Field outputSchemaField = expectedSchema.getFields().get(0);

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

Assert.assertEquals(outputSchemaField.getSchema().getType(),
outputSchema.getField(outputSchemaField.getName()).getSchema().getNonNullable().getType());
Assert.assertEquals(outputSchemaField.getSchema().getPrecision(),
outputSchema.getField(outputSchemaField.getName()).getSchema().getNonNullable().getPrecision());
Assert.assertEquals(outputSchemaField.getSchema().getScale(),
outputSchema.getField(outputSchemaField.getName()).getSchema().getNonNullable().getScale());
}

@Test
Expand Down

0 comments on commit ab025fe

Please sign in to comment.