hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r1434468 [1/4] - in /hive/trunk: data/files/ jdbc/src/java/org/apache/hadoop/hive/jdbc/ jdbc/src/test/org/apache/hadoop/hive/jdbc/ metastore/src/java/org/apache/hadoop/hive/metastore/ ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/...
Date Wed, 16 Jan 2013 23:04:27 GMT
Author: cws
Date: Wed Jan 16 23:04:24 2013
New Revision: 1434468

URL: http://svn.apache.org/viewvc?rev=1434468&view=rev
Log:
Add DECIMAL data type (Josh Wills, Vikram Dixit, Prasad Mujumdar, Mark Grover and Gunther Hagleitner via cws)

Added:
    hive/trunk/data/files/kv7.txt
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToDecimal.java
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java
    hive/trunk/ql/src/test/queries/clientpositive/decimal_1.q
    hive/trunk/ql/src/test/queries/clientpositive/decimal_2.q
    hive/trunk/ql/src/test/queries/clientpositive/decimal_3.q
    hive/trunk/ql/src/test/queries/clientpositive/decimal_serde.q
    hive/trunk/ql/src/test/queries/clientpositive/decimal_udf.q
    hive/trunk/ql/src/test/results/clientpositive/decimal_1.q.out
    hive/trunk/ql/src/test/results/clientpositive/decimal_2.q.out
    hive/trunk/ql/src/test/results/clientpositive/decimal_3.q.out
    hive/trunk/ql/src/test/results/clientpositive/decimal_serde.q.out
    hive/trunk/ql/src/test/results/clientpositive/decimal_udf.q.out
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/BigDecimalWritable.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyBigDecimal.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/objectinspector/primitive/LazyBigDecimalObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryBigDecimal.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/BigDecimalObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaBigDecimalObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/SettableBigDecimalObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableBigDecimalObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableConstantBigDecimalObjectInspector.java
Modified:
    hive/trunk/data/files/datatypes.txt
    hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java
    hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java
    hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java
    hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java
    hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/NumericOpMethodResolver.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericOp.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericUnaryOp.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFCeil.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFloor.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMinus.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToLong.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToShort.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCorrelation.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovariance.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovarianceSample.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFHistogramNumeric.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentileApprox.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStd.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStdSample.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVariance.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVarianceSample.java
    hive/trunk/ql/src/test/queries/clientpositive/udf7.q
    hive/trunk/ql/src/test/results/clientnegative/invalid_cast_from_binary_1.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_cast_from_binary_2.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_cast_from_binary_3.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_cast_from_binary_4.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_cast_from_binary_5.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_cast_from_binary_6.q.out
    hive/trunk/ql/src/test/results/clientnegative/wrong_column_type.q.out
    hive/trunk/ql/src/test/results/clientpositive/udf7.q.out
    hive/trunk/serde/if/serde.thrift
    hive/trunk/serde/src/gen/thrift/gen-cpp/serde_constants.cpp
    hive/trunk/serde/src/gen/thrift/gen-cpp/serde_constants.h
    hive/trunk/serde/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/serde/serdeConstants.java
    hive/trunk/serde/src/gen/thrift/gen-php/org/apache/hadoop/hive/serde/Types.php
    hive/trunk/serde/src/gen/thrift/gen-py/org_apache_hadoop_hive_serde/constants.py
    hive/trunk/serde/src/gen/thrift/gen-rb/serde_constants.rb
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/SerDeUtils.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/binarysortable/BinarySortableSerDe.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyFactory.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/objectinspector/primitive/LazyPrimitiveObjectInspectorFactory.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryFactory.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryUtils.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorConverters.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/PrimitiveObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorConverter.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorFactory.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoFactory.java
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestStatsSerde.java
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/MyTestClass.java
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/TestBinarySortableSerDe.java
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazybinary/MyTestClassBigger.java
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazybinary/MyTestClassSmaller.java
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/lazybinary/TestLazyBinarySerDe.java
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorConverters.java

Modified: hive/trunk/data/files/datatypes.txt
URL: http://svn.apache.org/viewvc/hive/trunk/data/files/datatypes.txt?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/data/files/datatypes.txt (original)
+++ hive/trunk/data/files/datatypes.txt Wed Jan 16 23:04:24 2013
@@ -1,3 +1,3 @@
-\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N
--1false-1.1\N\N\N-1-1-1.0-1\N\N\N
-1true1.11121x2ykva92.2111.01abcd1111213142212212x1abcd22012-04-22 09:00:00.123456789
+\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N
+-1false-1.1\N\N\N-1-1-1.0-1\N\N\N\N
+1true1.11121x2ykva92.2111.01abcd1111213142212212x1abcd22012-04-22 09:00:00.123456789123456789.0123456

Added: hive/trunk/data/files/kv7.txt
URL: http://svn.apache.org/viewvc/hive/trunk/data/files/kv7.txt?rev=1434468&view=auto
==============================================================================
--- hive/trunk/data/files/kv7.txt (added)
+++ hive/trunk/data/files/kv7.txt Wed Jan 16 23:04:24 2013
@@ -0,0 +1,38 @@
+-4400 4400
+1E+99 0
+1E-99 0
+0 0
+100 100
+10 10
+1 1
+0.1 0
+0.01 0
+200 200
+20 20
+2 2
+0 0
+0.2 0
+0.02 0
+0.3 0
+0.33 0
+0.333 0
+-0.3 0
+-0.33 0
+-0.333 0
+1.0 1
+2 2
+3.14 3
+-1.12 -1
+-1.12 -1
+-1.122 -11
+1.12 1
+1.122 1
+124.00 124
+125.2 125
+-1255.49 -1255
+3.14 3
+3.14 3
+3.140 4
+0.9999999999999999999999999 1
+-1234567890.1234567890 -1234567890
+1234567890.1234567800 1234567890

Modified: hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java Wed Jan 16 23:04:24 2013
@@ -21,6 +21,7 @@ package org.apache.hadoop.hive.jdbc;
 import java.io.InputStream;
 import java.io.Reader;
 import java.math.BigDecimal;
+import java.math.MathContext;
 import java.net.URL;
 import java.sql.Array;
 import java.sql.Blob;
@@ -102,19 +103,29 @@ public abstract class HiveBaseResultSet 
   }
 
   public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
-    throw new SQLException("Method not supported");
+    Object obj = getObject(columnIndex);
+    if (obj == null) {
+      return null;
+    }
+    if (obj instanceof BigDecimal) {
+      return ((BigDecimal) obj);
+    }
+    throw new SQLException("Cannot convert column " + columnIndex 
+                           + " to BigDecimal. Found data of type: " 
+                           + obj.getClass()+", value: " + obj.toString());
   }
 
   public BigDecimal getBigDecimal(String columnName) throws SQLException {
-    throw new SQLException("Method not supported");
+    return getBigDecimal(findColumn(columnName));
   }
 
   public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
-    throw new SQLException("Method not supported");
+    MathContext mc = new MathContext(scale);
+    return getBigDecimal(columnIndex).round(mc);
   }
 
   public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
