Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CDAP-15361] Fix set-type directive for decimal when scale is null #673

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ public static Schema getSchemaForType(String type, Integer scale) throws Directi
type = type.toUpperCase();
if (type.equals(ColumnTypeNames.DECIMAL)) {
// TODO make set-type support setting decimal precision
typeSchema = Schema.nullableOf(Schema.decimalOf(38, scale));
scale = scale != null ? scale : 38;
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
vanathi-g marked this conversation as resolved.
Show resolved Hide resolved
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
Loading