Review Board 1.7.22


New code to implement vectorized Scalar-Column arithmetic expression evaluation

Review Request #10706 - Created April 22, 2013 and updated

Eric Hanson
vectorization
HIVE-4380
Reviewers
hive
hive-git
New code to implement vectorized Scalar-Column arithmetic expression evaluation.

Several of the files are generated from templates/ScalarArithmeticColumn.txt. For easiest review, just have a look over the template, and review one of the generated files, say gen/LongScalarSubtractLongColumn.java. No need to review all the generated files. We plan to change the build system so the generated files don't get checked in at some point in the future.

 

Diff revision 1 (Latest)

  1. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarAddDoubleColumn.java: Loading...
  2. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarAddLongColumn.java: Loading...
  3. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarDivideDoubleColumn.java: Loading...
  4. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarDivideLongColumn.java: Loading...
  5. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarModuloDoubleColumn.java: Loading...
  6. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarModuloLongColumn.java: Loading...
  7. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarMultiplyDoubleColumn.java: Loading...
  8. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarMultiplyLongColumn.java: Loading...
  9. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarSubtractDoubleColumn.java: Loading...
  10. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarSubtractLongColumn.java: Loading...
  11. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarAddDoubleColumn.java: Loading...
  12. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarAddLongColumn.java: Loading...
  13. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarDivideDoubleColumn.java: Loading...
  14. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarDivideLongColumn.java: Loading...
  15. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarModuloDoubleColumn.java: Loading...
  16. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarModuloLongColumn.java: Loading...
  17. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarMultiplyDoubleColumn.java: Loading...
  18. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarMultiplyLongColumn.java: Loading...
  19. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarSubtractDoubleColumn.java: Loading...
  20. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarSubtractLongColumn.java: Loading...
  21. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/CodeGen.java: Loading...
  22. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ScalarArithmeticColumn.txt: Loading...
  23. ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorScalarColArithmetic.java: Loading...
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarAddDoubleColumn.java
New File

    
   
1
/**

    
   
2
 * Licensed to the Apache Software Foundation (ASF) under one

    
   
3
 * or more contributor license agreements.  See the NOTICE file

    
   
4
 * distributed with this work for additional information

    
   
5
 * regarding copyright ownership.  The ASF licenses this file

    
   
6
 * to you under the Apache License, Version 2.0 (the

    
   
7
 * "License"); you may not use this file except in compliance

    
   
8
 * with the License.  You may obtain a copy of the License at

    
   
9
 *

    
   
10
 *     http://www.apache.org/licenses/LICENSE-2.0

    
   
11
 *

    
   
12
 * Unless required by applicable law or agreed to in writing, software

    
   
13
 * distributed under the License is distributed on an "AS IS" BASIS,

    
   
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

    
   
15
 * See the License for the specific language governing permissions and

    
   
16
 * limitations under the License.

    
   
17
 */

    
   
18
 

    
   
19
package org.apache.hadoop.hive.ql.exec.vector.expressions.gen;

    
   
20

   

    
   
21
import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;

    
   
22

   

    
   
23
/*

    
   
24
 * Because of the templatized nature of the code, either or both

    
   
25
 * of these ColumnVector imports may be needed. Listing both of them

    
   
26
 * rather than using ....vectorization.*;

    
   
27
 */

    
   
28
import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;

    
   
29
import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;

    
   
30
import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;

    
   
31

   

    
   
32
/**

    
   
33
 * Implements a vectorized arithmetic operator with a scalar on the left and a

    
   
34
 * column vector on the right. The result is output to an output column vector.

    
   
35
 */

    
   