-    throw new SQLException("Method not supported");
+    return getBigDecimal(findColumn(columnName), scale);
   }
 
   public InputStream getBinaryStream(int columnIndex) throws SQLException {

Modified: hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java Wed Jan 16 23:04:24 2013
@@ -112,6 +112,8 @@ public class HiveResultSetMetaData imple
       return serdeConstants.BIGINT_TYPE_NAME;
     } else if ("timestamp".equalsIgnoreCase(type)) {
       return serdeConstants.TIMESTAMP_TYPE_NAME;
+    } else if ("decimal".equalsIgnoreCase(type)) {
+      return serdeConstants.DECIMAL_TYPE_NAME;
     } else if (type.startsWith("map<")) {
       return serdeConstants.STRING_TYPE_NAME;
     } else if (type.startsWith("array<")) {

Modified: hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java Wed Jan 16 23:04:24 2013
@@ -82,6 +82,8 @@ public class JdbcColumn {
     // see http://download.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Double.MAX_EXPONENT
     case Types.DOUBLE:
       return 25; // e.g. -(17#).e-####
+    case Types.DECIMAL:
+      return Integer.MAX_VALUE;
     default:
       throw new SQLException("Invalid column type: " + columnType);
     }
@@ -108,6 +110,8 @@ public class JdbcColumn {
       return 15;
     case Types.TIMESTAMP:
       return 29;
+    case Types.DECIMAL:
+      return Integer.MAX_VALUE;
     default:
       throw new SQLException("Invalid column type: " + columnType);
     }
@@ -129,6 +133,8 @@ public class JdbcColumn {
       return 15;
     case Types.TIMESTAMP:
       return 9;
+    case Types.DECIMAL:
+      return Integer.MAX_VALUE;
     default:
       throw new SQLException("Invalid column type: " + columnType);
     }
@@ -153,6 +159,8 @@ public class JdbcColumn {
       return 10;
     } else if (type.equalsIgnoreCase("bigint")) {
       return 10;
+    } else if (type.equalsIgnoreCase("decimal")) {
+      return 10;
     } else if (type.equalsIgnoreCase("float")) {
       return 2;
     } else if (type.equalsIgnoreCase("double")) {

Modified: hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java Wed Jan 16 23:04:24 2013
@@ -48,6 +48,8 @@ public class Utils {
       return Types.BIGINT;
     } else if ("timestamp".equalsIgnoreCase(type)) {
       return Types.TIMESTAMP;
+    } else if ("decimal".equalsIgnoreCase(type)) {
+      return Types.DECIMAL;
     } else if (type.startsWith("map<")) {
       return Types.VARCHAR;
     } else if (type.startsWith("array<")) {

Modified: hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java (original)
+++ hive/trunk/jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java Wed Jan 16 23:04:24 2013
@@ -148,7 +148,8 @@ public class TestJdbcDriver extends Test
         + " c14 map<int, map<int,int>>,"
         + " c15 struct<r:int,s:struct<a:int,b:string>>,"
         + " c16 array<struct<m:map<string,string>,n:int>>,"
-        + " c17 timestamp) comment '"+dataTypeTableComment
+        + " c17 timestamp, "
+        + " c18 decimal) comment'" + dataTypeTableComment
             +"' partitioned by (dt STRING)");
     assertFalse(res.next());
 
@@ -381,6 +382,7 @@ public class TestJdbcDriver extends Test
     assertEquals("[]", res.getString(16));
     assertEquals(null, res.getString(17));
     assertEquals(null, res.getTimestamp(17));
+    assertEquals(null, res.getBigDecimal(18));
 
     // row 3
     assertTrue(res.next());
@@ -402,6 +404,7 @@ public class TestJdbcDriver extends Test
     assertEquals("[[{}, 1], [{c=d, a=b}, 2]]", res.getString(16));
     assertEquals("2012-04-22 09:00:00.123456789", res.getString(17));
     assertEquals("2012-04-22 09:00:00.123456789", res.getTimestamp(17).toString());
+    assertEquals("123456789.0123456", res.getBigDecimal(18).toString());
 
     // test getBoolean rules on non-boolean columns
     assertEquals(true, res.getBoolean(1));
@@ -803,13 +806,13 @@ public class TestJdbcDriver extends Test
 
     ResultSet res = stmt.executeQuery(
         "select c1, c2, c3, c4, c5 as a, c6, c7, c8, c9, c10, c11, c12, " +
-        "c1*2, sentences(null, null, null) as b, c17 from " + dataTypeTableName + " limit 1");
+        "c1*2, sentences(null, null, null) as b, c17, c18 from " + dataTypeTableName + " limit 1");
     ResultSetMetaData meta = res.getMetaData();
 
     ResultSet colRS = con.getMetaData().getColumns(null, null,
         dataTypeTableName.toLowerCase(), null);
 
-    assertEquals(15, meta.getColumnCount());
+    assertEquals(16, meta.getColumnCount());
 
     assertTrue(colRS.next());
 
@@ -1012,6 +1015,13 @@ public class TestJdbcDriver extends Test
     assertEquals(29, meta.getPrecision(15));
     assertEquals(9, meta.getScale(15));
 
+    assertEquals("c18", meta.getColumnName(16));
+    assertEquals(Types.DECIMAL, meta.getColumnType(16));
+    assertEquals("decimal", meta.getColumnTypeName(16));
+    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(16));
+    assertEquals(Integer.MAX_VALUE, meta.getPrecision(16));
+    assertEquals(Integer.MAX_VALUE, meta.getScale(16));
+
     for (int i = 1; i <= meta.getColumnCount(); i++) {
       assertFalse(meta.isAutoIncrement(i));
       assertFalse(meta.isCurrency(i));

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java Wed Jan 16 23:04:24 2013
@@ -395,7 +395,7 @@ public class MetaStoreUtils {
         org.apache.hadoop.hive.serde.serdeConstants.STRING_TYPE_NAME, "string");
     typeToThriftTypeMap.put(
         org.apache.hadoop.hive.serde.serdeConstants.BINARY_TYPE_NAME, "binary");
-    // These 3 types are not supported yet.
+    // These 4 types are not supported yet.
     // We should define a complex type date in thrift that contains a single int
     // member, and DynamicSerDe
     // should convert it to date type at runtime.
@@ -406,6 +406,8 @@ public class MetaStoreUtils {
     typeToThriftTypeMap
         .put(org.apache.hadoop.hive.serde.serdeConstants.TIMESTAMP_TYPE_NAME,
             "timestamp");
+    typeToThriftTypeMap.put(
+        org.apache.hadoop.hive.serde.serdeConstants.DECIMAL_TYPE_NAME, "decimal");
   }
 
   /**

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java Wed Jan 16 23:04:24 2013
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -200,6 +201,7 @@ import org.apache.hadoop.hive.ql.udf.gen
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFTimestamp;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFToBinary;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDecimal;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUtcTimestamp;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFTranslate;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFUnion;
@@ -403,6 +405,8 @@ public final class FunctionRegistry {
         GenericUDFTimestamp.class);
     registerGenericUDF(serdeConstants.BINARY_TYPE_NAME,
         GenericUDFToBinary.class);
+    registerGenericUDF(serdeConstants.DECIMAL_TYPE_NAME,
+        GenericUDFToDecimal.class);
 
     // Aggregate functions
     registerGenericUDAF("max", new GenericUDAFMax());
@@ -638,7 +642,8 @@ public final class FunctionRegistry {
     registerNumericType(serdeConstants.BIGINT_TYPE_NAME, 4);
     registerNumericType(serdeConstants.FLOAT_TYPE_NAME, 5);
     registerNumericType(serdeConstants.DOUBLE_TYPE_NAME, 6);
-    registerNumericType(serdeConstants.STRING_TYPE_NAME, 7);
+    registerNumericType(serdeConstants.DECIMAL_TYPE_NAME, 7);
+    registerNumericType(serdeConstants.STRING_TYPE_NAME, 8);
   }
 
   /**
@@ -720,6 +725,11 @@ public final class FunctionRegistry {
         && to.equals(TypeInfoFactory.doubleTypeInfo)) {
       return true;
     }
+    // Allow implicit String to Decimal conversion
+    if (from.equals(TypeInfoFactory.stringTypeInfo)
+        && to.equals(TypeInfoFactory.decimalTypeInfo)) {
+      return true;
+    }
     // Void can be converted to any type
     if (from.equals(TypeInfoFactory.voidTypeInfo)) {
       return true;
@@ -731,7 +741,7 @@ public final class FunctionRegistry {
     }
 
     // Allow implicit conversion from Byte -> Integer -> Long -> Float -> Double
-    // -> String
+    // Decimal -> String
     Integer f = numericTypes.get(from);
     Integer t = numericTypes.get(to);
     if (f == null || t == null) {
@@ -1020,8 +1030,57 @@ public final class FunctionRegistry {
       throw new NoMatchingMethodException(udfClass, argumentsPassed, mlist);
     }
     if (udfMethods.size() > 1) {
-      // Ambiguous method found
-      throw new AmbiguousMethodException(udfClass, argumentsPassed, mlist);
+
+      // if the only difference is numeric types, pick the method 
+      // with the smallest overall numeric type.
+      int lowestNumericType = Integer.MAX_VALUE;
+      boolean multiple = true;
+      Method candidate = null;
+      List<TypeInfo> referenceArguments = null;
+      
+      for (Method m: udfMethods) {
+        int maxNumericType = 0;
+        
+        List<TypeInfo> argumentsAccepted = TypeInfoUtils.getParameterTypeInfos(m, argumentsPassed.size());
+        
+        if (referenceArguments == null) {
+          // keep the arguments for reference - we want all the non-numeric 
+          // arguments to be the same
+          referenceArguments = argumentsAccepted;
+        }
+        
+        Iterator<TypeInfo> referenceIterator = referenceArguments.iterator();
+        
+        for (TypeInfo accepted: argumentsAccepted) {
+          TypeInfo reference = referenceIterator.next();
+          
+          if (numericTypes.containsKey(accepted)) {
+            // We're looking for the udf with the smallest maximum numeric type.
+            int typeValue = numericTypes.get(accepted);
+            maxNumericType = typeValue > maxNumericType ? typeValue : maxNumericType;
+          } else if (!accepted.equals(reference)) {
+            // There are non-numeric arguments that don't match from one UDF to
+            // another. We give up at this point. 
+            throw new AmbiguousMethodException(udfClass, argumentsPassed, mlist);
+          }
+        }
+
+        if (lowestNumericType > maxNumericType) {
+          multiple = false;
+          lowestNumericType = maxNumericType;
+          candidate = m;
+        } else if (maxNumericType == lowestNumericType) {
+          // multiple udfs with the same max type. Unless we find a lower one
+          // we'll give up.
+          multiple = true;
+        }
+      }
+
+      if (!multiple) {
+        return candidate;
+      } else {
+        throw new AmbiguousMethodException(udfClass, argumentsPassed, mlist);
+      }
     }
     return udfMethods.get(0);
   }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/NumericOpMethodResolver.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/NumericOpMethodResolver.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/NumericOpMethodResolver.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/NumericOpMethodResolver.java Wed Jan 16 23:04:24 2013
@@ -66,12 +66,21 @@ public class NumericOpMethodResolver imp
     List<TypeInfo> pTypeInfos = null;
     List<TypeInfo> modArgTypeInfos = new ArrayList<TypeInfo>();
 
-    // If either argument is a string, we convert to a double because a number
-    // in string form should always be convertible into a double
+    // If either argument is a string, we convert to a double or decimal because a number
+    // in string form should always be convertible into either of those
     if (argTypeInfos.get(0).equals(TypeInfoFactory.stringTypeInfo)
         || argTypeInfos.get(1).equals(TypeInfoFactory.stringTypeInfo)) {
-      modArgTypeInfos.add(TypeInfoFactory.doubleTypeInfo);
-      modArgTypeInfos.add(TypeInfoFactory.doubleTypeInfo);
+      
+      // Default is double, but if one of the sides is already in decimal we 
+      // complete the operation in that type.
+      if (argTypeInfos.get(0).equals(TypeInfoFactory.decimalTypeInfo)
+          || argTypeInfos.get(1).equals(TypeInfoFactory.decimalTypeInfo)) {
+        modArgTypeInfos.add(TypeInfoFactory.decimalTypeInfo);
+        modArgTypeInfos.add(TypeInfoFactory.decimalTypeInfo);
+      } else {
+        modArgTypeInfos.add(TypeInfoFactory.doubleTypeInfo);
+        modArgTypeInfos.add(TypeInfoFactory.doubleTypeInfo);
+      }
     } else {
       // If it's a void, we change the type to a byte because once the types
       // are run through getCommonClass(), a byte and any other type T will

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java Wed Jan 16 23:04:24 2013
@@ -149,6 +149,7 @@ public class DDLSemanticAnalyzer extends
     TokenToTypeName.put(HiveParser.TOK_DATE, serdeConstants.DATE_TYPE_NAME);
     TokenToTypeName.put(HiveParser.TOK_DATETIME, serdeConstants.DATETIME_TYPE_NAME);
     TokenToTypeName.put(HiveParser.TOK_TIMESTAMP, serdeConstants.TIMESTAMP_TYPE_NAME);
+    TokenToTypeName.put(HiveParser.TOK_DECIMAL, serdeConstants.DECIMAL_TYPE_NAME);
   }
 
   public static String getTypeName(int token) throws SemanticException {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g Wed Jan 16 23:04:24 2013
@@ -108,6 +108,7 @@ TOK_DATETIME;
 TOK_TIMESTAMP;
 TOK_STRING;
 TOK_BINARY;
+TOK_DECIMAL;
 TOK_LIST;
 TOK_STRUCT;
 TOK_MAP;
@@ -1495,6 +1496,7 @@ primitiveType
     | KW_TIMESTAMP     ->    TOK_TIMESTAMP
     | KW_STRING        ->    TOK_STRING
     | KW_BINARY        ->    TOK_BINARY
+    | KW_DECIMAL       ->    TOK_DECIMAL
     ;
 
 listType
@@ -2463,6 +2465,7 @@ KW_DOUBLE: 'DOUBLE';
 KW_DATE: 'DATE';
 KW_DATETIME: 'DATETIME';
 KW_TIMESTAMP: 'TIMESTAMP';
+KW_DECIMAL: 'DECIMAL';
 KW_STRING: 'STRING';
 KW_ARRAY: 'ARRAY';
 KW_STRUCT: 'STRUCT';

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=1434468&r1=1434467&r2=1434468&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 Wed Jan 16 23:04:24 2013
@@ -501,6 +501,8 @@ public final class TypeCheckProcFactory 
           serdeConstants.BINARY_TYPE_NAME);
       conversionFunctionTextHashMap.put(HiveParser.TOK_TIMESTAMP,
           serdeConstants.TIMESTAMP_TYPE_NAME);
+      conversionFunctionTextHashMap.put(HiveParser.TOK_DECIMAL,
+          serdeConstants.DECIMAL_TYPE_NAME);
     }
 
     public static boolean isRedundantConversionFunction(ASTNode expr,

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFAbs.java Wed Jan 16 23:04:24 2013
@@ -20,6 +20,7 @@ package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
@@ -38,6 +39,7 @@ public class UDFAbs extends UDF {
   private final DoubleWritable resultDouble = new DoubleWritable();
   private final LongWritable resultLong = new LongWritable();
   private final IntWritable resultInt = new IntWritable();
+  private final BigDecimalWritable resultBigDecimal = new BigDecimalWritable();
 
   public DoubleWritable evaluate(DoubleWritable n) {
     if (n == null) {
@@ -68,4 +70,13 @@ public class UDFAbs extends UDF {
 
     return resultInt;
   }
+
+  public BigDecimalWritable evaluate(BigDecimalWritable n) {
+    if (n == null) {
+      return null;
+    }
+
+    resultBigDecimal.set(n.getBigDecimal().abs());
+    return resultBigDecimal;
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericOp.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericOp.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericOp.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericOp.java Wed Jan 16 23:04:24 2013
@@ -20,6 +20,7 @@ package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.NumericOpMethodResolver;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -48,6 +49,7 @@ public abstract class UDFBaseNumericOp e
   protected LongWritable longWritable = new LongWritable();
   protected FloatWritable floatWritable = new FloatWritable();
   protected DoubleWritable doubleWritable = new DoubleWritable();
+  protected BigDecimalWritable bigDecimalWritable = new BigDecimalWritable();
 
   public abstract ByteWritable evaluate(ByteWritable a, ByteWritable b);
 
@@ -61,4 +63,5 @@ public abstract class UDFBaseNumericOp e
 
   public abstract DoubleWritable evaluate(DoubleWritable a, DoubleWritable b);
 
+  public abstract BigDecimalWritable evaluate(BigDecimalWritable a, BigDecimalWritable b);
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericUnaryOp.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericUnaryOp.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericUnaryOp.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFBaseNumericUnaryOp.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -45,6 +46,7 @@ public abstract class UDFBaseNumericUnar
   protected LongWritable longWritable = new LongWritable();
   protected FloatWritable floatWritable = new FloatWritable();
   protected DoubleWritable doubleWritable = new DoubleWritable();
+  protected BigDecimalWritable bigDecimalWritable = new BigDecimalWritable();
 
   public abstract ByteWritable evaluate(ByteWritable a);
 
@@ -58,4 +60,5 @@ public abstract class UDFBaseNumericUnar
 
   public abstract DoubleWritable evaluate(DoubleWritable a);
 
+  public abstract BigDecimalWritable evaluate(BigDecimalWritable a);
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFCeil.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFCeil.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFCeil.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFCeil.java Wed Jan 16 23:04:24 2013
@@ -18,8 +18,13 @@
 
 package org.apache.hadoop.hive.ql.udf;
 
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
+
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.io.LongWritable;
 
@@ -34,7 +39,8 @@ import org.apache.hadoop.io.LongWritable
     + "  0\n"
     + "  > SELECT _FUNC_(5) FROM src LIMIT 1;\n" + "  5")
 public class UDFCeil extends UDF {
-  private LongWritable longWritable = new LongWritable();
+  private final LongWritable longWritable = new LongWritable();
+  private final BigDecimalWritable bigDecimalWritable = new BigDecimalWritable();
 
   public UDFCeil() {
   }
@@ -48,4 +54,14 @@ public class UDFCeil extends UDF {
     }
   }
 
+  public BigDecimalWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      BigDecimal bd = i.getBigDecimal();
+      int origScale = bd.scale();
+      bigDecimalWritable.set(bd.setScale(0, BigDecimal.ROUND_CEILING).setScale(origScale));
+      return bigDecimalWritable;
+    }
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFloor.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFloor.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFloor.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFloor.java Wed Jan 16 23:04:24 2013
@@ -18,8 +18,13 @@
 
 package org.apache.hadoop.hive.ql.udf;
 
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
+
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.io.LongWritable;
 
@@ -34,7 +39,8 @@ import org.apache.hadoop.io.LongWritable
     + "  -1\n"
     + "  > SELECT _FUNC_(5) FROM src LIMIT 1;\n" + "  5")
 public class UDFFloor extends UDF {
-  private LongWritable result = new LongWritable();
+  private final LongWritable result = new LongWritable();
+  private final BigDecimalWritable bdResult = new BigDecimalWritable();
 
   public UDFFloor() {
   }
@@ -48,4 +54,14 @@ public class UDFFloor extends UDF {
     }
   }
 
+  public BigDecimalWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      BigDecimal bd = i.getBigDecimal();
+      int origScale = bd.scale();
+      bdResult.set(bd.setScale(0, BigDecimal.ROUND_FLOOR).setScale(origScale));
+      return bdResult;
+    }
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java Wed Jan 16 23:04:24 2013
@@ -18,8 +18,12 @@
 
 package org.apache.hadoop.hive.ql.udf;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 
 /**
@@ -29,12 +33,15 @@ import org.apache.hadoop.hive.serde2.io.
 @Description(name = "/", value = "a _FUNC_ b - Divide a by b", extended = "Example:\n"
     + "  > SELECT 3 _FUNC_ 2 FROM src LIMIT 1;\n" + "  1.5")
 /**
- * Note that in SQL, the return type of divide is not necessarily the same 
+ * Note that in SQL, the return type of divide is not necessarily the same
  * as the parameters. For example, 3 / 2 = 1.5, not 1. To follow SQL, we always
  * return a double for divide.
  */
 public class UDFOPDivide extends UDF {
-  private DoubleWritable doubleWritable = new DoubleWritable();
+  private final DoubleWritable doubleWritable = new DoubleWritable();
+  private final BigDecimalWritable bigDecimalWritable = new BigDecimalWritable();
+
+  private final int MAX_SCALE = 65; // max compatible with MySQL
 
   public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
     // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
@@ -46,4 +53,18 @@ public class UDFOPDivide extends UDF {
     doubleWritable.set(a.get() / b.get());
     return doubleWritable;
   }
+
+  public BigDecimalWritable evaluate(BigDecimalWritable a, BigDecimalWritable b) {
+    if ((a == null) || (b == null)) {
+      return null;
+    }
+    if (b.getBigDecimal().compareTo(BigDecimal.ZERO) == 0) {
+      return null;
+    } else {
+        bigDecimalWritable.set(a.getBigDecimal().divide(
+          b.getBigDecimal(), MAX_SCALE, RoundingMode.HALF_UP));
+    }
+
+    return bigDecimalWritable;
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMinus.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMinus.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMinus.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMinus.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -107,4 +108,15 @@ public class UDFOPMinus extends UDFBaseN
     doubleWritable.set(a.get() - b.get());
     return doubleWritable;
   }
+
+  @Override
+  public BigDecimalWritable evaluate(BigDecimalWritable a, BigDecimalWritable b) {
+
+    if ((a == null) || (b == null)) {
+      return null;
+    }
+
+    bigDecimalWritable.set(a.getBigDecimal().subtract(b.getBigDecimal()));
+    return bigDecimalWritable;
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java Wed Jan 16 23:04:24 2013
@@ -18,7 +18,10 @@
 
 package org.apache.hadoop.hive.ql.udf;
 
+import java.math.BigDecimal;
+
 import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -107,4 +110,21 @@ public class UDFOPMod extends UDFBaseNum
     doubleWritable.set(a.get() % b.get());
     return doubleWritable;
   }
+
+  @Override
+  public BigDecimalWritable evaluate(BigDecimalWritable a, BigDecimalWritable b) {
+    if ((a == null) || (b == null)) {
+      return null;
+    }
+
+    BigDecimal av = a.getBigDecimal();
+    BigDecimal bv = b.getBigDecimal();
+
+    if (bv.compareTo(BigDecimal.ZERO) == 0) {
+      return null;
+    }
+
+    bigDecimalWritable.set(av.remainder(bv));
+    return bigDecimalWritable;
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -107,4 +108,14 @@ public class UDFOPMultiply extends UDFBa
     doubleWritable.set(a.get() * b.get());
     return doubleWritable;
   }
+
+  @Override
+  public BigDecimalWritable evaluate(BigDecimalWritable a, BigDecimalWritable b) {
+    if ((a == null) || (b == null)) {
+      return null;
+    }
+
+    bigDecimalWritable.set(a.getBigDecimal().multiply(b.getBigDecimal()));
+    return bigDecimalWritable;
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -90,4 +91,13 @@ public class UDFOPNegative extends UDFBa
     return doubleWritable;
   }
 
+  @Override
+  public BigDecimalWritable evaluate(BigDecimalWritable a) {
+    if (a == null) {
+      return null;
+    }
+    bigDecimalWritable.set(a.getBigDecimal().negate());
+    return bigDecimalWritable;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -113,4 +114,14 @@ public class UDFOPPlus extends UDFBaseNu
     return doubleWritable;
   }
 
+  @Override
+  public BigDecimalWritable evaluate(BigDecimalWritable a, BigDecimalWritable b) {
+    if ((a == null) || (b == null)) {
+      return null;
+    }
+
+    bigDecimalWritable.set(a.getBigDecimal().add(b.getBigDecimal()));
+    return bigDecimalWritable;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -66,4 +67,9 @@ public class UDFOPPositive extends UDFBa
     return a;
   }
 
+  @Override
+  public BigDecimalWritable evaluate(BigDecimalWritable a) {
+    return a;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java Wed Jan 16 23:04:24 2013
@@ -18,7 +18,10 @@
 
 package org.apache.hadoop.hive.ql.udf;
 
+import java.math.BigDecimal;
+
 import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -108,4 +111,21 @@ public class UDFPosMod extends UDFBaseNu
     doubleWritable.set(((a.get() % b.get()) + b.get()) % b.get());
     return doubleWritable;
   }
+
+  @Override
+  public BigDecimalWritable evaluate(BigDecimalWritable a, BigDecimalWritable b) {
+    if ((a == null) || (b == null)) {
+      return null;
+    }
+
+    BigDecimal av = a.getBigDecimal();
+    BigDecimal bv = b.getBigDecimal();
+
+    if (bv.compareTo(BigDecimal.ZERO) == 0) {
+      return null;
+    }
+
+    bigDecimalWritable.set(av.remainder(bv).add(bv).remainder(bv));
+    return bigDecimalWritable;
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java Wed Jan 16 23:04:24 2013
@@ -20,7 +20,9 @@ package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.io.IntWritable;
 
 /**
  * UDFPower.
@@ -31,7 +33,8 @@ import org.apache.hadoop.hive.serde2.io.
     extended = "Example:\n"
     + "  > SELECT _FUNC_(2, 3) FROM src LIMIT 1;\n" + "  8")
 public class UDFPower extends UDF {
-  private DoubleWritable result = new DoubleWritable();
+  private final DoubleWritable resultDouble = new DoubleWritable();
+  private final BigDecimalWritable resultBigDecimal = new BigDecimalWritable();
 
   public UDFPower() {
   }
@@ -43,8 +46,32 @@ public class UDFPower extends UDF {
     if (a == null || b == null) {
       return null;
     } else {
-      result.set(Math.pow(a.get(), b.get()));
-      return result;
+      resultDouble.set(Math.pow(a.get(), b.get()));
+      return resultDouble;
+    }
+  }
+  
+  /**
+   * Raise a to the power of b.
+   */
+  public DoubleWritable evaluate(DoubleWritable a, IntWritable b) {
+    if (a == null || b == null) {
+      return null;
+    } else {
+      resultDouble.set(Math.pow(a.get(), b.get()));
+      return resultDouble;
+    }
+  }
+  
+  /**
+   * Raise a to the power of b
+   */
+  public BigDecimalWritable evaluate(BigDecimalWritable a, IntWritable b) {
+    if (a == null || b == null) {
+      return null;
+    } else {
+      resultBigDecimal.set(a.getBigDecimal().pow(b.get()));
+      return resultBigDecimal;
     }
   }
 

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java Wed Jan 16 23:04:24 2013
@@ -23,6 +23,7 @@ import java.math.RoundingMode;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.io.IntWritable;
 
@@ -35,6 +36,7 @@ import org.apache.hadoop.io.IntWritable;
     extended = "Example:\n"
     + "  > SELECT _FUNC_(12.3456, 1) FROM src LIMIT 1;\n" + "  12.3'")
 public class UDFRound extends UDF {
+  private final BigDecimalWritable bigDecimalWritable = new BigDecimalWritable();
   private final DoubleWritable doubleWritable = new DoubleWritable();
 
   public UDFRound() {
@@ -65,4 +67,25 @@ public class UDFRound extends UDF {
     return evaluate(n, i.get());
   }
 
+  private BigDecimalWritable evaluate(BigDecimalWritable n, int i) {
+    if (n == null) {
+      return null;
+    }
+    BigDecimal bd = n.getBigDecimal();
+    bd = n.getBigDecimal().setScale(i, RoundingMode.HALF_UP);
+    bigDecimalWritable.set(bd);
+    return bigDecimalWritable;
+  }
+
+  public BigDecimalWritable evaluate(BigDecimalWritable n) {
+    return evaluate(n, 0);
+  }
+
+  public BigDecimalWritable evaluate(BigDecimalWritable n, IntWritable i) {
+    if (i == null) {
+      return null;
+    }
+    return evaluate(n, i.get());
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java Wed Jan 16 23:04:24 2013
@@ -18,7 +18,10 @@
 
 package org.apache.hadoop.hive.ql.udf;
 
+import java.math.BigDecimal;
+
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -35,7 +38,7 @@ import org.apache.hadoop.io.Text;
  *
  */
 public class UDFToBoolean extends UDF {
-  private BooleanWritable booleanWritable = new BooleanWritable();
+  private final BooleanWritable booleanWritable = new BooleanWritable();
 
   public UDFToBoolean() {
   }
@@ -172,4 +175,13 @@ public class UDFToBoolean extends UDF {
     }
   }
 
+  public BooleanWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      booleanWritable.set(BigDecimal.ZERO.compareTo(i.getBigDecimal()) != 0);
+      return booleanWritable;
+    }
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -36,7 +37,7 @@ import org.apache.hadoop.io.Text;
  *
  */
 public class UDFToByte extends UDF {
-  private ByteWritable byteWritable = new ByteWritable();
+  private final ByteWritable byteWritable = new ByteWritable();
 
   public UDFToByte() {
   }
@@ -181,4 +182,12 @@ public class UDFToByte extends UDF {
     }
   }
 
+  public ByteWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      byteWritable.set(i.getBigDecimal().byteValue());
+      return byteWritable;
+    }
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -34,7 +35,7 @@ import org.apache.hadoop.io.Text;
  *
  */
 public class UDFToDouble extends UDF {
-  private DoubleWritable doubleWritable = new DoubleWritable();
+  private final DoubleWritable doubleWritable = new DoubleWritable();
 
   public UDFToDouble() {
   }
@@ -183,4 +184,12 @@ public class UDFToDouble extends UDF {
     }
   }
 
+  public DoubleWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      doubleWritable.set(i.getBigDecimal().doubleValue());
+      return doubleWritable;
+    }
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -35,7 +36,7 @@ import org.apache.hadoop.io.Text;
  *
  */
 public class UDFToFloat extends UDF {
-  private FloatWritable floatWritable = new FloatWritable();
+  private final FloatWritable floatWritable = new FloatWritable();
 
   public UDFToFloat() {
   }
@@ -184,4 +185,13 @@ public class UDFToFloat extends UDF {
     }
   }
 
+  public FloatWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      floatWritable.set(i.getBigDecimal().floatValue());
+      return floatWritable;
+    }
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -36,7 +37,7 @@ import org.apache.hadoop.io.Text;
  *
  */
 public class UDFToInteger extends UDF {
-  private IntWritable intWritable = new IntWritable();
+  private final IntWritable intWritable = new IntWritable();
 
   public UDFToInteger() {
   }
@@ -188,4 +189,13 @@ public class UDFToInteger extends UDF {
     }
   }
 
+  public IntWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      intWritable.set(i.getBigDecimal().intValue());
+      return intWritable;
+    }
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToLong.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToLong.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToLong.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToLong.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -36,7 +37,7 @@ import org.apache.hadoop.io.Text;
  *
  */
 public class UDFToLong extends UDF {
-  private LongWritable longWritable = new LongWritable();
+  private final LongWritable longWritable = new LongWritable();
 
   public UDFToLong() {
   }
@@ -192,4 +193,13 @@ public class UDFToLong extends UDF {
     }
   }
 
