From 540dba476294ceeae0f3d30b4befa79caac2b195 Mon Sep 17 00:00:00 2001 From: minurajeeve Date: Fri, 6 Oct 2023 18:11:29 +0530 Subject: [PATCH] Adding test case when scale is null --- .../java/io/cdap/wrangler/utils/ColumnConverter.java | 2 +- .../java/io/cdap/directives/column/SetTypeTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/wrangler-core/src/main/java/io/cdap/wrangler/utils/ColumnConverter.java b/wrangler-core/src/main/java/io/cdap/wrangler/utils/ColumnConverter.java index 777eb5048..29d64a596 100644 --- a/wrangler-core/src/main/java/io/cdap/wrangler/utils/ColumnConverter.java +++ b/wrangler-core/src/main/java/io/cdap/wrangler/utils/ColumnConverter.java @@ -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. " + diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/SetTypeTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/SetTypeTest.java index 1d53727c4..cb617696c 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/SetTypeTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/SetTypeTest.java @@ -213,6 +213,17 @@ public void testToDecimalInvalidRoundingMode() throws Exception { TestingRig.execute(directives, rows); } + @Test + public void testToDecimalScaleIsNull() throws Exception { + List rows = Collections.singletonList(new Row("scale_2", "125.45")); + String[] directives = new String[] {"set-type scale_2 decimal"}; + List 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 trueRows = Collections.singletonList(