You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jd...@apache.org on 2017/07/06 00:46:01 UTC
hive git commit: HIVE-10616: TypeInfoUtils doesn't handle DECIMAL
with just precision specified (Thomas Friedrich,
reviewed by Gunther Hagleitner)
Repository: hive
Updated Branches:
refs/heads/master c39b87958 -> 2a718a1b3
HIVE-10616: TypeInfoUtils doesn't handle DECIMAL with just precision specified (Thomas Friedrich, reviewed by Gunther Hagleitner)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/2a718a1b
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/2a718a1b
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/2a718a1b
Branch: refs/heads/master
Commit: 2a718a1b39d3e8e6a6bd26d1e33e71df5efcf711
Parents: c39b879
Author: Jason Dere <jd...@hortonworks.com>
Authored: Wed Jul 5 17:44:08 2017 -0700
Committer: Jason Dere <jd...@hortonworks.com>
Committed: Wed Jul 5 17:44:08 2017 -0700
----------------------------------------------------------------------
.../hive/serde2/typeinfo/TypeInfoUtils.java | 4 +++
.../hive/serde2/typeinfo/TestTypeInfoUtils.java | 34 +++++++++++++++++++-
2 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/2a718a1b/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java
----------------------------------------------------------------------
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 @@ public final class TypeInfoUtils {
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]);
http://git-wip-us.apache.org/repos/asf/hive/blob/2a718a1b/serde/src/test/org/apache/hadoop/hive/serde2/typeinfo/TestTypeInfoUtils.java
----------------------------------------------------------------------
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 class TestTypeInfoUtils extends TestCase {
"char(123",
"char(123,)",
"char()",
- "char("
+ "char(",
+ "decimal()"
};
for (String typeString : validTypeStrings) {
@@ -80,4 +81,35 @@ public class TestTypeInfoUtils extends TestCase {
}
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());
+ }
+ }
}