+  public LongWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      longWritable.set(i.getBigDecimal().longValue());
+      return longWritable;
+    }
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToShort.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToShort.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToShort.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToShort.java Wed Jan 16 23:04:24 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -181,4 +182,13 @@ public class UDFToShort extends UDF {
     }
   }
 
+  public ShortWritable evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      shortWritable.set(i.getBigDecimal().shortValue());
+      return shortWritable;
+    }
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java Wed Jan 16 23:04:24 2013
@@ -20,6 +20,7 @@ package org.apache.hadoop.hive.ql.udf;
 
 import org.apache.hadoop.hive.ql.exec.UDF;
 import org.apache.hadoop.hive.serde2.ByteStream;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
@@ -141,10 +142,19 @@ public class UDFToString extends UDF {
     }
   }
 
+  public Text evaluate(BigDecimalWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      t.set(i.toString());
+      return t;
+    }
+  }
+
   public Text evaluate (BytesWritable bw) {
     if (null == bw) {
       return null;
-}
+    }
     t.set(bw.getBytes(),0,bw.getLength());
     return t;
   }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCorrelation.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCorrelation.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCorrelation.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCorrelation.java Wed Jan 16 23:04:24 2013
@@ -102,6 +102,7 @@ public class GenericUDAFCorrelation exte
     case FLOAT:
     case DOUBLE:
     case TIMESTAMP:
