hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sd...@apache.org
Subject svn commit: r1157222 [1/3] - in /hive/trunk: ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/java/org/apache/hadoop/hive/ql/udf/ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/ ql/src/test/queries/clie...
Date Fri, 12 Aug 2011 19:21:38 GMT
Author: sdong
Date: Fri Aug 12 19:21:36 2011
New Revision: 1157222

URL: http://svn.apache.org/viewvc?rev=1157222&view=rev
Log:
HIVE-2272. add TIMESTAMP data type (Franklin Hu via Siying Dong)

Added:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTimestamp.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToUtcTimestamp.java
    hive/trunk/ql/src/test/queries/clientpositive/timestamp_1.q
    hive/trunk/ql/src/test/queries/clientpositive/timestamp_2.q
    hive/trunk/ql/src/test/queries/clientpositive/timestamp_3.q
    hive/trunk/ql/src/test/queries/clientpositive/timestamp_comparison.q
    hive/trunk/ql/src/test/queries/clientpositive/timestamp_udf.q
    hive/trunk/ql/src/test/results/clientpositive/timestamp_1.q.out
    hive/trunk/ql/src/test/results/clientpositive/timestamp_2.q.out
    hive/trunk/ql/src/test/results/clientpositive/timestamp_3.q.out
    hive/trunk/ql/src/test/results/clientpositive/timestamp_comparison.q.out
    hive/trunk/ql/src/test/results/clientpositive/timestamp_udf.q.out
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyTimestamp.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/objectinspector/primitive/LazyTimestampObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryTimestamp.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaTimestampObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/SettableTimestampObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/TimestampObjectInspector.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableTimestampObjectInspector.java
Removed:
    hive/trunk/ql/src/test/queries/clientnegative/invalid_t_create3.q
    hive/trunk/ql/src/test/results/clientnegative/invalid_t_create3.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.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/ErrorMsg.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDate.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateAdd.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateDiff.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateSub.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.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/UDFUnixTimeStamp.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFWeekOfYear.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFAverage.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFContextNGrams.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/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFnGrams.java
    hive/trunk/ql/src/test/results/clientnegative/invalid_create_tbl1.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_t_alter1.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_t_alter2.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_t_create1.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_t_create2.q.out
    hive/trunk/ql/src/test/results/clientnegative/invalid_t_transform.q.out
    hive/trunk/ql/src/test/results/clientnegative/wrong_column_type.q.out
    hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
    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/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

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -155,6 +155,7 @@ import org.apache.hadoop.hive.ql.udf.gen
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFEWAHBitmapOr;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFElt;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFField;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFFromUtcTimestamp;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFHash;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFIf;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFIn;
@@ -181,6 +182,8 @@ import org.apache.hadoop.hive.ql.udf.gen
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFSplit;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFStringToMap;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFStruct;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFTimestamp;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUtcTimestamp;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFUnion;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDFWhen;
 import org.apache.hadoop.hive.ql.udf.generic.GenericUDTF;
