FAQ
Author: hashutosh
Date: Fri Jun 14 21:57:58 2013
New Revision: 1493260

URL: http://svn.apache.org/r1493260
Log:
HIVE-4699 : Integrate basic UDFs for Timesamp (Gopal V via Ashutosh Chauhan)

Modified:
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFDayOfMonthLong.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFHourLong.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMinuteLong.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMonthLong.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFSecondLong.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFUnixTimeStampLong.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFWeekOfYearLong.java
     hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFYearLong.java

Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java Fri Jun 14 21:57:58 2013
@@ -42,6 +42,7 @@ import org.apache.hadoop.hive.ql.exec.ve
  import org.apache.hadoop.hive.ql.exec.vector.expressions.SelectColumnIsNull;
  import org.apache.hadoop.hive.ql.exec.vector.expressions.SelectColumnIsTrue;
  import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFUnixTimeStampLong;
  import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
  import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFCount;
  import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFCountStar;
@@ -70,6 +71,10 @@ import org.apache.hadoop.hive.ql.plan.Ex
  import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
  import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
  import org.apache.hadoop.hive.ql.plan.api.OperatorType;
+import org.apache.hadoop.hive.ql.udf.UDFDayOfMonth;
+import org.apache.hadoop.hive.ql.udf.UDFHour;
+import org.apache.hadoop.hive.ql.udf.UDFMinute;
+import org.apache.hadoop.hive.ql.udf.UDFMonth;
  import org.apache.hadoop.hive.ql.udf.UDFOPDivide;
  import org.apache.hadoop.hive.ql.udf.UDFOPMinus;
  import org.apache.hadoop.hive.ql.udf.UDFOPMod;
@@ -77,6 +82,9 @@ import org.apache.hadoop.hive.ql.udf.UDF
  import org.apache.hadoop.hive.ql.udf.UDFOPNegative;
  import org.apache.hadoop.hive.ql.udf.UDFOPPlus;
  import org.apache.hadoop.hive.ql.udf.UDFOPPositive;
+import org.apache.hadoop.hive.ql.udf.UDFSecond;
+import org.apache.hadoop.hive.ql.udf.UDFWeekOfYear;
+import org.apache.hadoop.hive.ql.udf.UDFYear;
  import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
  import org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge;
  import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd;
@@ -90,6 +98,7 @@ import org.apache.hadoop.hive.ql.udf.gen
  import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPNotNull;
  import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPNull;
  import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPOr;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp;
  import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
  import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;

@@ -386,6 +395,29 @@ public class VectorizationContext {
        return getVectorExpression((GenericUDFOPOr) udf, childExpr);
      } else if (udf instanceof GenericUDFBridge) {
        return getVectorExpression((GenericUDFBridge) udf, childExpr);
+ } else if(udf instanceof GenericUDFToUnixTimeStamp) {
+ return getVectorExpression((GenericUDFToUnixTimeStamp) udf, childExpr);
+ }
+ throw new HiveException("Udf: "+udf.getClass().getSimpleName()+", is not supported");
+ }
+
+ private VectorExpression getVectorExpression(GenericUDFToUnixTimeStamp udf,
+ List<ExprNodeDesc> childExpr) throws HiveException {
+ ExprNodeDesc leftExpr = childExpr.get(0);
+ leftExpr = foldConstantsForUnaryExpression(leftExpr);
+ VectorExpression v1 = getVectorExpression(leftExpr);
+ String colType = v1.getOutputType();
+ String outputType = "long";
+ if(colType.equalsIgnoreCase("timestamp")) {
+ int inputCol = v1.getOutputColumn();
+ int outputCol = ocm.allocateOutputColumn(outputType);
+ try {
+ VectorExpression v2 = new VectorUDFUnixTimeStampLong(inputCol, outputCol);
+ return v2;
+ } catch(Exception e) {
+ e.printStackTrace();
+ throw new HiveException("Udf: Vector"+udf+", could not be initialized for " + colType, e);
+ }
      }
      throw new HiveException("Udf: "+udf.getClass().getSimpleName()+", is not supported");
    }
@@ -408,10 +440,44 @@ public class VectorizationContext {
        return getUnaryMinusExpression(childExpr);
      } else if (cl.equals(UDFOPPositive.class)) {
        return getUnaryPlusExpression(childExpr);
+ } else if (cl.equals(UDFYear.class) ||
+ cl.equals(UDFMonth.class) ||
+ cl.equals(UDFWeekOfYear.class) ||
+ cl.equals(UDFDayOfMonth.class) ||
+ cl.equals(UDFHour.class) ||
+ cl.equals(UDFMinute.class) ||
+ cl.equals(UDFSecond.class)) {
+ return getTimestampFieldExpression(cl.getSimpleName(), childExpr);
      }
+
      throw new HiveException("Udf: "+udf.getClass().getSimpleName()+", is not supported");
    }

