hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zs...@apache.org
Subject svn commit: r899036 - in /hadoop/hive/trunk: CHANGES.txt ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFromUnixTime.java ql/src/test/queries/clientpositive/udf5.q ql/src/test/results/clientpositive/udf5.q.out
Date Thu, 14 Jan 2010 02:56:48 GMT
Author: zshao
Date: Thu Jan 14 02:56:47 2010
New Revision: 899036

URL: http://svn.apache.org/viewvc?rev=899036&view=rev
Log:
HIVE-983. Function from_unixtime should take bigint.

Modified:
    hadoop/hive/trunk/CHANGES.txt
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFromUnixTime.java
    hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf5.q
    hadoop/hive/trunk/ql/src/test/results/clientpositive/udf5.q.out

Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=899036&r1=899035&r2=899036&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Thu Jan 14 02:56:47 2010
@@ -8,6 +8,9 @@
 
   IMPROVEMENTS
 
+    HIVE-983. Function from_unixtime takes long.
+    (Ning Zhang via zshao)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFromUnixTime.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFromUnixTime.java?rev=899036&r1=899035&r2=899036&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFromUnixTime.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFFromUnixTime.java Thu Jan
14 02:56:47 2010
@@ -26,6 +26,7 @@
 import org.apache.hadoop.hive.ql.exec.UDF;
 import org.apache.hadoop.hive.ql.exec.description;
 import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 
 @description(
@@ -59,20 +60,44 @@
    * @param format See http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    * @return a String in the format specified.
    */
+  public Text evaluate(LongWritable unixtime, Text format)  {
+    if (unixtime == null || format == null) {
+      return null;
+    }
+    
+    return eval(unixtime.get(), format);
+  }
+
+  /**
+   * Convert UnixTime to a string format.
+   * @param unixtime  The number of seconds from 1970-01-01 00:00:00
+   * @param format See http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
+   * @return a String in the format specified.
+   */
   public Text evaluate(IntWritable unixtime, Text format)  {
     if (unixtime == null || format == null) {
       return null;
     }
     
+    return eval((long)unixtime.get(), format);
+  }
+
+  /**
+   * Internal evaluation function given the seconds from 1970-01-01 00:00:00
+   * and the output text format.
+   * @param unixtime seconds of type long from 1970-01-01 00:00:00
+   * @param format display format. See http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
+   * @return elapsed time in the given format.
+   */
+  private Text eval(long unixtime, Text format) {
     if (!format.equals(lastFormat)) {
       formatter = new SimpleDateFormat(format.toString());
       lastFormat.set(format);
     }
     
     // convert seconds to milliseconds
-    Date date = new Date(unixtime.get() * 1000L);
+    Date date = new Date(unixtime * 1000L);
     result.set(formatter.format(date));
     return result;
   }
-
 }

Modified: hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf5.q
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf5.q?rev=899036&r1=899035&r2=899036&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf5.q (original)
+++ hadoop/hive/trunk/ql/src/test/queries/clientpositive/udf5.q Thu Jan 14 02:56:47 2010
@@ -6,3 +6,8 @@
 SELECT from_unixtime(1226446340), to_date(from_unixtime(1226446340)), day('2008-11-01'),
month('2008-11-01'), year('2008-11-01'), day('2008-11-01 15:32:20'), month('2008-11-01 15:32:20'),
year('2008-11-01 15:32:20') FROM dest1;
 
 SELECT from_unixtime(1226446340), to_date(from_unixtime(1226446340)), day('2008-11-01'),
month('2008-11-01'), year('2008-11-01'), day('2008-11-01 15:32:20'), month('2008-11-01 15:32:20'),
year('2008-11-01 15:32:20') FROM dest1;
+
+EXPLAIN
+SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd HH:mm:ss'), 'MM/dd/yy
HH:mm:ss') from dest1;
+
+SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd HH:mm:ss'), 'MM/dd/yy
HH:mm:ss') from dest1;

Modified: hadoop/hive/trunk/ql/src/test/results/clientpositive/udf5.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/results/clientpositive/udf5.q.out?rev=899036&r1=899035&r2=899036&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/results/clientpositive/udf5.q.out (original)
+++ hadoop/hive/trunk/ql/src/test/results/clientpositive/udf5.q.out Thu Jan 14 02:56:47 2010
@@ -65,9 +65,55 @@
 PREHOOK: query: SELECT from_unixtime(1226446340), to_date(from_unixtime(1226446340)), day('2008-11-01'),
month('2008-11-01'), year('2008-11-01'), day('2008-11-01 15:32:20'), month('2008-11-01 15:32:20'),
year('2008-11-01 15:32:20') FROM dest1
 PREHOOK: type: QUERY
 PREHOOK: Input: default@dest1
-PREHOOK: Output: file:/data/users/njain/hive5/hive5/build/ql/tmp/478157482/10000
+PREHOOK: Output: file:/data/users/nzhang/work/876/apache-hive/build/ql/tmp/1960950507/10000
 POSTHOOK: query: SELECT from_unixtime(1226446340), to_date(from_unixtime(1226446340)), day('2008-11-01'),
month('2008-11-01'), year('2008-11-01'), day('2008-11-01 15:32:20'), month('2008-11-01 15:32:20'),
year('2008-11-01 15:32:20') FROM dest1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@dest1
-POSTHOOK: Output: file:/data/users/njain/hive5/hive5/build/ql/tmp/478157482/10000
+POSTHOOK: Output: file:/data/users/nzhang/work/876/apache-hive/build/ql/tmp/1960950507/10000
 2008-11-11 15:32:20	2008-11-11	1	11	2008	1	11	2008
+PREHOOK: query: EXPLAIN
+SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd HH:mm:ss'), 'MM/dd/yy
HH:mm:ss') from dest1
+PREHOOK: type: QUERY
+POSTHOOK: query: EXPLAIN
+SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd HH:mm:ss'), 'MM/dd/yy
HH:mm:ss') from dest1
+POSTHOOK: type: QUERY
+ABSTRACT SYNTAX TREE:
+  (TOK_QUERY (TOK_FROM (TOK_TABREF dest1)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE))
(TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION from_unixtime (TOK_FUNCTION unix_timestamp '2010-01-13
11:57:40' 'yyyy-MM-dd HH:mm:ss') 'MM/dd/yy HH:mm:ss')))))
+
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-1
+    Map Reduce
+      Alias -> Map Operator Tree:
+        dest1 
+          TableScan
+            alias: dest1
+            Select Operator
+              expressions:
+                    expr: from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd
HH:mm:ss'), 'MM/dd/yy HH:mm:ss')
+                    type: string
+              outputColumnNames: _col0
+              File Output Operator
+                compressed: false
+                GlobalTableId: 0
+                table:
+                    input format: org.apache.hadoop.mapred.TextInputFormat
+                    output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+
+
+PREHOOK: query: SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd HH:mm:ss'),
'MM/dd/yy HH:mm:ss') from dest1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@dest1
+PREHOOK: Output: file:/data/users/nzhang/work/876/apache-hive/build/ql/tmp/1373998585/10000
+POSTHOOK: query: SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd HH:mm:ss'),
'MM/dd/yy HH:mm:ss') from dest1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@dest1
+POSTHOOK: Output: file:/data/users/nzhang/work/876/apache-hive/build/ql/tmp/1373998585/10000
+01/13/10 11:57:40



Mime
View raw message