Review Board 1.7.22


Implement vectorized string column-scalar filters

Review Request #10840 - Created April 29, 2013 and updated

Eric Hanson
vectorization
HIVE-4383
Reviewers
hive
hive-git
Implement vectorized string column-scalar filters. Includes changes equivalent to HIVE-4348 to correct unit test build failure on Windows in this branch.

 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColEqualStringScalar.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
import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr;

    
   
23
import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;

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

    
   
25

   

    
   
26
/**

    
   
27
 * This is a generated class to evaluate a == comparison on a vector of strings.

    
   
28
 */

    
   
29
public class FilterStringColEqualStringScalar extends VectorExpression {

    
   
30
  private int colNum;

    
   
31
  private byte[] value;

    
   
32

   

    
   
33
  public FilterStringColEqualStringScalar(int colNum, byte[] value) {

    
   
34
    this.colNum = colNum;

    
   
35
    this.value = value;

    
   
36
  }

    
   
37

   

    
   
38
  @Override

    
   
39
  public void evaluate(VectorizedRowBatch batch) {

    
   
40
    BytesColumnVector inputColVector = (BytesColumnVector) batch.cols[colNum];

    
   
41
    int[] sel = batch.selected;

    
   
42
    boolean[] nullPos = inputColVector.isNull;

    
   
43
    int n = batch.size;

    
   
44
    byte[][] vector = inputColVector.vector;

    
   
45
    int[] length = inputColVector.length;

    
   
46
    int[] start = inputColVector.start;

    
   
47
    

    
   
48

   

    
   
49
    // return immediately if batch is empty

    
   
50
    if (n == 0) {

    
   
51
      return;

    
   
52
    }

    
   
53
    

    
   
54
    if (inputColVector.noNulls) {

    
   
55
      if (inputColVector.isRepeating) {

    
   
56
      

    
   
57
        // All must be selected otherwise size would be zero. Repeating property will not change.

    
   
58
        if (!(StringExpr.compare(vector[0], start[0], length[0], value, 0, value.length) == 0)) {

    
   
59

   

    
   
60
          //Entire batch is filtered out.

    
   
61
          batch.size = 0;

    
   
62
        }

    
   
63
      } else if (batch.selectedInUse) {

    
   
64
        int newSize = 0;

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

    
   
66
          int i = sel[j];

    
   
67
          if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) == 0) {

    
   
68
            sel[newSize++] = i;

    
   
69
          }

    
   
70
        }

    
   
71
        batch.size = newSize;

    
   
72
      } else {

    
   
73
        int newSize = 0;

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

    
   
75
          if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) == 0) {

    
   
76
            sel[newSize++] = i;

    
   
77
          }

    
   
78
        }

    
   
79
        if (newSize < n) {

    
   
80
          batch.size = newSize;

    
   
81
          batch.selectedInUse = true;

    
   
82
        }

    
   
83
      }

    
   
84
    } else {

    
   
85
      if (inputColVector.isRepeating) {

    
   
86
      

    
   
87
        // All must be selected otherwise size would be zero. Repeating property will not change.

    
   
88
        if (!nullPos[0]) {

    
   
89
          if (!(StringExpr.compare(vector[0], start[0], length[0], value, 0, value.length) == 0)) {

    
   
90

   

    
   
91
            //Entire batch is filtered out.

    
   
92
            batch.size = 0;

    
   
93
          }

    
   
94
        } else {

    
   
95
          batch.size = 0;

    
   
96
        }

    
   
97
      } else if (batch.selectedInUse) {

    
   
98
        int newSize = 0;

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

    
   
100
          int i = sel[j];

    
   
101
          if (!nullPos[i]) {

    
   
102
           if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) == 0) {

    
   
103
             sel[newSize++] = i;

    
   
104
           }

    
   
105
          }

    
   
106
        }

    
   
107
        

    
   
108
        //Change the selected vector

    
   
109
        batch.size = newSize;

    
   
110
      } else {

    
   
111
        int newSize = 0;

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

    
   
113
          if (!nullPos[i]) {

    
   
114
            if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) == 0) {

    
   
115
              sel[newSize++] = i;

    
   
116
            }

    
   
117
          }

    
   
118
        }

    
   
119
        if (newSize < n) {

    
   
120
          batch.size = newSize;

    
   
121
          batch.selectedInUse = true;

    
   
122
        }

    
   
123
      }

    
   
124
    }

    
   
125
  }

    
   
126

   

    
   
127
  @Override

    
   
128
  public int getOutputColumn() {

    
   
129
    return -1;

    
   
130
  }

    
   
131

   

    
   
132
  @Override

    
   
133
  public String getOutputType() {

    
   
134
    return "boolean";

    
   
135
  }

    
   
136
}
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColGreaterEqualStringScalar.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColGreaterStringScalar.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColLessEqualStringScalar.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColLessStringScalar.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColNotEqualStringScalar.java
New File
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/CodeGen.java
Revision 318541b New Change
 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareScalar.txt
New File
 
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java
Revision fe34b11 New Change
 
  1. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColEqualStringScalar.java: Loading...
  2. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColGreaterEqualStringScalar.java: Loading...
  3. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColGreaterStringScalar.java: Loading...
  4. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColLessEqualStringScalar.java: Loading...
  5. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColLessStringScalar.java: Loading...
  6. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/gen/FilterStringColNotEqualStringScalar.java: Loading...
  7. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/CodeGen.java: Loading...
  8. ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareScalar.txt: Loading...
  9. ql/src/test/org/apache/hadoop/hive/ql/exec/vector/expressions/TestVectorStringExpressions.java: Loading...