36
public class DoubleScalarAddDoubleColumn extends VectorExpression {

    
   
37
  private int colNum;

    
   
38
  private double value;

    
   
39
  private int outputColumn;

    
   
40

   

    
   
41
  public DoubleScalarAddDoubleColumn(double value, int colNum, int outputColumn) {

    
   
42
    this.colNum = colNum;

    
   
43
    this.value = value;

    
   
44
    this.outputColumn = outputColumn;

    
   
45
  }

    
   
46

   

    
   
47
  @Override

    
   
48
  /**

    
   
49
   * Method to evaluate scalar-column operation in vectorized fashion.

    
   
50
   *

    
   
51
   * @batch a package of rows with each column stored in a vector

    
   
52
   */

    
   
53
  public void evaluate(VectorizedRowBatch batch) {

    
   
54
    DoubleColumnVector inputColVector = (DoubleColumnVector) batch.cols[colNum];

    
   
55
    DoubleColumnVector outputColVector = (DoubleColumnVector) batch.cols[outputColumn];

    
   
56
    int[] sel = batch.selected;

    
   
57
    boolean[] inputIsNull = inputColVector.isNull;

    
   
58
    boolean[] outputIsNull = outputColVector.isNull;

    
   
59
    outputColVector.noNulls = inputColVector.noNulls;

    
   
60
    int n = batch.size;

    
   
61
    double[] vector = inputColVector.vector;

    
   
62
    double[] outputVector = outputColVector.vector;

    
   
63
    

    
   
64
    // return immediately if batch is empty

    
   
65
    if (n == 0) {

    
   
66
      return;

    
   
67
    }

    
   
68

   

    
   
69
    if (inputColVector.isRepeating) {

    
   
70
    

    
   
71
      /*

    
   
72
       * All must be selected otherwise size would be zero

    
   
73
       * Repeating property will not change.

    
   
74
       */

    
   
75
      outputVector[0] = value + vector[0];

    
   
76
      

    
   
77
      // Even if there are no nulls, we always copy over entry 0. Simplifies code.

    
   
78
      outputIsNull[0] = inputIsNull[0]; 

    
   
79
      outputColVector.isRepeating = true;

    
   
80
    } else if (inputColVector.noNulls) {

    
   
81
      if (batch.selectedInUse) {

    
   
82
        for(int j = 0; j != n; j++) {

    
   
83
          int i = sel[j];

    
   
84
          outputVector[i] = value + vector[i];

    
   
85
        }

    
   
86
      } else {

    
   
87
        for(int i = 0; i != n; i++) {

    
   
88
          outputVector[i] = value + vector[i];

    
   
89
        }

    
   
90
      }

    
   
91
      outputColVector.isRepeating = false;

    
   
92
    } else {                         /* there are nulls */ 

    
   
93
      if (batch.selectedInUse) {

    
   
94
        for(int j = 0; j != n; j++) {

    
   
95
          int i = sel[j];

    
   
96
          outputVector[i] = value + vector[i];

    
   
97
          outputIsNull[i] = inputIsNull[i];

    
   
98
        }

    
   
99
      } else {

    
   
100
        for(int i = 0; i != n; i++) {

    
   
101
          outputVector[i] = value + vector[i];

    
   
102
        }

    
   
103
        System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);

    
   
104
      }

    
   
105
      outputColVector.isRepeating = false;

    
   
106
    }

    
   
107
  }

    
   
108

   

    
   
109
  @Override

    
   
110
  public int getOutputColumn() {

    
   
111
    return outputColumn;

    
   
112
  }

    
   
113
  

    
   
114
  @Override

    
   
115
  public String getOutputType() {

    
   
116
    return "double";

    
   
117
  }

    
   
118
}
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarAddLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarDivideDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarDivideLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarModuloDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarModuloLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarMultiplyDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarMultiplyLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarSubtractDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarSubtractLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarAddDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarAddLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarDivideDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarDivideLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarModuloDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarModuloLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarMultiplyDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarMultiplyLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarSubtractDoubleColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarSubtractLongColumn.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/CodeGen.java
Revision d6f45d3 New Change
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ScalarArithmeticColumn.txt
New File
 
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorScalarColArithmetic.java
New File
 
  1. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarAddDoubleColumn.java: Loading...
  2. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarAddLongColumn.java: Loading...
  3. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarDivideDoubleColumn.java: Loading...
  4. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarDivideLongColumn.java: Loading...
  5. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarModuloDoubleColumn.java: Loading...
  6. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarModuloLongColumn.java: Loading...
  7. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarMultiplyDoubleColumn.java: Loading...
  8. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarMultiplyLongColumn.java: Loading...
  9. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarSubtractDoubleColumn.java: Loading...
  10. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/DoubleScalarSubtractLongColumn.java: Loading...
  11. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarAddDoubleColumn.java: Loading...
  12. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarAddLongColumn.java: Loading...
  13. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarDivideDoubleColumn.java: Loading...
  14. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarDivideLongColumn.java: Loading...
  15. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarModuloDoubleColumn.java: Loading...
  16. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarModuloLongColumn.java: Loading...
  17. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarMultiplyDoubleColumn.java: Loading...
  18. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarMultiplyLongColumn.java: Loading...
  19. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarSubtractDoubleColumn.java: Loading...
  20. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/LongScalarSubtractLongColumn.java: Loading...
  21. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/CodeGen.java: Loading...
  22. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ScalarArithmeticColumn.txt: Loading...
  23. ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorScalarColArithmetic.java: Loading...