You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2013/11/07 16:24:18 UTC
svn commit: r1539682 - in /hive/trunk:
common/src/java/org/apache/hadoop/hive/common/type/
common/src/test/org/apache/hadoop/hive/common/type/
ql/src/java/org/apache/hadoop/hive/ql/parse/
ql/src/test/queries/clientpositive/ ql/src/test/results/clientpo...
Author: xuefu
Date: Thu Nov 7 15:24:17 2013
New Revision: 1539682
URL: http://svn.apache.org/r1539682
Log:
HIVE-5726: The DecimalTypeInfo instance associated with a decimal constant is not in line with the precision/scale of the constant (reviewed by Brock)
Modified:
hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java
hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
hive/trunk/ql/src/test/queries/clientpositive/ctas_hadoop20.q
hive/trunk/ql/src/test/results/clientpositive/ctas_hadoop20.q.out
hive/trunk/ql/src/test/results/clientpositive/literal_decimal.q.out
Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java?rev=1539682&r1=1539681&r2=1539682&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java Thu Nov 7 15:24:17 2013
@@ -222,7 +222,13 @@ public class HiveDecimal implements Comp
int maxScale = Math.min(MAX_SCALE, Math.min(MAX_PRECISION - intDigits, bd.scale()));
if (bd.scale() > maxScale ) {
- bd = allowRounding ? bd.setScale(maxScale, RoundingMode.HALF_UP) : null;
+ if (allowRounding) {
+ bd = bd.setScale(maxScale, RoundingMode.HALF_UP);
+ // Trimming is again necessary, because rounding may introduce new trailing 0's.
+ bd = trim(bd);
+ } else {
+ bd = null;
+ }
}
return bd;
Modified: hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java?rev=1539682&r1=1539681&r2=1539682&view=diff
==============================================================================
--- hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java (original)
+++ hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java Thu Nov 7 15:24:17 2013
@@ -54,7 +54,14 @@ public class TestHiveDecimal {
dec = HiveDecimal.create("178613588865784752580332404014434337809799306448796128931113691624");
Assert.assertNull(dec);
}
-
+
+ @Test
+ public void testTrailingZeroRemovalAfterEnforcement() {
+ String decStr = "8.0900000000000000000000000000000123456";
+ HiveDecimal dec = HiveDecimal.create(decStr);
+ Assert.assertEquals("8.09", dec.toString());
+ }
+
@Test
public void testMultiply() {
HiveDecimal dec1 = HiveDecimal.create("0.1786135888657847525803");
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java?rev=1539682&r1=1539681&r2=1539682&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java Thu Nov 7 15:24:17 2013
@@ -32,6 +32,7 @@ import java.util.Stack;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.common.type.HiveDecimal;
import org.apache.hadoop.hive.ql.ErrorMsg;
import org.apache.hadoop.hive.ql.exec.ColumnInfo;
import org.apache.hadoop.hive.ql.exec.FunctionInfo;
@@ -272,8 +273,16 @@ public final class TypeCheckProcFactory
0, expr.getText().length() - 1));
} else if (expr.getText().endsWith("BD")) {
// Literal decimal
- return new ExprNodeConstantDesc(TypeInfoFactory.decimalTypeInfo,
- expr.getText().substring(0, expr.getText().length() - 2));
+ String strVal = expr.getText().substring(0, expr.getText().length() - 2);
+ HiveDecimal hd = HiveDecimal.create(strVal);
+ int prec = 1;
+ int scale = 0;
+ if (hd != null) {
+ prec = hd.precision();
+ scale = hd.scale();
+ }
+ DecimalTypeInfo typeInfo = TypeInfoFactory.getDecimalTypeInfo(prec, scale);
+ return new ExprNodeConstantDesc(typeInfo, strVal);
} else {
v = Double.valueOf(expr.getText());
v = Long.valueOf(expr.getText());
Modified: hive/trunk/ql/src/test/queries/clientpositive/ctas_hadoop20.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/ctas_hadoop20.q?rev=1539682&r1=1539681&r2=1539682&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/ctas_hadoop20.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/ctas_hadoop20.q Thu Nov 7 15:24:17 2013
@@ -58,11 +58,6 @@ create table nzhang_ctas6 (key string, `
insert overwrite table nzhang_ctas6 select key, value from src limit 10;
create table nzhang_ctas7 as select key, `to` from nzhang_ctas6;
-
-
-
-
-
-
-
-
+create table nzhang_ctas8 as select 3.14BD from nzhang_ctas6 limit 1;
+desc nzhang_ctas8;
+drop table nzhang_ctas8;
Modified: hive/trunk/ql/src/test/results/clientpositive/ctas_hadoop20.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/ctas_hadoop20.q.out?rev=1539682&r1=1539681&r2=1539682&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/ctas_hadoop20.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/ctas_hadoop20.q.out Thu Nov 7 15:24:17 2013
@@ -965,3 +965,29 @@ POSTHOOK: Input: default@nzhang_ctas6
POSTHOOK: Output: default@nzhang_ctas7
POSTHOOK: Lineage: nzhang_ctas6.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
POSTHOOK: Lineage: nzhang_ctas6.to SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
+PREHOOK: query: create table nzhang_ctas8 as select 3.14BD from nzhang_ctas6 limit 1
+PREHOOK: type: CREATETABLE_AS_SELECT
+PREHOOK: Input: default@nzhang_ctas6
+POSTHOOK: query: create table nzhang_ctas8 as select 3.14BD from nzhang_ctas6 limit 1
+POSTHOOK: type: CREATETABLE_AS_SELECT
+POSTHOOK: Input: default@nzhang_ctas6
+POSTHOOK: Output: default@nzhang_ctas8
+POSTHOOK: Lineage: nzhang_ctas6.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: nzhang_ctas6.to SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
+PREHOOK: query: desc nzhang_ctas8
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: desc nzhang_ctas8
+POSTHOOK: type: DESCTABLE
+POSTHOOK: Lineage: nzhang_ctas6.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: nzhang_ctas6.to SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
+_c0 decimal(3,2) None
+PREHOOK: query: drop table nzhang_ctas8
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@nzhang_ctas8
+PREHOOK: Output: default@nzhang_ctas8
+POSTHOOK: query: drop table nzhang_ctas8
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@nzhang_ctas8
+POSTHOOK: Output: default@nzhang_ctas8
+POSTHOOK: Lineage: nzhang_ctas6.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: nzhang_ctas6.to SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
Modified: hive/trunk/ql/src/test/results/clientpositive/literal_decimal.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/literal_decimal.q.out?rev=1539682&r1=1539681&r2=1539682&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/literal_decimal.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/literal_decimal.q.out Thu Nov 7 15:24:17 2013
@@ -20,21 +20,21 @@ STAGE PLANS:
expr: (- 1)
type: decimal(65,30)
expr: 0
- type: decimal(65,30)
+ type: decimal(1,0)
expr: 1
- type: decimal(65,30)
+ type: decimal(1,0)
expr: 3.14
- type: decimal(65,30)
+ type: decimal(3,2)
expr: (- 3.14)
type: decimal(65,30)
expr: 99999999999999999
- type: decimal(65,30)
+ type: decimal(17,0)
expr: 99999999999999999.9999999999999
- type: decimal(65,30)
+ type: decimal(30,13)
expr: 1E-99
- type: decimal(65,30)
+ type: decimal(1,0)
expr: 1E99
- type: decimal(65,30)
+ type: decimal(1,0)
outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8
Limit
ListSink