Review Board 1.7.22


Fix validation of nested expressions.

Review Request #14956 - Created Oct. 25, 2013 and updated

Jitendra Pandey
trunk
HIVE-5604
Reviewers
hive
ashutoshc
hive-git
Fix validation of nested expressions.

 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorExpressionDescriptor.java
Revision 8750a9a New Change
[20] 18 lines
[+20]
19
package org.apache.hadoop.hive.ql.exec.vector;
19
package org.apache.hadoop.hive.ql.exec.vector;
20

    
   
20

   
21
import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
21
import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
22
import org.apache.hadoop.hive.ql.metadata.HiveException;
22
import org.apache.hadoop.hive.ql.metadata.HiveException;
23

    
   
23

   
24
import java.util.Arrays;
24
/**
25

    
   
25
 * Describes a vector expression and encapsulates the {@link Mode}, number of arguments,

    
   
26
 * argument types {@link ArgumentType} and expression types {@link InputExpressionType}.

    
   
27
 */
26
public class VectorExpressionDescriptor {
28
public class VectorExpressionDescriptor {
27

    
   
29

   

    
   
30
  final static int MAX_NUM_ARGUMENTS = 3;

    
   
31

   
28
  public enum ArgumentType {
32
  public enum ArgumentType {
29
    NONE(0),
33
    NONE(0),
30
    LONG(1),
34
    LONG(1),
31
    DOUBLE(2),
35
    DOUBLE(2),
32
    STRING(3),
36
    STRING(3),
[+20] [20] 44 lines
[+20] [+] public int getValue() {
77
      return value;
81
      return value;
78
    }
82
    }
79
  }
83
  }
80

    
   
84

   
81
  /**
85
  /**
82
   * Each vector expression has a bitmap that determines the kind or a classification for
86
   * Builder builds a {@link Descriptor} object. Setter methods are provided to set the {@link Mode}, number
83
   * the expression. Following parameters are used to identify the kind of an expression.
87
   * of arguments, argument types and expression types for each argument.
84
   * <ol>

   
85
   * <li>The expression produces an output column (projection) or does in-place filtering

   
86
   *     (filter).</li>

   
87
   * <li>Number if arguments the expression takes (unary, binary etc). For now we assume maximum 3

   
88
   *     arguments.</li>

   
89
   * <li>Types of each argument (long/double/string)</li>

   
90
   * <li>The input to the expression is a column or a scalar.</li>

   
91
   * </ol>

   
92
   * The bitmap consists of 18 bits:

   
93
   *   <ul>

   
94
   *   <li>1 bit for filter/projection.

   
95
   *   <li>2 bits for number of input arguments.

   
96
   *   <li>3 bits for each argument type. Total 9 bits for maximum 3 arguments. For unary

   
97
   *       expressions only first 3 bits are set, rest of the 6 bits are set to 0.

   
98
   *   <li>2 bits to encode whether argument is a column or scalar. Total 6 bits for each argument.

   
99
   *   <ul>

   
100
   */
88
   */
101
  public static class Builder {
89
  public static class Builder {
102
    private Mode mode = Mode.PROJECTION;
90
    private Mode mode = Mode.PROJECTION;
103
    private final int maxNumArguments = 3;
91
    ArgumentType [] argTypes = new ArgumentType[MAX_NUM_ARGUMENTS];
104
    ArgumentType [] argTypes = new ArgumentType[maxNumArguments];
92
    InputExpressionType [] exprTypes = new InputExpressionType[MAX_NUM_ARGUMENTS];
105
    InputExpressionType [] exprTypes = new InputExpressionType[maxNumArguments];

   
106
    private int argCount = 0;
93
    private int argCount = 0;
107

    
   
94

   
108
    public Builder() {
95
    public Builder() {
109
      argTypes[0] = ArgumentType.NONE;
96
      for (int i = 0 ; i < MAX_NUM_ARGUMENTS; i++) {
110
      argTypes[1] = ArgumentType.NONE;
97
        argTypes[i] = ArgumentType.NONE;
111
      argTypes[2] = ArgumentType.NONE;
98
        exprTypes[i] = InputExpressionType.NONE;
112
      exprTypes[0] = InputExpressionType.NONE;
99
      }
113
      exprTypes[1] = InputExpressionType.NONE;

   
114
      exprTypes[2] = InputExpressionType.NONE;

   
115
    }
100
    }
116

    
   
101

   
117
    public Builder setMode(Mode m) {
102
    public Builder setMode(Mode m) {
118
      this.mode = m;
103
      this.mode = m;
119
      return this;
104
      return this;
[+20] [20] 44 lines
[+20] [+] public Builder setInputExpressionType(int index, InputExpressionType type) {
164
      return new Descriptor(mode, argCount, argTypes, exprTypes);
149
      return new Descriptor(mode, argCount, argTypes, exprTypes);
165
    }
150
    }
166
  }
151
  }
167

    
   
152

   
168
  /**
153
  /**
169
   * Descriptor is immutable and is constructed by the {@link Builder} only.
154
   * Descriptor is immutable and is constructed by the {@link Builder} only. {@link #equals(Object)} is the only

    
   
155
   * publicly exposed member which can be used to compare two descriptors.
170
   */
156
   */
171
  public static final class Descriptor {
157
  public static final class Descriptor {
172

    
   
158

   
173
    @Override
159
    @Override
174
    public boolean equals(Object o) {
160
    public boolean equals(Object o) {
[+20] [20] 47 lines
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
Revision 4a9b870 New Change
 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/Vectorizer.java
Revision e698870 New Change
 
ql/src/test/org/apache/hadoop/hive/ql/optimizer/physical/TestVectorizer.java
Revision 51bc09a New Change
 
  1. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorExpressionDescriptor.java: Loading...
  2. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java: Loading...
  3. ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/Vectorizer.java: Loading...
  4. ql/src/test/org/apache/hadoop/hive/ql/optimizer/physical/TestVectorizer.java: Loading...