@@ -368,6 +371,9 @@ public final class FunctionRegistry {
     registerUDF(Constants.STRING_TYPE_NAME, UDFToString.class, false,
         UDFToString.class.getSimpleName());
 
+    registerGenericUDF(Constants.TIMESTAMP_TYPE_NAME,
+        GenericUDFTimestamp.class);
+
     // Aggregate functions
     registerGenericUDAF("max", new GenericUDAFMax());
     registerGenericUDAF("min", new GenericUDAFMin());
@@ -420,6 +426,10 @@ public final class FunctionRegistry {
     registerGenericUDF("map_keys", GenericUDFMapKeys.class);
     registerGenericUDF("map_values", GenericUDFMapValues.class);
 
+    registerGenericUDF("from_utc_timestamp", GenericUDFFromUtcTimestamp.class);
+    registerGenericUDF("to_utc_timestamp", GenericUDFToUtcTimestamp.class);
+
+
     // Generic UDTF's
     registerGenericUDTF("explode", GenericUDTFExplode.class);
     registerGenericUDTF("json_tuple", GenericUDTFJSONTuple.class);
@@ -622,6 +632,9 @@ public final class FunctionRegistry {
    * @return null if no common class could be found.
    */
   public static TypeInfo getCommonClass(TypeInfo a, TypeInfo b) {
+    if (a.equals(b)) {
+      return a;
+    }
     Integer ai = numericTypes.get(a);
     Integer bi = numericTypes.get(b);
     if (ai == null || bi == null) {
@@ -649,6 +662,11 @@ public final class FunctionRegistry {
       return true;
     }
 
+    if (from.equals(TypeInfoFactory.timestampTypeInfo)
+        && to.equals(TypeInfoFactory.stringTypeInfo)) {
+      return true;
+    }
+
     // Allow implicit conversion from Byte -> Integer -> Long -> Float -> Double
     // -> String
     Integer f = numericTypes.get(from);

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -33,9 +33,9 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
-import java.util.Map.Entry;
 
 import org.antlr.runtime.tree.CommonTree;
 import org.antlr.runtime.tree.Tree;
@@ -58,8 +58,8 @@ import org.apache.hadoop.hive.ql.exec.Ut
 import org.apache.hadoop.hive.ql.hooks.ReadEntity;
 import org.apache.hadoop.hive.ql.hooks.WriteEntity;
 import org.apache.hadoop.hive.ql.index.HiveIndex;
-import org.apache.hadoop.hive.ql.index.HiveIndexHandler;
 import org.apache.hadoop.hive.ql.index.HiveIndex.IndexType;
+import org.apache.hadoop.hive.ql.index.HiveIndexHandler;
 import org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat;
 import org.apache.hadoop.hive.ql.io.RCFileInputFormat;
 import org.apache.hadoop.hive.ql.metadata.Hive;
@@ -70,7 +70,9 @@ import org.apache.hadoop.hive.ql.metadat
 import org.apache.hadoop.hive.ql.plan.AddPartitionDesc;
 import org.apache.hadoop.hive.ql.plan.AlterDatabaseDesc;
 import org.apache.hadoop.hive.ql.plan.AlterIndexDesc;
+import org.apache.hadoop.hive.ql.plan.AlterIndexDesc.AlterIndexTypes;
 import org.apache.hadoop.hive.ql.plan.AlterTableDesc;
+import org.apache.hadoop.hive.ql.plan.AlterTableDesc.AlterTableTypes;
 import org.apache.hadoop.hive.ql.plan.AlterTableSimpleDesc;
 import org.apache.hadoop.hive.ql.plan.CreateDatabaseDesc;
 import org.apache.hadoop.hive.ql.plan.CreateIndexDesc;
@@ -105,8 +107,6 @@ import org.apache.hadoop.hive.ql.plan.St
 import org.apache.hadoop.hive.ql.plan.SwitchDatabaseDesc;
 import org.apache.hadoop.hive.ql.plan.TableDesc;
 import org.apache.hadoop.hive.ql.plan.UnlockTableDesc;
-import org.apache.hadoop.hive.ql.plan.AlterIndexDesc.AlterIndexTypes;
-import org.apache.hadoop.hive.ql.plan.AlterTableDesc.AlterTableTypes;
 import org.apache.hadoop.hive.ql.security.authorization.Privilege;
 import org.apache.hadoop.hive.ql.security.authorization.PrivilegeRegistry;
 import org.apache.hadoop.hive.ql.session.SessionState;
@@ -139,9 +139,8 @@ public class DDLSemanticAnalyzer extends
   }
 
   public static String getTypeName(int token) throws SemanticException {
-    // date, datetime, and timestamp types aren't currently supported
-    if (token == HiveParser.TOK_DATE || token == HiveParser.TOK_DATETIME ||
-        token == HiveParser.TOK_TIMESTAMP) {
+    // date and datetime types aren't currently supported
+    if (token == HiveParser.TOK_DATE || token == HiveParser.TOK_DATETIME) {
       throw new SemanticException(ErrorMsg.UNSUPPORTED_TYPE.getMsg());
     }
     return TokenToTypeName.get(token);

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java Fri Aug 12 19:21:36 2011
@@ -151,8 +151,8 @@ public enum ErrorMsg {
       + "Please check your hive.input.format setting and make sure your Hadoop version support "
       + "CombineFileInputFormat"),
   NONEXISTPARTCOL("Non-Partition column appears in the partition specification: "),
-  UNSUPPORTED_TYPE("DATE, DATETIME, and TIMESTAMP types aren't supported yet. Please use "
-      + "STRING instead"),
+  UNSUPPORTED_TYPE("DATE and DATETIME types aren't supported yet. Please use "
+      + "TIMESTAMP instead"),
   CREATE_NON_NATIVE_AS("CREATE TABLE AS SELECT cannot be used for a non-native table"),
   LOAD_INTO_NON_NATIVE("A non-native table cannot be used as target for LOAD"),
   LOCKMGR_NOT_SPECIFIED("Lock manager not specified correctly, set hive.lock.manager"),

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -458,6 +458,8 @@ public final class TypeCheckProcFactory 
           Constants.DOUBLE_TYPE_NAME);
       conversionFunctionTextHashMap.put(HiveParser.TOK_STRING,
           Constants.STRING_TYPE_NAME);
+      conversionFunctionTextHashMap.put(HiveParser.TOK_TIMESTAMP,
+          Constants.TIMESTAMP_TYPE_NAME);
     }
 
     public static boolean isRedundantConversionFunction(ASTNode expr,

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDate.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDate.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDate.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDate.java Fri Aug 12 19:21:36 2011
@@ -24,6 +24,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.Text;
 
 /**
@@ -45,7 +46,7 @@ public class UDFDate extends UDF {
 
   /**
    * Get the date part of a date time string.
-   * 
+   *
    * @param dateString
    *          the date string in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -66,4 +67,13 @@ public class UDFDate extends UDF {
     }
   }
 
+  public Text evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    }
+
+    t.set(formatter.format(i.getTimestamp()));
+    return t;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateAdd.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateAdd.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateAdd.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateAdd.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -52,11 +53,11 @@ public class UDFDateAdd extends UDF {
   /**
    * Add a number of days to the date. The time part of the string will be
    * ignored.
-   * 
+   *
    * NOTE: This is a subset of what MySQL offers as:
    * http://dev.mysql.com/doc/refman
    * /5.1/en/date-and-time-functions.html#function_date-add
-   * 
+   *
    * @param dateString1
    *          the date string in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -81,4 +82,15 @@ public class UDFDateAdd extends UDF {
     }
   }
 
+  public Text evaluate(TimestampWritable t, IntWritable days) {
+    if (t == null || days == null) {
+      return null;
+    }
+    calendar.setTime(t.getTimestamp());
+    calendar.add(Calendar.DAY_OF_MONTH, days.get());
+    Date newDate = calendar.getTime();
+    result.set(formatter.format(newDate));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateDiff.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateDiff.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateDiff.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateDiff.java Fri Aug 12 19:21:36 2011
@@ -20,10 +20,12 @@ package org.apache.hadoop.hive.ql.udf;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.TimeZone;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -42,7 +44,7 @@ import org.apache.hadoop.io.Text;
 public class UDFDateDiff extends UDF {
   private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
 
-  private IntWritable result = new IntWritable();
+  private final IntWritable result = new IntWritable();
 
   public UDFDateDiff() {
     formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -52,7 +54,7 @@ public class UDFDateDiff extends UDF {
    * Calculate the difference in the number of days. The time part of the string
    * will be ignored. If dateString1 is earlier than dateString2, then the
    * result can be negative.
-   * 
+   *
    * @param dateString1
    *          the date string in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -62,22 +64,54 @@ public class UDFDateDiff extends UDF {
    * @return the difference in days.
    */
   public IntWritable evaluate(Text dateString1, Text dateString2) {
+    return evaluate(toDate(dateString1), toDate(dateString2));
+  }
+
+  public IntWritable evaluate(TimestampWritable t1, TimestampWritable t2) {
+    return evaluate(toDate(t1), toDate(t2));
+  }
+
+  public IntWritable evaluate(TimestampWritable t, Text dateString) {
+    return evaluate(toDate(t), toDate(dateString));
+  }
 
-    if (dateString1 == null || dateString2 == null) {
+  public IntWritable evaluate(Text dateString, TimestampWritable t) {
+    return evaluate(toDate(dateString), toDate(t));
+  }
+
+  private IntWritable evaluate(Date date, Date date2) {
+    if (date == null || date2 == null) {
       return null;
     }
 
+    // NOTE: This implementation avoids the extra-second problem
+    // by comparing with UTC epoch and integer division.
+    // 86400 is the number of seconds in a day
+    long diffInMilliSeconds = date.getTime() - date2.getTime();
+    result.set((int) (diffInMilliSeconds / (86400 * 1000)));
+    return result;
+  }
+
+  private Date format(String dateString) {
     try {
-      // NOTE: This implementation avoids the extra-second problem
-      // by comparing with UTC epoch and integer division.
-      long diffInMilliSeconds = (formatter.parse(dateString1.toString())
-          .getTime() - formatter.parse(dateString2.toString()).getTime());
-      // 86400 is the number of seconds in a day
-      result.set((int) (diffInMilliSeconds / (86400 * 1000)));
-      return result;
+      return formatter.parse(dateString);
     } catch (ParseException e) {
       return null;
     }
   }
 
+  private Date toDate(Text dateString) {
+    if (dateString == null) {
+      return null;
+    }
+    return format(dateString.toString());
+  }
+
+  private Date toDate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+    return t.getTimestamp();
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateSub.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateSub.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateSub.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateSub.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -52,11 +53,11 @@ public class UDFDateSub extends UDF {
   /**
    * Subtract a number of days to the date. The time part of the string will be
    * ignored.
-   * 
+   *
    * NOTE: This is a subset of what MySQL offers as:
    * http://dev.mysql.com/doc/refman
    * /5.1/en/date-and-time-functions.html#function_date-sub
-   * 
+   *
    * @param dateString1
    *          the date string in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -81,4 +82,15 @@ public class UDFDateSub extends UDF {
     }
   }
 
+  public Text evaluate(TimestampWritable t, IntWritable days) {
+    if (t == null || days == null) {
+      return null;
+    }
+    calendar.setTime(t.getTimestamp());
+    calendar.add(Calendar.DAY_OF_MONTH, -days.get());
+    Date newDate = calendar.getTime();
+    result.set(formatter.format(newDate));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -49,7 +50,7 @@ public class UDFDayOfMonth extends UDF {
 
   /**
    * Get the day of month from a date string.
-   * 
+   *
    * @param dateString
    *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -72,4 +73,14 @@ public class UDFDayOfMonth extends UDF {
     }
   }
 
+  public IntWritable evaluate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+
+    calendar.setTime(t.getTimestamp());
+    result.set(calendar.get(Calendar.DAY_OF_MONTH));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -52,7 +53,7 @@ public class UDFHour extends UDF {
 
   /**
    * Get the hour from a date string.
-   * 
+   *
    * @param dateString
    *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -80,4 +81,14 @@ public class UDFHour extends UDF {
     }
   }
 
+  public IntWritable evaluate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+
+    calendar.setTime(t.getTimestamp());
+    result.set(calendar.get(Calendar.HOUR));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -52,7 +53,7 @@ public class UDFMinute extends UDF {
 
   /**
    * Get the minute from a date string.
-   * 
+   *
    * @param dateString
    *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -80,4 +81,14 @@ public class UDFMinute extends UDF {
     }
   }
 
+  public IntWritable evaluate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+
+    calendar.setTime(t.getTimestamp());
+    result.set(calendar.get(Calendar.MINUTE));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -47,7 +48,7 @@ public class UDFMonth extends UDF {
 
   /**
    * Get the month from a date string.
-   * 
+   *
    * @param dateString
    *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -68,4 +69,14 @@ public class UDFMonth extends UDF {
     }
   }
 
+  public IntWritable evaluate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+
+    calendar.setTime(t.getTimestamp());
+    result.set(1 + calendar.get(Calendar.MONTH));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -53,7 +54,7 @@ public class UDFSecond extends UDF {
 
   /**
    * Get the minute from a date string.
-   * 
+   *
    * @param dateString
    *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -81,4 +82,14 @@ public class UDFSecond extends UDF {
     }
   }
 
+  public IntWritable evaluate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+
+    calendar.setTime(t.getTimestamp());
+    result.set(calendar.get(Calendar.SECOND));
+    return result;
+  }
+
 }

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -22,6 +22,7 @@ import org.apache.hadoop.hive.ql.exec.UD
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.FloatWritable;
 import org.apache.hadoop.io.IntWritable;
@@ -41,7 +42,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert a void to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The value of a void type
    * @return BooleanWritable
@@ -52,7 +53,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert from a byte to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The byte value to convert
    * @return BooleanWritable
@@ -68,7 +69,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert from a short to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The short value to convert
    * @return BooleanWritable
@@ -84,7 +85,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert from a integer to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The integer value to convert
    * @return BooleanWritable
@@ -100,7 +101,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert from a long to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The long value to convert
    * @return BooleanWritable
@@ -116,7 +117,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert from a float to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The float value to convert
    * @return BooleanWritable
@@ -132,7 +133,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert from a double to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The double value to convert
    * @return BooleanWritable
@@ -148,7 +149,7 @@ public class UDFToBoolean extends UDF {
 
   /**
    * Convert from a string to boolean. This is called for CAST(... AS BOOLEAN)
-   * 
+   *
    * @param i
    *          The string value to convert
    * @return BooleanWritable
@@ -162,4 +163,13 @@ public class UDFToBoolean extends UDF {
     }
   }
 
+  public BooleanWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      booleanWritable.set(i.getSeconds() != 0 || i.getNanos() != 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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -22,6 +22,7 @@ import org.apache.hadoop.hive.ql.exec.UD
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.hive.serde2.lazy.LazyByte;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.FloatWritable;
@@ -42,7 +43,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from void to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The void value to convert
    * @return Byte
@@ -53,7 +54,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from boolean to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The boolean value to convert
    * @return Byte
@@ -69,7 +70,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from short to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The short value to convert
    * @return Byte
@@ -85,7 +86,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from integer to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The integer value to convert
    * @return Byte
@@ -101,7 +102,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from long to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The long value to convert
    * @return Byte
@@ -117,7 +118,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from float to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The float value to convert
    * @return Byte
@@ -133,7 +134,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from double to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The double value to convert
    * @return Byte
@@ -149,7 +150,7 @@ public class UDFToByte extends UDF {
 
   /**
    * Convert from string to a byte. This is called for CAST(... AS TINYINT)
-   * 
+   *
    * @param i
    *          The string value to convert
    * @return Byte
@@ -171,4 +172,13 @@ public class UDFToByte extends UDF {
     }
   }
 
+  public ByteWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      byteWritable.set((byte)i.getSeconds());
+      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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -22,13 +22,13 @@ import org.apache.hadoop.hive.ql.exec.UD
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.FloatWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.NullWritable;
 import org.apache.hadoop.io.Text;
-
 /**
  * UDFToDouble.
  *
@@ -41,7 +41,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from void to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The void value to convert
    * @return DoubleWritable
@@ -52,7 +52,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from boolean to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The boolean value to convert
    * @return DoubleWritable
@@ -68,7 +68,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from boolean to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The byte value to convert
    * @return DoubleWritable
@@ -84,7 +84,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from short to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The short value to convert
    * @return DoubleWritable
@@ -100,7 +100,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from integer to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The integer value to convert
    * @return DoubleWritable
@@ -116,7 +116,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from long to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The long value to convert
    * @return DoubleWritable
@@ -132,7 +132,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from float to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The float value to convert
    * @return DoubleWritable
@@ -148,7 +148,7 @@ public class UDFToDouble extends UDF {
 
   /**
    * Convert from string to a double. This is called for CAST(... AS DOUBLE)
-   * 
+   *
    * @param i
    *          The string value to convert
    * @return DoubleWritable
@@ -168,4 +168,19 @@ public class UDFToDouble extends UDF {
     }
   }
 
+  public DoubleWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      try {
+        doubleWritable.set(i.getDouble());
+        return doubleWritable;
+      } catch (NumberFormatException e) {
+        // MySQL returns 0 if the string is not a well-formed numeric value.
+        // But we decided to return NULL instead, which is more conservative.
+        return null;
+      }
+    }
+  }
+
 }

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -22,6 +22,7 @@ import org.apache.hadoop.hive.ql.exec.UD
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.FloatWritable;
 import org.apache.hadoop.io.IntWritable;
@@ -41,7 +42,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from void to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The void value to convert
    * @return FloatWritable
@@ -52,7 +53,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from boolean to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The boolean value to convert
    * @return FloatWritable
@@ -68,7 +69,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from byte to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The byte value to convert
    * @return FloatWritable
@@ -84,7 +85,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from short to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The short value to convert
    * @return FloatWritable
@@ -100,7 +101,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from integer to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The integer value to convert
    * @return FloatWritable
@@ -116,7 +117,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from long to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The long value to convert
    * @return FloatWritable
@@ -132,7 +133,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from double to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The double value to convert
    * @return FloatWritable
@@ -148,7 +149,7 @@ public class UDFToFloat extends UDF {
 
   /**
    * Convert from string to a float. This is called for CAST(... AS FLOAT)
-   * 
+   *
    * @param i
    *          The string value to convert
    * @return FloatWritable
@@ -168,4 +169,19 @@ public class UDFToFloat extends UDF {
     }
   }
 
+  public FloatWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      try {
+        floatWritable.set((float) i.getDouble());
+        return floatWritable;
+      } catch (NumberFormatException e) {
+        // MySQL returns 0 if the string is not a well-formed numeric value.
+        // But we decided to return NULL instead, which is more conservative.
+        return null;
+      }
+    }
+  }
+
 }

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -22,6 +22,7 @@ import org.apache.hadoop.hive.ql.exec.UD
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.hive.serde2.lazy.LazyInteger;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.FloatWritable;
@@ -42,7 +43,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from void to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The void value to convert
    * @return Integer
@@ -53,7 +54,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from boolean to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The boolean value to convert
    * @return IntWritable
@@ -69,7 +70,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from byte to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The byte value to convert
    * @return IntWritable
@@ -85,7 +86,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from short to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The short value to convert
    * @return IntWritable
@@ -101,7 +102,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from long to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The long value to convert
    * @return IntWritable
@@ -117,7 +118,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from float to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The float value to convert
    * @return IntWritable
@@ -133,7 +134,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from double to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The double value to convert
    * @return IntWritable
@@ -149,7 +150,7 @@ public class UDFToInteger extends UDF {
 
   /**
    * Convert from string to an integer. This is called for CAST(... AS INT)
-   * 
+   *
    * @param i
    *          The string value to convert
    * @return IntWritable
@@ -171,4 +172,20 @@ public class UDFToInteger extends UDF {
     }
   }
 
+  /**
+   * Convert from Timestamp to an integer. This is called for CAST(... AS INT)
+   *
+   * @param i
+   *          The Timestamp value to convert
+   * @return IntWritable
+   */
+  public IntWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      intWritable.set(i.getSeconds());
+      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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -22,6 +22,7 @@ import org.apache.hadoop.hive.ql.exec.UD
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.hive.serde2.lazy.LazyLong;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.FloatWritable;
@@ -42,7 +43,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from void to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The void value to convert
    * @return LongWritable
@@ -53,7 +54,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from boolean to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The boolean value to convert
    * @return LongWritable
@@ -69,7 +70,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from byte to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The byte value to convert
    * @return LongWritable
@@ -85,7 +86,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from short to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The short value to convert
    * @return LongWritable
@@ -101,7 +102,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from integer to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The integer value to convert
    * @return LongWritable
@@ -117,7 +118,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from long to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The long value to convert
    * @return LongWritable
@@ -128,7 +129,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from float to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The float value to convert
    * @return LongWritable
@@ -144,7 +145,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from double to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The double value to convert
    * @return LongWritable
@@ -160,7 +161,7 @@ public class UDFToLong extends UDF {
 
   /**
    * Convert from string to a long. This is called for CAST(... AS BIGINT)
-   * 
+   *
    * @param i
    *          The string value to convert
    * @return LongWritable
@@ -182,4 +183,13 @@ public class UDFToLong extends UDF {
     }
   }
 
+  public LongWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      longWritable.set(i.getSeconds());
+      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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -22,6 +22,7 @@ import org.apache.hadoop.hive.ql.exec.UD
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.hive.serde2.lazy.LazyShort;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.FloatWritable;
@@ -42,7 +43,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from void to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The void value to convert
    * @return ShortWritable
@@ -53,7 +54,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from boolean to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The boolean value to convert
    * @return ShortWritable
@@ -69,7 +70,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from byte to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The byte value to convert
    * @return ShortWritable
@@ -85,7 +86,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from integer to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The integer value to convert
    * @return ShortWritable
@@ -101,7 +102,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from long to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The long value to convert
    * @return ShortWritable
@@ -117,7 +118,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from float to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The float value to convert
    * @return ShortWritable
@@ -133,7 +134,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from double to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The double value to convert
    * @return ShortWritable
@@ -149,7 +150,7 @@ public class UDFToShort extends UDF {
 
   /**
    * Convert from string to a short. This is called for CAST(... AS SMALLINT)
-   * 
+   *
    * @param i
    *          The string value to convert
    * @return ShortWritable
@@ -170,4 +171,14 @@ public class UDFToShort extends UDF {
       }
     }
   }
+
+  public ShortWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      shortWritable.set((short) i.getSeconds());
+      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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -23,6 +23,7 @@ import org.apache.hadoop.hive.serde2.Byt
 import org.apache.hadoop.hive.serde2.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.hive.serde2.lazy.LazyInteger;
 import org.apache.hadoop.hive.serde2.lazy.LazyLong;
 import org.apache.hadoop.io.BooleanWritable;
@@ -122,4 +123,21 @@ public class UDFToString extends UDF {
     }
   }
 
+  public Text evaluate(Text i) {
+      if (i == null) {
+          return null;
+      }
+      i.set(i.toString());
+      return i;
+  }
+
+  public Text evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      t.set(i.toString());
+      return t;
+    }
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFUnixTimeStamp.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFUnixTimeStamp.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFUnixTimeStamp.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFUnixTimeStamp.java Fri Aug 12 19:21:36 2011
@@ -24,6 +24,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 
@@ -48,7 +49,7 @@ public class UDFUnixTimeStamp extends UD
 
   /**
    * Return current UnixTime.
-   * 
+   *
    * @return long Number of seconds from 1970-01-01 00:00:00
    */
   public LongWritable evaluate() {
@@ -59,7 +60,7 @@ public class UDFUnixTimeStamp extends UD
 
   /**
    * Convert time string to UnixTime.
-   * 
+   *
    * @param dateText
    *          Time string in format yyyy-MM-dd HH:mm:ss
    * @return long Number of seconds from 1970-01-01 00:00:00
@@ -82,7 +83,7 @@ public class UDFUnixTimeStamp extends UD
 
   /**
    * Convert time string to UnixTime with user defined pattern.
-   * 
+   *
    * @param dateText
    *          Time string in format patternstring
    * @param patternText
@@ -104,4 +105,13 @@ public class UDFUnixTimeStamp extends UD
 
     return evaluate(dateText);
   }
+
+  public LongWritable evaluate(TimestampWritable i) {
+    if (i == null) {
+      return null;
+    } else {
+      result.set(i.getSeconds());
+      return result;
+    }
+  }
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFWeekOfYear.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFWeekOfYear.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFWeekOfYear.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFWeekOfYear.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -32,9 +33,9 @@ import org.apache.hadoop.io.Text;
  * UDFWeekOfYear.
  *
  */
-@Description(name = "yearweek", 
+@Description(name = "yearweek",
     value = "_FUNC_(date) - Returns the week of the year of the given date. A week "
-    + "is considered to start on a Monday and week 1 is the first week with >3 days.", 
+    + "is considered to start on a Monday and week 1 is the first week with >3 days.",
     extended = "Examples:\n"
     + "  > SELECT _FUNC_('2008-02-20') FROM src LIMIT 1;\n"
     + "  8\n"
@@ -52,7 +53,7 @@ public class UDFWeekOfYear extends UDF {
 
   /**
    * Get the week of the year from a date string.
-   * 
+   *
    * @param dateString
    *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -73,4 +74,14 @@ public class UDFWeekOfYear extends UDF {
     }
   }
 
+  public IntWritable evaluate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+
+    calendar.setTime(t.getTimestamp());
+    result.set(calendar.get(Calendar.WEEK_OF_YEAR));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java Fri Aug 12 19:21:36 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 
@@ -32,8 +33,8 @@ import org.apache.hadoop.io.Text;
  * UDFYear.
  *
  */
-@Description(name = "year", 
-    value = "_FUNC_(date) - Returns the year of date", 
+@Description(name = "year",
+    value = "_FUNC_(date) - Returns the year of date",
     extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or "
     + "'yyyy-MM-dd'.\n"
     + "Example:\n "
@@ -49,7 +50,7 @@ public class UDFYear extends UDF {
 
   /**
    * Get the year from a date string.
-   * 
+   *
    * @param dateString
    *          the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
    *          "yyyy-MM-dd".
@@ -72,4 +73,14 @@ public class UDFYear extends UDF {
     }
   }
 
+  public IntWritable evaluate(TimestampWritable t) {
+    if (t == null) {
+      return null;
+    }
+
+    calendar.setTime(t.getTimestamp());
+    result.set(calendar.get(Calendar.YEAR));
+    return result;
+  }
+
 }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFAverage.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFAverage.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFAverage.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFAverage.java Fri Aug 12 19:21:36 2011
@@ -70,6 +70,7 @@ public class GenericUDAFAverage extends 
     case FLOAT:
     case DOUBLE:
     case STRING:
+    case TIMESTAMP:
       return new GenericUDAFAverageEvaluator();
     case BOOLEAN:
     default:

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFContextNGrams.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFContextNGrams.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFContextNGrams.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFContextNGrams.java Fri Aug 12 19:21:36 2011
@@ -132,6 +132,7 @@ public class GenericUDAFContextNGrams im
     case SHORT:
     case INT:
     case LONG:
+    case TIMESTAMP:
       break;
 
     default:
@@ -151,6 +152,7 @@ public class GenericUDAFContextNGrams im
       case SHORT:
       case INT:
       case LONG:
+      case TIMESTAMP:
         break;
 
       default:

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -101,6 +101,7 @@ public class GenericUDAFCorrelation exte
     case LONG:
     case FLOAT:
     case DOUBLE:
+    case TIMESTAMP:
       switch (((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()) {
       case BYTE:
       case SHORT:
@@ -108,6 +109,7 @@ public class GenericUDAFCorrelation exte
       case LONG:
       case FLOAT:
       case DOUBLE:
+      case TIMESTAMP:
         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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -92,6 +92,7 @@ public class GenericUDAFCovariance exten
     case LONG:
     case FLOAT:
     case DOUBLE:
+    case TIMESTAMP:
       switch (((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()) {
       case BYTE:
       case SHORT:
@@ -99,6 +100,7 @@ public class GenericUDAFCovariance exten
       case LONG:
       case FLOAT:
       case DOUBLE:
+      case TIMESTAMP:
         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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -66,6 +66,7 @@ public class GenericUDAFCovarianceSample
     case LONG:
     case FLOAT:
     case DOUBLE:
+    case TIMESTAMP:
       switch (((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()) {
       case BYTE:
       case SHORT:
@@ -73,6 +74,7 @@ public class GenericUDAFCovarianceSample
       case LONG:
       case FLOAT:
       case DOUBLE:
+      case TIMESTAMP:
         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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -86,6 +86,7 @@ public class GenericUDAFHistogramNumeric
     case LONG:
     case FLOAT:
     case DOUBLE:
+    case TIMESTAMP:
       break;
     case STRING:
     case BOOLEAN:

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -91,6 +91,7 @@ public class GenericUDAFPercentileApprox
     case LONG:
     case FLOAT:
     case DOUBLE:
+    case TIMESTAMP:
       break;
     default:
       throw new UDFArgumentTypeException(0,
@@ -155,6 +156,7 @@ public class GenericUDAFPercentileApprox
       case SHORT:
       case INT:
       case LONG:
+      case TIMESTAMP:
         break;
       default:
         throw new UDFArgumentTypeException(2, "Only an integer argument is accepted as "

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -55,6 +55,7 @@ public class GenericUDAFStd extends Gene
     case FLOAT:
     case DOUBLE:
     case STRING:
+    case TIMESTAMP:
       return new GenericUDAFStdEvaluator();
     case BOOLEAN:
     default:

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -54,6 +54,7 @@ public class GenericUDAFStdSample extend
     case FLOAT:
     case DOUBLE:
     case STRING:
+    case TIMESTAMP:
       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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -60,6 +60,7 @@ public class GenericUDAFSum extends Abst
     case SHORT:
     case INT:
     case LONG:
+    case TIMESTAMP:
       return new GenericUDAFSumLong();
     case FLOAT:
     case DOUBLE:

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -71,6 +71,7 @@ public class GenericUDAFVariance extends
     case FLOAT:
     case DOUBLE:
     case STRING:
+    case TIMESTAMP:
       return new GenericUDAFVarianceEvaluator();
     case BOOLEAN:
     default:

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=1157222&r1=1157221&r2=1157222&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 Fri Aug 12 19:21:36 2011
@@ -55,6 +55,7 @@ public class GenericUDAFVarianceSample e
     case FLOAT:
     case DOUBLE:
     case STRING:
+    case TIMESTAMP:
       return new GenericUDAFVarianceSampleEvaluator();
     case BOOLEAN:
     default:

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFnGrams.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFnGrams.java?rev=1157222&r1=1157221&r2=1157222&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFnGrams.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFnGrams.java Fri Aug 12 19:21:36 2011
@@ -113,6 +113,7 @@ public class GenericUDAFnGrams implement
     case SHORT:
     case INT:
     case LONG:
+    case TIMESTAMP:
       break;
 
     default:
@@ -130,6 +131,7 @@ public class GenericUDAFnGrams implement
     case SHORT:
     case INT:
     case LONG:
+    case TIMESTAMP:
       break;
 
     default:
@@ -148,6 +150,7 @@ public class GenericUDAFnGrams implement
       case SHORT:
       case INT:
       case LONG:
+      case TIMESTAMP:
         break;
 
       default:

Added: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java?rev=1157222&view=auto
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java (added)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java Fri Aug 12 19:21:36 2011
@@ -0,0 +1,125 @@
+/**
+ * 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 java.sql.Timestamp;
+import java.util.TimeZone;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.io.TimestampWritable;
+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.TextConverter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.TimestampConverter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.Text;
+
+
+public class GenericUDFFromUtcTimestamp extends GenericUDF {
+
+  static final Log LOG = LogFactory.getLog(GenericUDFFromUtcTimestamp.class);
+
+  private PrimitiveObjectInspector[] argumentOIs;
+  private TimestampConverter timestampConverter;
+  private TextConverter textConverter;
+
+  @Override
+  public ObjectInspector initialize(ObjectInspector[] arguments)
+      throws UDFArgumentException {
+    if (arguments.length < 2) {
+      throw new UDFArgumentLengthException(
+          "The function " + getName() + " requires at least two "
+          + "argument, got " + arguments.length);
+    }
+    try {
+      argumentOIs = new PrimitiveObjectInspector[2];
+      argumentOIs[0] = (PrimitiveObjectInspector) arguments[0];
+      if (arguments.length > 1) {
+        argumentOIs[1] = (PrimitiveObjectInspector) arguments[1];
+      }
+    } catch (ClassCastException e) {
+      throw new UDFArgumentException(
+          "The function " + getName() + " takes only primitive types");
+    }
+
+    timestampConverter = new TimestampConverter(argumentOIs[0],
+        PrimitiveObjectInspectorFactory.writableTimestampObjectInspector);
+    textConverter = new TextConverter(argumentOIs[1]);
+    return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
+  }
+
+  @Override
+  public Object evaluate(DeferredObject[] arguments) throws HiveException {
+    Object o0 = arguments[0].get();
+    TimeZone timezone = null;
+    if (o0 == null) {
+      return null;
+    }
+
+    if (arguments.length > 1 && arguments[1] != null) {
+      Text text = textConverter.convert(arguments[1].get());
+      if (text != null) {
+        timezone = TimeZone.getTimeZone(text.toString());
+      }
+    } else {
+      return null;
+    }
+
+    Timestamp timestamp = ((TimestampWritable) timestampConverter.convert(o0))
+        .getTimestamp();
+
+    int offset = timezone.getOffset(timestamp.getTime());
+    if (invert()) {
+      offset = -offset;
+    }
+    return applyOffset(offset, timestamp);
+  }
+
+  protected Timestamp applyOffset(long offset, Timestamp t) {
+    long newTime = t.getTime() + offset;
+    int nanos = (int) (t.getNanos() + (newTime % 1000) * 1000000);
+    t.setTime(newTime);
+    t.setNanos(nanos);
+
+    return t;
+  }
+
+  @Override
+  public String getDisplayString(String[] children) {
+    StringBuilder sb = new StringBuilder();
+    sb.append("Converting field ");
+    sb.append(children[0]);
+    sb.append(" from UTC to timezone: ");
+    if (children.length > 1) {
+      sb.append(children[1]);
+    }
+    return sb.toString();
+  }
+
+  public String getName() {
+    return "from_utc_timestamp";
+  }
+
+  protected boolean invert() {
+    return false;
+  }
+}

Added: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTimestamp.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTimestamp.java?rev=1157222&view=auto
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTimestamp.java (added)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTimestamp.java Fri Aug 12 19:21:36 2011
@@ -0,0 +1,82 @@
+/**
+ * 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.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.TimestampConverter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+
+/**
+ *
+ * GenericUDFTimestamp
+ *
+ * Example usage:
+ * ... CAST(<Timestamp string> as TIMESTAMP) ...
+ *
+ * Creates a TimestampWritable object using PrimitiveObjectInspectorConverter
+ *
+ */
+public class GenericUDFTimestamp extends GenericUDF {
+
+  private PrimitiveObjectInspector argumentOI;
+  private TimestampConverter tc;
+
+  @Override
+  public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+    if (arguments.length < 1) {
+      throw new UDFArgumentLengthException(
+          "The function TIMESTAMP requires at least one argument, got "
+          + arguments.length);
+    }
+    try {
+      argumentOI = (PrimitiveObjectInspector) arguments[0];
+    } catch (ClassCastException e) {
+      throw new UDFArgumentException(
+          "The function TIMESTAMP takes only primitive types");
+    }
+
+    tc = new TimestampConverter(argumentOI,
+        PrimitiveObjectInspectorFactory.writableTimestampObjectInspector);
+    return PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
+  }
+
+  @Override
+  public Object evaluate(DeferredObject[] arguments) throws HiveException {
+    Object o0 = arguments[0].get();
+    if (o0 == null) {
+      return null;
+    }
+
+    return tc.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 TIMESTAMP");
+    return sb.toString();
+  }
+
+}

Added: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToUtcTimestamp.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToUtcTimestamp.java?rev=1157222&view=auto
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToUtcTimestamp.java (added)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToUtcTimestamp.java Fri Aug 12 19:21:36 2011
@@ -0,0 +1,46 @@
+/**
+ * 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;
+
+
+public class GenericUDFToUtcTimestamp extends
+    GenericUDFFromUtcTimestamp {
+
+  @Override
+  public String getDisplayString(String[] children) {
+    StringBuilder sb = new StringBuilder();
+    sb.append("Convert ");
+    sb.append(children[0]);
+    sb.append(" from timezone ");
+    if (children.length > 1) {
+      sb.append(children[1]);
+    }
+    sb.append(" to UTC");
+    return sb.toString();
+  }
+
+  @Override
+  public String getName() {
+    return "to_utc_timestamp";
+  }
+
+  @Override
+  protected boolean invert() {
+    return true;
+  }
+}

Added: hive/trunk/ql/src/test/queries/clientpositive/timestamp_1.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/timestamp_1.q?rev=1157222&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/timestamp_1.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/timestamp_1.q Fri Aug 12 19:21:36 2011
@@ -0,0 +1,72 @@
+drop table timestamp_1;
+
+create table timestamp_1 (t timestamp);
+alter table timestamp_1 set serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe';
+
+insert overwrite table timestamp_1 
+  select cast('2011-01-01 01:01:01' as timestamp) from src limit 1;
+select cast(t as boolean) from timestamp_1 limit 1;
+select cast(t as tinyint) from timestamp_1 limit 1;
+select cast(t as smallint) from timestamp_1 limit 1;
+select cast(t as int) from timestamp_1 limit 1;
+select cast(t as bigint) from timestamp_1 limit 1;
+select cast(t as float) from timestamp_1 limit 1;
+select cast(t as double) from timestamp_1 limit 1;
+select cast(t as string) from timestamp_1 limit 1;
+
+insert overwrite table timestamp_1
+  select '2011-01-01 01:01:01' from src limit 1;
+select cast(t as boolean) from timestamp_1 limit 1;
+select cast(t as tinyint) from timestamp_1 limit 1;
+select cast(t as smallint) from timestamp_1 limit 1;
+select cast(t as int) from timestamp_1 limit 1;
+select cast(t as bigint) from timestamp_1 limit 1;
+select cast(t as float) from timestamp_1 limit 1;
+select cast(t as double) from timestamp_1 limit 1;
+select cast(t as string) from timestamp_1 limit 1;
+
+insert overwrite table timestamp_1
+  select '2011-01-01 01:01:01.1' from src limit 1;
+select cast(t as boolean) from timestamp_1 limit 1;
+select cast(t as tinyint) from timestamp_1 limit 1;
+select cast(t as smallint) from timestamp_1 limit 1;
+select cast(t as int) from timestamp_1 limit 1;
+select cast(t as bigint) from timestamp_1 limit 1;
+select cast(t as float) from timestamp_1 limit 1;
+select cast(t as double) from timestamp_1 limit 1;
+select cast(t as string) from timestamp_1 limit 1;
+
+insert overwrite table timestamp_1
+  select '2011-01-01 01:01:01.0001' from src limit 1;
+select cast(t as boolean) from timestamp_1 limit 1;
+select cast(t as tinyint) from timestamp_1 limit 1;
+select cast(t as smallint) from timestamp_1 limit 1;
+select cast(t as int) from timestamp_1 limit 1;
+select cast(t as bigint) from timestamp_1 limit 1;
+select cast(t as float) from timestamp_1 limit 1;
+select cast(t as double) from timestamp_1 limit 1;
+select cast(t as string) from timestamp_1 limit 1;
+
+insert overwrite table timestamp_1
+  select '2011-01-01 01:01:01.000100000' from src limit 1;
+select cast(t as boolean) from timestamp_1 limit 1;
+select cast(t as tinyint) from timestamp_1 limit 1;
+select cast(t as smallint) from timestamp_1 limit 1;
+select cast(t as int) from timestamp_1 limit 1;
+select cast(t as bigint) from timestamp_1 limit 1;
+select cast(t as float) from timestamp_1 limit 1;
+select cast(t as double) from timestamp_1 limit 1;
+select cast(t as string) from timestamp_1 limit 1;
+
+insert overwrite table timestamp_1
+  select '2011-01-01 01:01:01.001000011' from src limit 1;
+select cast(t as boolean) from timestamp_1 limit 1;
+select cast(t as tinyint) from timestamp_1 limit 1;
+select cast(t as smallint) from timestamp_1 limit 1;
+select cast(t as int) from timestamp_1 limit 1;
+select cast(t as bigint) from timestamp_1 limit 1;
+select cast(t as float) from timestamp_1 limit 1;
+select cast(t as double) from timestamp_1 limit 1;
+select cast(t as string) from timestamp_1 limit 1;
+
+drop table timestamp_1;

Added: hive/trunk/ql/src/test/queries/clientpositive/timestamp_2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/timestamp_2.q?rev=1157222&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/timestamp_2.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/timestamp_2.q Fri Aug 12 19:21:36 2011
@@ -0,0 +1,72 @@
+drop table timestamp_2;
+
+create table timestamp_2 (t timestamp);
+alter table timestamp_2 set serde 'org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe';
+
+insert overwrite table timestamp_2 
+  select cast('2011-01-01 01:01:01' as timestamp) from src limit 1;
+select cast(t as boolean) from timestamp_2 limit 1;
+select cast(t as tinyint) from timestamp_2 limit 1;
+select cast(t as smallint) from timestamp_2 limit 1;
+select cast(t as int) from timestamp_2 limit 1;
+select cast(t as bigint) from timestamp_2 limit 1;
+select cast(t as float) from timestamp_2 limit 1;
+select cast(t as double) from timestamp_2 limit 1;
+select cast(t as string) from timestamp_2 limit 1;
+
+insert overwrite table timestamp_2
+  select '2011-01-01 01:01:01' from src limit 1;
+select cast(t as boolean) from timestamp_2 limit 1;
+select cast(t as tinyint) from timestamp_2 limit 1;
+select cast(t as smallint) from timestamp_2 limit 1;
+select cast(t as int) from timestamp_2 limit 1;
+select cast(t as bigint) from timestamp_2 limit 1;
+select cast(t as float) from timestamp_2 limit 1;
+select cast(t as double) from timestamp_2 limit 1;
+select cast(t as string) from timestamp_2 limit 1;
+
+insert overwrite table timestamp_2
+  select '2011-01-01 01:01:01.1' from src limit 1;
+select cast(t as boolean) from timestamp_2 limit 1;
+select cast(t as tinyint) from timestamp_2 limit 1;
+select cast(t as smallint) from timestamp_2 limit 1;
+select cast(t as int) from timestamp_2 limit 1;
+select cast(t as bigint) from timestamp_2 limit 1;
+select cast(t as float) from timestamp_2 limit 1;
+select cast(t as double) from timestamp_2 limit 1;
+select cast(t as string) from timestamp_2 limit 1;
+
+insert overwrite table timestamp_2
+  select '2011-01-01 01:01:01.0001' from src limit 1;
+select cast(t as boolean) from timestamp_2 limit 1;
+select cast(t as tinyint) from timestamp_2 limit 1;
+select cast(t as smallint) from timestamp_2 limit 1;
+select cast(t as int) from timestamp_2 limit 1;
+select cast(t as bigint) from timestamp_2 limit 1;
+select cast(t as float) from timestamp_2 limit 1;
+select cast(t as double) from timestamp_2 limit 1;
+select cast(t as string) from timestamp_2 limit 1;
+
+insert overwrite table timestamp_2
+  select '2011-01-01 01:01:01.000100000' from src limit 1;
+select cast(t as boolean) from timestamp_2 limit 1;
+select cast(t as tinyint) from timestamp_2 limit 1;
+select cast(t as smallint) from timestamp_2 limit 1;
+select cast(t as int) from timestamp_2 limit 1;
+select cast(t as bigint) from timestamp_2 limit 1;
+select cast(t as float) from timestamp_2 limit 1;
+select cast(t as double) from timestamp_2 limit 1;
+select cast(t as string) from timestamp_2 limit 1;
+
+insert overwrite table timestamp_2
+  select '2011-01-01 01:01:01.001000011' from src limit 1;
+select cast(t as boolean) from timestamp_2 limit 1;
+select cast(t as tinyint) from timestamp_2 limit 1;
+select cast(t as smallint) from timestamp_2 limit 1;
+select cast(t as int) from timestamp_2 limit 1;
+select cast(t as bigint) from timestamp_2 limit 1;
+select cast(t as float) from timestamp_2 limit 1;
+select cast(t as double) from timestamp_2 limit 1;
+select cast(t as string) from timestamp_2 limit 1;
+
+drop table timestamp_2;



Mime
View raw message