+    case DECIMAL:
       switch (((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()) {
       case BYTE:
       case SHORT:
@@ -110,6 +111,7 @@ public class GenericUDAFCorrelation exte
       case FLOAT:
       case DOUBLE:
       case TIMESTAMP:
+      case DECIMAL:
         return new GenericUDAFCorrelationEvaluator();
       case STRING:
       case BOOLEAN:

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovariance.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovariance.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovariance.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovariance.java Wed Jan 16 23:04:24 2013
@@ -93,6 +93,7 @@ public class GenericUDAFCovariance exten
     case FLOAT:
     case DOUBLE:
     case TIMESTAMP:
+    case DECIMAL:
       switch (((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()) {
       case BYTE:
       case SHORT:
@@ -101,6 +102,7 @@ public class GenericUDAFCovariance exten
       case FLOAT:
       case DOUBLE:
       case TIMESTAMP:
+      case DECIMAL:
         return new GenericUDAFCovarianceEvaluator();
       case STRING:
       case BOOLEAN:

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovarianceSample.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovarianceSample.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovarianceSample.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovarianceSample.java Wed Jan 16 23:04:24 2013
@@ -67,6 +67,7 @@ public class GenericUDAFCovarianceSample
     case FLOAT:
     case DOUBLE:
     case TIMESTAMP:
+    case DECIMAL:
       switch (((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()) {
       case BYTE:
       case SHORT:
@@ -75,6 +76,7 @@ public class GenericUDAFCovarianceSample
       case FLOAT:
       case DOUBLE:
       case TIMESTAMP:
+      case DECIMAL:
         return new GenericUDAFCovarianceSampleEvaluator();
       case STRING:
       case BOOLEAN:

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFHistogramNumeric.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFHistogramNumeric.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFHistogramNumeric.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFHistogramNumeric.java Wed Jan 16 23:04:24 2013
@@ -45,7 +45,7 @@ import org.apache.hadoop.util.StringUtil
 
 /**
  * Computes an approximate histogram of a numerical column using a user-specified number of bins.
- * 
+ *
  * The output is an array of (x,y) pairs as Hive struct objects that represents the histogram's
  * bin centers and heights.
  */
@@ -72,7 +72,7 @@ public class GenericUDAFHistogramNumeric
       throw new UDFArgumentTypeException(parameters.length - 1,
           "Please specify exactly two arguments.");
     }
-    
+
     // validate the first parameter, which is the expression to compute over
     if (parameters[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
       throw new UDFArgumentTypeException(0,
@@ -87,6 +87,7 @@ public class GenericUDAFHistogramNumeric
     case FLOAT:
     case DOUBLE:
     case TIMESTAMP:
+    case DECIMAL:
       break;
     case STRING:
     case BOOLEAN:
@@ -170,7 +171,7 @@ public class GenericUDAFHistogramNumeric
 
     @Override
     public Object terminatePartial(AggregationBuffer agg) throws HiveException {
-      // Return a single ArrayList where the first element is the number of histogram bins, 
+      // Return a single ArrayList where the first element is the number of histogram bins,
       // and subsequent elements represent histogram (x,y) pairs.
       StdAgg myagg = (StdAgg) agg;
       return myagg.histogram.serialize();
@@ -233,7 +234,7 @@ public class GenericUDAFHistogramNumeric
     }
 
 
-    // Aggregation buffer definition and manipulation methods 
+    // Aggregation buffer definition and manipulation methods
     static class StdAgg implements AggregationBuffer {
       NumericHistogram histogram; // the histogram object
     };

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentileApprox.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentileApprox.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentileApprox.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentileApprox.java Wed Jan 16 23:04:24 2013
@@ -46,7 +46,7 @@ import org.apache.hadoop.util.StringUtil
 /**
  * Computes an approximate percentile (quantile) from an approximate histogram, for very
  * large numbers of rows where the regular percentile() UDAF might run out of memory.
- * 
+ *
  * The input is a single double value or an array of double values representing the quantiles
  * requested. The output, corresponding to the input, is either an single double value or an
  * array of doubles that are the quantile values.
@@ -59,7 +59,7 @@ import org.apache.hadoop.util.StringUtil
     extended = "'expr' can be any numeric column, including doubles and floats, and 'pc' is " +
                "either a single double/float with a requested percentile, or an array of double/" +
                "float with multiple percentiles. If 'nb' is not specified, the default " +
-               "approximation is done with 10,000 histogram bins, which means that if there are " + 
+               "approximation is done with 10,000 histogram bins, which means that if there are " +
                "10,000 or fewer unique values in 'expr', you can expect an exact result. The " +
                "percentile() function always computes an exact percentile and can run out of " +
                "memory if there are too many unique values in a column, which necessitates " +
@@ -77,7 +77,7 @@ public class GenericUDAFPercentileApprox
       throw new UDFArgumentTypeException(parameters.length - 1,
           "Please specify either two or three arguments.");
     }
-    
+
     // Validate the first parameter, which is the expression to compute over. This should be a
     // numeric primitive type.
     if (parameters[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
@@ -93,6 +93,7 @@ public class GenericUDAFPercentileApprox
     case FLOAT:
     case DOUBLE:
     case TIMESTAMP:
+    case DECIMAL:
       break;
     default:
       throw new UDFArgumentTypeException(0,
@@ -147,7 +148,7 @@ public class GenericUDAFPercentileApprox
     // Also make sure it is a constant.
     if (!ObjectInspectorUtils.isConstantObjectInspector(parameters[1])) {
       throw new UDFArgumentTypeException(1,
-        "The second argument must be a constant, but " + parameters[1].getTypeName() + 
+        "The second argument must be a constant, but " + parameters[1].getTypeName() +
         " was passed instead.");
     }
 
@@ -172,7 +173,7 @@ public class GenericUDAFPercentileApprox
       // Also make sure it is a constant.
       if (!ObjectInspectorUtils.isConstantObjectInspector(parameters[2])) {
         throw new UDFArgumentTypeException(2,
-          "The third argument must be a constant, but " + parameters[2].getTypeName() + 
+          "The third argument must be a constant, but " + parameters[2].getTypeName() +
           " was passed instead.");
       }
     }
@@ -184,7 +185,7 @@ public class GenericUDAFPercentileApprox
       return new GenericUDAFSinglePercentileApproxEvaluator();
     }
   }
-  
+
   public static class GenericUDAFSinglePercentileApproxEvaluator extends
     GenericUDAFPercentileApproxEvaluator {
 
@@ -234,7 +235,7 @@ public class GenericUDAFPercentileApprox
     }
   }
 
-  
+
   public static class GenericUDAFMultiplePercentileApproxEvaluator extends
     GenericUDAFPercentileApproxEvaluator {
 
@@ -299,7 +300,7 @@ public class GenericUDAFPercentileApprox
 
     @Override
     public void merge(AggregationBuffer agg, Object partial) throws HiveException {
-      if(partial == null) { 
+      if(partial == null) {
         return;
       }
       PercentileAggBuf myagg = (PercentileAggBuf) agg;
@@ -316,7 +317,7 @@ public class GenericUDAFPercentileApprox
       }
 
       // merge histograms
-      myagg.histogram.merge(partialHistogram);           
+      myagg.histogram.merge(partialHistogram);
     }
 
     @Override
@@ -382,7 +383,7 @@ public class GenericUDAFPercentileApprox
       } else {
         result = new double[1];
         result[0] = PrimitiveObjectInspectorUtils.getDouble(
-              quantileObj, 
+              quantileObj,
               (PrimitiveObjectInspector)quantileOI);
       }
       for(int ii = 0; ii < result.length; ++ii) {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStd.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStd.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStd.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStd.java Wed Jan 16 23:04:24 2013
@@ -28,7 +28,7 @@ import org.apache.hadoop.hive.serde2.typ
 /**
  * Compute the standard deviation by extending GenericUDAFVariance and
  * overriding the terminate() method of the evaluator.
- * 
+ *
  */
 @Description(name = "std,stddev,stddev_pop",
     value = "_FUNC_(x) - Returns the standard deviation of a set of numbers")
@@ -56,6 +56,7 @@ public class GenericUDAFStd extends Gene
     case DOUBLE:
     case STRING:
     case TIMESTAMP:
+    case DECIMAL:
       return new GenericUDAFStdEvaluator();
     case BOOLEAN:
     default:
@@ -68,7 +69,7 @@ public class GenericUDAFStd extends Gene
   /**
    * Compute the standard deviation by extending GenericUDAFVarianceEvaluator
    * and overriding the terminate() method of the evaluator.
-   * 
+   *
    */
   public static class GenericUDAFStdEvaluator extends
       GenericUDAFVarianceEvaluator {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStdSample.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStdSample.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStdSample.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStdSample.java Wed Jan 16 23:04:24 2013
@@ -28,7 +28,7 @@ import org.apache.hadoop.hive.serde2.typ
 /**
  * Compute the sample standard deviation by extending GenericUDAFVariance and
  * overriding the terminate() method of the evaluator.
- * 
+ *
  */
 @Description(name = "stddev_samp",
     value = "_FUNC_(x) - Returns the sample standard deviation of a set of numbers")
@@ -55,6 +55,7 @@ public class GenericUDAFStdSample extend
     case DOUBLE:
     case STRING:
     case TIMESTAMP:
+    case DECIMAL:
       return new GenericUDAFStdSampleEvaluator();
     case BOOLEAN:
     default:

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java Wed Jan 16 23:04:24 2013
@@ -17,12 +17,15 @@
  */
 package org.apache.hadoop.hive.ql.udf.generic;
 
+import java.math.BigDecimal;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.serde2.io.BigDecimalWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
@@ -66,6 +69,8 @@ public class GenericUDAFSum extends Abst
     case DOUBLE:
     case STRING:
       return new GenericUDAFSumDouble();
+    case DECIMAL:
+      return new GenericUDAFSumBigDecimal();
     case BOOLEAN:
     default:
       throw new UDFArgumentTypeException(0,
@@ -75,6 +80,89 @@ public class GenericUDAFSum extends Abst
   }
 
   /**
+   * GenericUDAFSumBigDecimal.
+   *
+   */
+  public static class GenericUDAFSumBigDecimal extends GenericUDAFEvaluator {
+    private PrimitiveObjectInspector inputOI;
+    private BigDecimalWritable result;
+
+    @Override
+    public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException {
+      assert (parameters.length == 1);
+      super.init(m, parameters);
+      result = new BigDecimalWritable(BigDecimal.ZERO);
+      inputOI = (PrimitiveObjectInspector) parameters[0];
+      return PrimitiveObjectInspectorFactory.writableBigDecimalObjectInspector;
+    }
+
+    /** class for storing decimal sum value. */
+    static class SumBigDecimalAgg implements AggregationBuffer {
+      boolean empty;
+      BigDecimal sum;
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      SumBigDecimalAgg agg = new SumBigDecimalAgg();
+      reset(agg);
+      return agg;
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      SumBigDecimalAgg bdAgg = (SumBigDecimalAgg) agg;
+      bdAgg.empty = true;
+      bdAgg.sum = BigDecimal.ZERO;
+    }
+
+    boolean warned = false;
+
+    @Override
+    public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException {
+      assert (parameters.length == 1);
+      try {
+        merge(agg, parameters[0]);
+      } catch (NumberFormatException e) {
+        if (!warned) {
+          warned = true;
+          LOG.warn(getClass().getSimpleName() + " "
+              + StringUtils.stringifyException(e));
+          LOG
+              .warn(getClass().getSimpleName()
+              + " ignoring similar exceptions.");
+        }
+      }
+    }
+
+    @Override
+    public Object terminatePartial(AggregationBuffer agg) throws HiveException {
+      return terminate(agg);
+    }
+
+    @Override
+    public void merge(AggregationBuffer agg, Object partial) throws HiveException {
+      if (partial != null) {
+        SumBigDecimalAgg myagg = (SumBigDecimalAgg) agg;
+        myagg.empty = false;
+        myagg.sum = myagg.sum.add(
+            PrimitiveObjectInspectorUtils.getBigDecimal(partial, inputOI));
+      }
+    }
+
+    @Override
+    public Object terminate(AggregationBuffer agg) throws HiveException {
+      SumBigDecimalAgg myagg = (SumBigDecimalAgg) agg;
+      if (myagg.empty) {
+        return null;
+      }
+      result.set(myagg.sum);
+      return result;
+    }
+
+  }
+
+  /**
    * GenericUDAFSumDouble.
    *
    */

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVariance.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVariance.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVariance.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVariance.java Wed Jan 16 23:04:24 2013
@@ -43,7 +43,7 @@ import org.apache.hadoop.util.StringUtil
 /**
  * Compute the variance. This class is extended by: GenericUDAFVarianceSample
  * GenericUDAFStd GenericUDAFStdSample
- * 
+ *
  */
 @Description(name = "variance,var_pop",
     value = "_FUNC_(x) - Returns the variance of a set of numbers")
@@ -72,6 +72,7 @@ public class GenericUDAFVariance extends
     case DOUBLE:
     case STRING:
     case TIMESTAMP:
+    case DECIMAL:
       return new GenericUDAFVarianceEvaluator();
     case BOOLEAN:
     default:
@@ -85,18 +86,18 @@ public class GenericUDAFVariance extends
    * Evaluate the variance using the algorithm described by Chan, Golub, and LeVeque in
    * "Algorithms for computing the sample variance: analysis and recommendations"
    * The American Statistician, 37 (1983) pp. 242--247.
-   * 
+   *
    * variance = variance1 + variance2 + n/(m*(m+n)) * pow(((m/n)*t1 - t2),2)
-   * 
+   *
    * where: - variance is sum[x-avg^2] (this is actually n times the variance)
    * and is updated at every step. - n is the count of elements in chunk1 - m is
-   * the count of elements in chunk2 - t1 = sum of elements in chunk1, t2 = 
+   * the count of elements in chunk2 - t1 = sum of elements in chunk1, t2 =
    * sum of elements in chunk2.
    *
    * This algorithm was proven to be numerically stable by J.L. Barlow in
    * "Error analysis of a pairwise summation algorithm to compute sample variance"
    * Numer. Math, 58 (1991) pp. 583--590
-   * 
+   *
    */
   public static class GenericUDAFVarianceEvaluator extends GenericUDAFEvaluator {
 

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVarianceSample.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVarianceSample.java?rev=1434468&r1=1434467&r2=1434468&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVarianceSample.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFVarianceSample.java Wed Jan 16 23:04:24 2013
@@ -28,7 +28,7 @@ import org.apache.hadoop.hive.serde2.typ
 /**
  * Compute the sample variance by extending GenericUDAFVariance and overriding
  * the terminate() method of the evaluator.
- * 
+ *
  */
 @Description(name = "var_samp",
     value = "_FUNC_(x) - Returns the sample variance of a set of numbers")
@@ -56,6 +56,7 @@ public class GenericUDAFVarianceSample e
     case DOUBLE:
     case STRING:
     case TIMESTAMP:
+    case DECIMAL:
       return new GenericUDAFVarianceSampleEvaluator();
     case BOOLEAN:
     default:

Added: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToDecimal.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToDecimal.java?rev=1434468&view=auto
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToDecimal.java (added)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToDecimal.java Wed Jan 16 23:04:24 2013
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.BigDecimalConverter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+
+@Description(name = "decimal", value = "_FUNC_(a) - cast a to decimal")
+public class GenericUDFToDecimal extends GenericUDF {
+
+  private PrimitiveObjectInspector argumentOI;
+  private BigDecimalConverter bdConverter;
+
+  @Override
+  public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+    if (arguments.length < 1) {
+      throw new UDFArgumentLengthException(
+          "The function DECIMAL requires at least one argument, got "
+          + arguments.length);
+    }
+    try {
+      argumentOI = (PrimitiveObjectInspector) arguments[0];
+    } catch (ClassCastException e) {
+      throw new UDFArgumentException(
+          "The function DECIMAL takes only primitive types");
+    }
+
+    bdConverter = new BigDecimalConverter(argumentOI,
+        PrimitiveObjectInspectorFactory.writableBigDecimalObjectInspector);
+    return PrimitiveObjectInspectorFactory.writableBigDecimalObjectInspector;
+  }
+
+  @Override
+  public Object evaluate(DeferredObject[] arguments) throws HiveException {
+    Object o0 = arguments[0].get();
+    if (o0 == null) {
+      return null;
+    }
+
+    return bdConverter.convert(o0);
+  }
+
+  @Override
+  public String getDisplayString(String[] children) {
+    assert (children.length == 1);
+    StringBuilder sb = new StringBuilder();
+    sb.append("CAST( ");
+    sb.append(children[0]);
+    sb.append(" AS DECIMAL)");
+    return sb.toString();
+  }
+
+}



Mime
View raw message