+ private VectorExpression getTimestampFieldExpression(String udf,
+ List<ExprNodeDesc> childExpr) throws HiveException {
+ ExprNodeDesc leftExpr = childExpr.get(0);
+ leftExpr = foldConstantsForUnaryExpression(leftExpr);
+ VectorExpression v1 = getVectorExpression(leftExpr);
+ String colType = v1.getOutputType();
+ String outputType = "long";
+ if(colType.equalsIgnoreCase("timestamp")) {
+ int inputCol = v1.getOutputColumn();
+ int outputCol = ocm.allocateOutputColumn(outputType);
+ String pkg = "org.apache.hadoop.hive.ql.exec.vector.expressions";
+ // org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFYearLong
+ String vectorUDF = pkg + ".Vector"+udf+"Long";
+ try {
+ VectorExpression v2 = (VectorExpression)Class.forName(vectorUDF).
+ getDeclaredConstructors()[0].newInstance(inputCol,outputCol);
+ return v2;
+ } catch(Exception e) {
+ e.printStackTrace();
+ throw new HiveException("Udf: Vector"+udf+", could not be initialized for " + colType, e);
+ }
+ }
+ throw new HiveException("Udf: "+udf+", is not supported for " + colType);
+ }
+
    private VectorExpression getBinaryArithmeticExpression(String method,
        List<ExprNodeDesc> childExpr) throws HiveException {
      ExprNodeDesc leftExpr = childExpr.get(0);

Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFDayOfMonthLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFDayOfMonthLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFDayOfMonthLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFDayOfMonthLong.java Fri Jun 14 21:57:58 2013
@@ -23,7 +23,7 @@ import java.util.Calendar;

  public final class VectorUDFDayOfMonthLong extends VectorUDFTimestampFieldLong {

- VectorUDFDayOfMonthLong(int colNum, int outputColumn) {
+ public VectorUDFDayOfMonthLong(int colNum, int outputColumn) {
      super(Calendar.DAY_OF_MONTH, colNum,outputColumn);
    }


Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFHourLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFHourLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFHourLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFHourLong.java Fri Jun 14 21:57:58 2013
@@ -23,7 +23,7 @@ import java.util.Calendar;

  public final class VectorUDFHourLong extends VectorUDFTimestampFieldLong {

- VectorUDFHourLong(int colNum, int outputColumn) {
+ public VectorUDFHourLong(int colNum, int outputColumn) {
      super(Calendar.HOUR_OF_DAY, colNum,outputColumn);
    }


Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMinuteLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMinuteLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMinuteLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMinuteLong.java Fri Jun 14 21:57:58 2013
@@ -23,7 +23,7 @@ import java.util.Calendar;

  public final class VectorUDFMinuteLong extends VectorUDFTimestampFieldLong {

- VectorUDFMinuteLong(int colNum, int outputColumn) {
+ public VectorUDFMinuteLong(int colNum, int outputColumn) {
      super(Calendar.MINUTE, colNum,outputColumn);
    }


Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMonthLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMonthLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMonthLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFMonthLong.java Fri Jun 14 21:57:58 2013
@@ -23,7 +23,7 @@ import java.util.Calendar;

  public final class VectorUDFMonthLong extends VectorUDFTimestampFieldLong {

- VectorUDFMonthLong(int colNum, int outputColumn) {
+ public VectorUDFMonthLong(int colNum, int outputColumn) {
      super(Calendar.MONTH, colNum,outputColumn);
    }


Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFSecondLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFSecondLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFSecondLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFSecondLong.java Fri Jun 14 21:57:58 2013
@@ -23,7 +23,7 @@ import java.util.Calendar;

  public final class VectorUDFSecondLong extends VectorUDFTimestampFieldLong {

- VectorUDFSecondLong(int colNum, int outputColumn) {
+ public VectorUDFSecondLong(int colNum, int outputColumn) {
      super(Calendar.SECOND, colNum,outputColumn);
    }


Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFUnixTimeStampLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFUnixTimeStampLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFUnixTimeStampLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFUnixTimeStampLong.java Fri Jun 14 21:57:58 2013
@@ -33,7 +33,7 @@ public final class VectorUDFUnixTimeStam
      return ms/1000;
    }

- VectorUDFUnixTimeStampLong(int colNum, int outputColumn) {
+ public VectorUDFUnixTimeStampLong(int colNum, int outputColumn) {
      /* not a real field */
      super(-1, colNum,outputColumn);
    }

Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFWeekOfYearLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFWeekOfYearLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFWeekOfYearLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFWeekOfYearLong.java Fri Jun 14 21:57:58 2013
@@ -23,7 +23,7 @@ import java.util.Calendar;

  public final class VectorUDFWeekOfYearLong extends VectorUDFTimestampFieldLong {

- VectorUDFWeekOfYearLong(int colNum, int outputColumn) {
+ public VectorUDFWeekOfYearLong(int colNum, int outputColumn) {
      super(Calendar.WEEK_OF_YEAR, colNum,outputColumn);
      /* code copied over from UDFWeekOfYear implementation */
      calendar.setFirstDayOfWeek(Calendar.MONDAY);

Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFYearLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFYearLong.java?rev=1493260&r1=1493259&r2=1493260&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFYearLong.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorUDFYearLong.java Fri Jun 14 21:57:58 2013
@@ -53,7 +53,7 @@ public final class VectorUDFYearLong ext
      }
    }

- VectorUDFYearLong(int colNum, int outputColumn) {
+ public VectorUDFYearLong(int colNum, int outputColumn) {
      super(Calendar.YEAR, colNum,outputColumn);
    }

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedJun 14, '13 at 9:58p
activeJun 14, '13 at 9:58p
posts1
users1
websitehive.apache.org

1 user in discussion

Hashutosh: 1 post

People

Translate

site design / logo © 2021 Grokbase