diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java b/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java index 9f083ec..8be6896 100644 --- a/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java +++ b/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java @@ -449,6 +449,10 @@ private TypeInfo parseType() { if (params == null || params.length == 0) { // It's possible that old metadata still refers to "decimal" as a column type w/o // precision/scale. In this case, the default (10,0) is assumed. Thus, do nothing here. + } else if (params.length == 1) { + // only precision is specified + precision = Integer.valueOf(params[0]); + HiveDecimalUtils.validateParameter(precision, scale); } else if (params.length == 2) { // New metadata always have two parameters. precision = Integer.parseInt(params[0]); diff --git a/serde/src/test/org/apache/hadoop/hive/serde2/typeinfo/TestTypeInfoUtils.java b/serde/src/test/org/apache/hadoop/hive/serde2/typeinfo/TestTypeInfoUtils.java index d913d60..0ff4302 100644 --- a/serde/src/test/org/apache/hadoop/hive/serde2/typeinfo/TestTypeInfoUtils.java +++ b/serde/src/test/org/apache/hadoop/hive/serde2/typeinfo/TestTypeInfoUtils.java @@ -53,7 +53,8 @@ public void testTypeInfoParser() { "char(123", "char(123,)", "char()", - "char(" + "char(", + "decimal()" }; for (String typeString : validTypeStrings) { @@ -80,4 +81,35 @@ public void testQualifiedTypeNoParams() { } assertEquals("char TypeInfo with no params should fail", true, caughtException); } + + public static class DecimalTestCase { + String typeString; + int expectedPrecision; + int expectedScale; + + public DecimalTestCase(String typeString, int expectedPrecision, int expectedScale) { + this.typeString = typeString; + this.expectedPrecision = expectedPrecision; + this.expectedScale = expectedScale; + } + } + + public void testDecimal() { + DecimalTestCase[] testCases = { + new DecimalTestCase("decimal", 10, 0), + new DecimalTestCase("decimal(1)", 1, 0), + new DecimalTestCase("decimal(25)", 25, 0), + new DecimalTestCase("decimal(2,0)", 2, 0), + new DecimalTestCase("decimal(2,1)", 2, 1), + new DecimalTestCase("decimal(25,10)", 25, 10), + new DecimalTestCase("decimal(38,20)", 38, 20) + }; + + for (DecimalTestCase testCase : testCases) { + TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(testCase.typeString); + DecimalTypeInfo decimalType = (DecimalTypeInfo) typeInfo; + assertEquals("Failed for " + testCase.typeString, testCase.expectedPrecision, decimalType.getPrecision()); + assertEquals("Failed for " + testCase.typeString, testCase.expectedScale, decimalType.getScale()); + } + } }