Review Board 1.7.22


Eric Hanson got review request #15251!

Add unit test for vectorized BETWEEN for timestamp inputs

Review Request #15251 - Created Nov. 5, 2013 and updated

Eric Hanson
trunk
HIVE-5699
Reviewers
hive
ashutoshc
hive-git
Add unit test for vectorized BETWEEN for timestamp inputs

 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
Revision a2ffebd New Change
[20] 32 lines
[+20]
33
import org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator;
33
import org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator;
34
import org.apache.hadoop.hive.ql.exec.ExprNodeEvaluatorFactory;
34
import org.apache.hadoop.hive.ql.exec.ExprNodeEvaluatorFactory;
35
import org.apache.hadoop.hive.ql.exec.FunctionInfo;
35
import org.apache.hadoop.hive.ql.exec.FunctionInfo;
36
import org.apache.hadoop.hive.ql.exec.FunctionRegistry;
36
import org.apache.hadoop.hive.ql.exec.FunctionRegistry;
37
import org.apache.hadoop.hive.ql.exec.UDF;
37
import org.apache.hadoop.hive.ql.exec.UDF;

    
   
38
import org.apache.hadoop.hive.ql.exec.vector.TimestampUtils;
38
import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor.InputExpressionType;
39
import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor.InputExpressionType;
39
import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor.Mode;
40
import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor.Mode;
40
import org.apache.hadoop.hive.ql.exec.vector.expressions.*;
41
import org.apache.hadoop.hive.ql.exec.vector.expressions.*;
41
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
42
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
42
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFCount;
43
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFCount;
[+20] [20] 511 lines
[+20] [+] private VectorExpression instantiateExpression(Class<?> vclass, Object...args)
554

    
   
555

   
555
  private VectorExpression getGenericUdfVectorExpression(GenericUDF udf,
556
  private VectorExpression getGenericUdfVectorExpression(GenericUDF udf,
556
      List<ExprNodeDesc> childExpr, Mode mode) throws HiveException {
557
      List<ExprNodeDesc> childExpr, Mode mode) throws HiveException {
557
    //First handle special cases
558
    //First handle special cases
558
    if (udf instanceof GenericUDFBetween) {
559
    if (udf instanceof GenericUDFBetween) {
559
      return getBetweenFilterExpression(childExpr);
560
      return getBetweenFilterExpression(childExpr, mode);
560
    } else if (udf instanceof GenericUDFBridge) {
561
    } else if (udf instanceof GenericUDFBridge) {
561
      VectorExpression v = getGenericUDFBridgeVectorExpression((GenericUDFBridge) udf, childExpr, mode);
562
      VectorExpression v = getGenericUDFBridgeVectorExpression((GenericUDFBridge) udf, childExpr, mode);
562
      if (v != null) {
563
      if (v != null) {
563
        return v;
564
        return v;
564
      }
565
      }
[+20] [20] 106 lines
[+20] [+] private VectorExpression getCastToLongExpression(List<ExprNodeDesc> childExpr)
671
   * because the NOT is actually specified in the expression tree as the first argument,
672
   * because the NOT is actually specified in the expression tree as the first argument,
672
   * and we don't want any runtime cost for that. So creating the VectorExpression
673
   * and we don't want any runtime cost for that. So creating the VectorExpression
673
   * needs to be done differently than the standard way where all arguments are
674
   * needs to be done differently than the standard way where all arguments are
674
   * passed to the VectorExpression constructor.
675
   * passed to the VectorExpression constructor.
675
   */
676
   */
676
  private VectorExpression getBetweenFilterExpression(List<ExprNodeDesc> childExpr)
677
  private VectorExpression getBetweenFilterExpression(List<ExprNodeDesc> childExpr, Mode mode)
677
      throws HiveException {
678
      throws HiveException {
678

    
   
679

   

    
   
680
    if (mode == Mode.PROJECTION) {

    
   
681

   

    
   
682
      // Projection mode is not yet supported for [NOT] BETWEEN. Return null so Vectorizer

    
   
683
      // knows to revert to row-at-a-time execution.

    
   
684
      return null;

    
   
685
    }

    
   
686

   
679
    boolean notKeywordPresent = (Boolean) ((ExprNodeConstantDesc) childExpr.get(0)).getValue();
687
    boolean notKeywordPresent = (Boolean) ((ExprNodeConstantDesc) childExpr.get(0)).getValue();
680
    ExprNodeDesc colExpr = childExpr.get(1);
688
    ExprNodeDesc colExpr = childExpr.get(1);
681

    
   
689

   
682
    // To hold left and right boundaries as long value in nanos for timestamp type.
690
    // To hold left and right boundaries as long value in nanos for timestamp type.
683
    long left, right;
691
    long left, right;
[+20] [20] 191 lines
[+20] [+] private long getTimestampScalar(ExprNodeDesc expr) throws HiveException {
875

    
   
883

   
876
      if (!(java instanceof Timestamp)) {
884
      if (!(java instanceof Timestamp)) {
877
        throw new HiveException("Udf: failed to convert from string to timestamp");
885
        throw new HiveException("Udf: failed to convert from string to timestamp");
878
      }
886
      }
879
      Timestamp ts = (Timestamp) java;
887
      Timestamp ts = (Timestamp) java;
880
      long result = ts.getTime();
888
      return TimestampUtils.getTimeNanoSec(ts);
881
      result *= 1000000;    // shift left 6 digits to make room for nanos below ms precision

   
882
      result += ts.getNanos() % 1000000;     // add in nanos, after removing the ms portion

   
883
      return result;

   
884
    }
889
    }
885

    
   
890

   
886
    throw new HiveException("Udf: unhandled constant type for scalar argument. "
891
    throw new HiveException("Udf: unhandled constant type for scalar argument. "
887
        + "Expecting string.");
892
        + "Expecting string.");
888
  }
893
  }
889

    
   
894

   
890

    
   

   
891
  private Constructor<?> getConstructor(Class<?> cl) throws HiveException {
895
  private Constructor<?> getConstructor(Class<?> cl) throws HiveException {
892
    try {
896
    try {
893
      Constructor<?> [] ctors = cl.getDeclaredConstructors();
897
      Constructor<?> [] ctors = cl.getDeclaredConstructors();
894
      if (ctors.length == 1) {
898
      if (ctors.length == 1) {
895
        return ctors[0];
899
        return ctors[0];
[+20] [20] 154 lines
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java
Revision 6afaf1b New Change
 
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorFilterExpressions.java
Revision 24da692 New Change
 
  1. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java: Loading...
  2. ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorizationContext.java: Loading...
  3. ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorFilterExpressions.java: Loading...