hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject [38/50] [abbrv] hive git commit: revert HIVE-12531 : Implement fast-path for Year/Month UDFs for dates between 1999 and 2038 (Jason Dere via Sergey Shelukhin)
Date Mon, 04 Apr 2016 20:37:13 GMT
revert HIVE-12531 : Implement fast-path for Year/Month UDFs for dates between 1999 and 2038
(Jason Dere via Sergey Shelukhin)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/09b00fc8
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/09b00fc8
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/09b00fc8

Branch: refs/heads/llap
Commit: 09b00fc863d19cf513fe1d188bb671f370f64c2d
Parents: ff10f03
Author: Jason Dere <jdere@hortonworks.com>
Authored: Tue Mar 29 11:16:32 2016 -0700
Committer: Jason Dere <jdere@hortonworks.com>
Committed: Tue Mar 29 11:16:32 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hive/ql/udf/UDFMonth.java     | 16 ++++++++--------
 .../java/org/apache/hadoop/hive/ql/udf/UDFYear.java | 16 ++++++++--------
 .../expressions/TestVectorDateExpressions.java      | 13 +++----------
 3 files changed, 19 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/09b00fc8/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java
index 05afb8e..8c2b0e4 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java
@@ -20,8 +20,8 @@ package org.apache.hadoop.hive.ql.udf;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
-import org.joda.time.MutableDateTime;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
@@ -53,7 +53,7 @@ import org.apache.hadoop.io.Text;
 @NDV(maxNdv = 31)
 public class UDFMonth extends UDF {
   private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
-  private transient final MutableDateTime mdt = new MutableDateTime();
+  private final Calendar calendar = Calendar.getInstance();
 
   private final IntWritable result = new IntWritable();
 
@@ -75,8 +75,8 @@ public class UDFMonth extends UDF {
     }
     try {
       Date date = formatter.parse(dateString.toString());
-      mdt.setMillis(date.getTime());
-      result.set(mdt.getMonthOfYear());
+      calendar.setTime(date);
+      result.set(1 + calendar.get(Calendar.MONTH));
       return result;
     } catch (ParseException e) {
       return null;
@@ -88,8 +88,8 @@ public class UDFMonth extends UDF {
       return null;
     }
 
-    mdt.setMillis(d.get().getTime());
-    result.set(mdt.getMonthOfYear());
+    calendar.setTime(d.get());
+    result.set(1 + calendar.get(Calendar.MONTH));
     return result;
   }
 
@@ -98,8 +98,8 @@ public class UDFMonth extends UDF {
       return null;
     }
 
-    mdt.setMillis(t.getTimestamp().getTime());
-    result.set(mdt.getMonthOfYear());
+    calendar.setTime(t.getTimestamp());
+    result.set(1 + calendar.get(Calendar.MONTH));
     return result;
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/09b00fc8/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java
index fb3a655..d7ecd8c 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java
@@ -20,8 +20,8 @@ package org.apache.hadoop.hive.ql.udf;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
-import org.joda.time.MutableDateTime;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDF;
@@ -53,7 +53,7 @@ import org.apache.hadoop.io.Text;
 @NDV(maxNdv = 20) // although technically its unbounded, its unlikely we will ever see ndv
> 20
 public class UDFYear extends UDF {
   private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
-  private transient final MutableDateTime mdt = new MutableDateTime();
+  private final Calendar calendar = Calendar.getInstance();
 
   private final IntWritable result = new IntWritable();
 
@@ -77,8 +77,8 @@ public class UDFYear extends UDF {
 
     try {
       Date date = formatter.parse(dateString.toString());
-      mdt.setMillis(date.getTime());
-      result.set(mdt.getYear());
+      calendar.setTime(date);
+      result.set(calendar.get(Calendar.YEAR));
       return result;
     } catch (ParseException e) {
       return null;
@@ -90,8 +90,8 @@ public class UDFYear extends UDF {
       return null;
     }
 
-    mdt.setMillis(d.get().getTime());
-    result.set(mdt.getYear());
+    calendar.setTime(d.get());
+    result.set(calendar.get(Calendar.YEAR));
     return result;
   }
 
@@ -100,8 +100,8 @@ public class UDFYear extends UDF {
       return null;
     }
 
-    mdt.setMillis(t.getTimestamp().getTime());
-    result.set(mdt.getYear());
+    calendar.setTime(t.getTimestamp());
+    result.set(calendar.get(Calendar.YEAR));
     return result;
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/09b00fc8/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorDateExpressions.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorDateExpressions.java
b/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorDateExpressions.java
index 61c96e9..58cecc1 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorDateExpressions.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorDateExpressions.java
@@ -38,9 +38,7 @@ import org.junit.Test;
 import org.junit.internal.runners.statements.Fail;
 
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import com.sun.tools.javac.resources.javac;
 
-import java.sql.Date;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -55,7 +53,6 @@ import java.util.concurrent.ThreadFactory;
 public class TestVectorDateExpressions {
 
   private ExecutorService runner;
-  private static final int MAX_SANE_DATE_VALUE = new DateWritable(Date.valueOf("3000-01-01")).getDays();
 
   /* copied over from VectorUDFTimestampFieldLong */
   private TimestampWritable toTimestampWritable(long daysSinceEpoch) {
@@ -81,15 +78,11 @@ public class TestVectorDateExpressions {
   }
 
   private VectorizedRowBatch getVectorizedRandomRowBatch(int seed, int size) {
-    return getVectorizedRandomRowBatch(seed, size, Integer.MAX_VALUE);
-  }
-
-  private VectorizedRowBatch getVectorizedRandomRowBatch(int seed, int size, int maxValue)
{
     VectorizedRowBatch batch = new VectorizedRowBatch(2, size);
     LongColumnVector lcv = new LongColumnVector(size);
     Random rand = new Random(seed);
     for (int i = 0; i < size; i++) {
-      lcv.vector[i] = (rand.nextInt(maxValue));
+      lcv.vector[i] = (rand.nextInt());
     }
     batch.cols[0] = lcv;
     batch.cols[1] = new LongColumnVector(size);
@@ -166,7 +159,7 @@ public class TestVectorDateExpressions {
     batch.cols[0].isNull[0] = true;
     verifyUDFYear(batch);
 
-    batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE, MAX_SANE_DATE_VALUE);
+    batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE);
     verifyUDFYear(batch);
     TestVectorizedRowBatch.addRandomNulls(batch.cols[0]);
     verifyUDFYear(batch);
@@ -290,7 +283,7 @@ public class TestVectorDateExpressions {
     batch.cols[0].isNull[0] = true;
     verifyUDFMonth(batch);
 
-    batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE, MAX_SANE_DATE_VALUE);
+    batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE);
     verifyUDFMonth(batch);
     TestVectorizedRowBatch.addRandomNulls(batch.cols[0]);
     verifyUDFMonth(batch);


Mime
View raw message