diff --git ql/src/gen/vectorization/ExpressionTemplates/ColumnArithmeticColumn.txt ql/src/gen/vectorization/ExpressionTemplates/ColumnArithmeticColumn.txt new file mode 100644 index 0000000..2ab4aec --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/ColumnArithmeticColumn.txt @@ -0,0 +1,157 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil; +import org.apache.hadoop.hive.ql.exec.vector.*; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * Generated from template ColumnArithmeticColumn.txt, which covers binary arithmetic + * expressions between columns. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum1; + private int colNum2; + private int outputColumn; + + public (int colNum1, int colNum2, int outputColumn) { + this.colNum1 = colNum1; + this.colNum2 = colNum2; + this.outputColumn = outputColumn; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + inputColVector1 = () batch.cols[colNum1]; + inputColVector2 = () batch.cols[colNum2]; + outputColVector = () batch.cols[outputColumn]; + int[] sel = batch.selected; + int n = batch.size; + [] vector1 = inputColVector1.vector; + [] vector2 = inputColVector2.vector; + [] outputVector = outputColVector.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + outputColVector.isRepeating = + inputColVector1.isRepeating && inputColVector2.isRepeating + || inputColVector1.isRepeating && !inputColVector1.noNulls && inputColVector1.isNull[0] + || inputColVector2.isRepeating && !inputColVector2.noNulls && inputColVector2.isNull[0]; + + // Handle nulls first + NullUtil.propagateNullsColCol( + inputColVector1, inputColVector2, outputColVector, sel, n, batch.selectedInUse); + + /* Disregard nulls for processing. In other words, + * the arithmetic operation is performed even if one or + * more inputs are null. This is to improve speed by avoiding + * conditional checks in the inner loop. + */ + if (inputColVector1.isRepeating && inputColVector2.isRepeating) { + outputVector[0] = vector1[0] vector2[0]; + } else if (inputColVector1.isRepeating) { + if (batch.selectedInUse) { + for(int j = 0; j != n; j++) { + int i = sel[j]; + outputVector[i] = vector1[0] vector2[i]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = vector1[0] vector2[i]; + } + } + } else if (inputColVector2.isRepeating) { + if (batch.selectedInUse) { + for(int j = 0; j != n; j++) { + int i = sel[j]; + outputVector[i] = vector1[i] vector2[0]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = vector1[i] vector2[0]; + } + } + } else { + if (batch.selectedInUse) { + for(int j = 0; j != n; j++) { + int i = sel[j]; + outputVector[i] = vector1[i] vector2[i]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = vector1[i] vector2[i]; + } + } + } + + /* For the case when the output can have null values, follow + * the convention that the data values must be 1 for long and + * NaN for double. This is to prevent possible later zero-divide errors + * in complex arithmetic expressions like col2 / (col1 - 1) + * in the case when some col1 entries are null. + */ + NullUtil.setNullDataEntries(outputColVector, batch.selectedInUse, sel, n); + } + + @Override + public int getOutputColumn() { + return outputColumn; + } + + @Override + public String getOutputType() { + return ""; + } + + public int getColNum1() { + return colNum1; + } + + public void setColNum1(int colNum1) { + this.colNum1 = colNum1; + } + + public int getColNum2() { + return colNum2; + } + + public void setColNum2(int colNum2) { + this.colNum2 = colNum2; + } + + public void setOutputColumn(int outputColumn) { + this.outputColumn = outputColumn; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/ColumnArithmeticScalar.txt ql/src/gen/vectorization/ExpressionTemplates/ColumnArithmeticScalar.txt new file mode 100644 index 0000000..35890f8 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/ColumnArithmeticScalar.txt @@ -0,0 +1,134 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.; +import org.apache.hadoop.hive.ql.exec.vector.; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil; + +/** + * Generated from template ColumnArithmeticScalar.txt, which covers binary arithmetic + * expressions between a column and a scalar. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private value; + private int outputColumn; + + public (int colNum, value, int outputColumn) { + this.colNum = colNum; + this.value = value; + this.outputColumn = outputColumn; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + inputColVector = () batch.cols[colNum]; + outputColVector = () batch.cols[outputColumn]; + int[] sel = batch.selected; + boolean[] inputIsNull = inputColVector.isNull; + boolean[] outputIsNull = outputColVector.isNull; + outputColVector.noNulls = inputColVector.noNulls; + outputColVector.isRepeating = inputColVector.isRepeating; + int n = batch.size; + [] vector = inputColVector.vector; + [] outputVector = outputColVector.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector.isRepeating) { + outputVector[0] = vector[0] value; + + // Even if there are no nulls, we always copy over entry 0. Simplifies code. + outputIsNull[0] = inputIsNull[0]; + } else if (inputColVector.noNulls) { + if (batch.selectedInUse) { + for(int j = 0; j != n; j++) { + int i = sel[j]; + outputVector[i] = vector[i] value; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = vector[i] value; + } + } + } else /* there are nulls */ { + if (batch.selectedInUse) { + for(int j = 0; j != n; j++) { + int i = sel[j]; + outputVector[i] = vector[i] value; + outputIsNull[i] = inputIsNull[i]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = vector[i] value; + } + System.arraycopy(inputIsNull, 0, outputIsNull, 0, n); + } + } + + NullUtil.setNullOutputEntriesColScalar(outputColVector, batch.selectedInUse, sel, n); + } + + @Override + public int getOutputColumn() { + return outputColumn; + } + + @Override + public String getOutputType() { + return ""; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public getValue() { + return value; + } + + public void setValue( value) { + this.value = value; + } + + public void setOutputColumn(int outputColumn) { + this.outputColumn = outputColumn; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/ColumnCompareScalar.txt ql/src/gen/vectorization/ExpressionTemplates/ColumnCompareScalar.txt new file mode 100644 index 0000000..e333224 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/ColumnCompareScalar.txt @@ -0,0 +1,149 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.; +import org.apache.hadoop.hive.ql.exec.vector.; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * Generated from template ColumnCompareScalar.txt, which covers binary comparison + * expressions between a column and a scalar. The boolean output is stored in a + * separate boolean column. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private value; + private int outputColumn; + + public (int colNum, value, int outputColumn) { + this.colNum = colNum; + this.value = value; + this.outputColumn = outputColumn; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + inputColVector = () batch.cols[colNum]; + outputColVector = () batch.cols[outputColumn]; + int[] sel = batch.selected; + boolean[] nullPos = inputColVector.isNull; + boolean[] outNulls = outputColVector.isNull; + int n = batch.size; + [] vector = inputColVector.vector; + [] outputVector = outputColVector.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + outputColVector.isRepeating = false; + outputColVector.noNulls = inputColVector.noNulls; + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + outputVector[0] = vector[0] value ? 1 : 0; + outputColVector.isRepeating = true; + } else if (batch.selectedInUse) { + for(int j=0; j != n; j++) { + int i = sel[j]; + outputVector[i] = vector[i] value ? 1 : 0; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = vector[i] value ? 1 : 0; + } + } + } else { + if (inputColVector.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + if (!nullPos[0]) { + outputVector[0] = vector[0] value ? 1 : 0; + outNulls[0] = false; + } else { + outNulls[0] = true; + } + outputColVector.isRepeating = true; + } else if (batch.selectedInUse) { + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos[i]) { + outputVector[i] = vector[i] value ? 1 : 0; + outNulls[i] = false; + } else { + //comparison with null is null + outNulls[i] = true; + } + } + } else { + System.arraycopy(nullPos, 0, outNulls, 0, n); + for(int i = 0; i != n; i++) { + if (!nullPos[i]) { + outputVector[i] = vector[i] value ? 1 : 0; + } + } + } + } + } + + @Override + public int getOutputColumn() { + return outputColumn; + } + + @Override + public String getOutputType() { + return ""; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public getValue() { + return value; + } + + public void setValue( value) { + this.value = value; + } + + public void setOutputColumn(int outputColumn) { + this.outputColumn = outputColumn; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/ColumnUnaryMinus.txt ql/src/gen/vectorization/ExpressionTemplates/ColumnUnaryMinus.txt new file mode 100644 index 0000000..085145a --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/ColumnUnaryMinus.txt @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.*; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * Generated from template ColumnUnaryMinus.txt, which covers unary negation operator. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private int outputColumn; + + public (int colNum, int outputColumn) { + this.colNum = colNum; + this.outputColumn = outputColumn; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + this.evaluateChildren(batch); + } + + inputColVector = () batch.cols[colNum]; + outputColVector = () batch.cols[outputColumn]; + int[] sel = batch.selected; + boolean[] inputIsNull = inputColVector.isNull; + boolean[] outputIsNull = outputColVector.isNull; + outputColVector.noNulls = inputColVector.noNulls; + int n = batch.size; + [] vector = inputColVector.vector; + [] outputVector = outputColVector.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + outputVector[0] = - vector[0]; + // Even if there are no nulls, we always copy over entry 0. Simplifies code. + outputIsNull[0] = inputIsNull[0]; + outputColVector.isRepeating = true; + } else if (inputColVector.noNulls) { + if (batch.selectedInUse) { + for(int j=0; j != n; j++) { + int i = sel[j]; + outputVector[i] = -vector[i]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = -vector[i]; + } + } + outputColVector.isRepeating = false; + } else /* there are nulls */ { + if (batch.selectedInUse) { + for(int j=0; j != n; j++) { + int i = sel[j]; + outputVector[i] = -vector[i]; + outputIsNull[i] = inputIsNull[i]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = -vector[i]; + } + System.arraycopy(inputIsNull, 0, outputIsNull, 0, n); + } + outputColVector.isRepeating = false; + } + } + + @Override + public int getOutputColumn() { + return outputColumn; + } + + @Override + public String getOutputType() { + return ""; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public void setOutputColumn(int outputColumn) { + this.outputColumn = outputColumn; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/FilterColumnCompareColumn.txt ql/src/gen/vectorization/ExpressionTemplates/FilterColumnCompareColumn.txt new file mode 100644 index 0000000..1c16816 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/FilterColumnCompareColumn.txt @@ -0,0 +1,254 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.*; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * Generated from template FilterColumnCompareColumn.txt, which covers binary comparison + * expressions between two columns, however output is not produced in a separate column. + * The selected vector of the input {@link VectorizedRowBatch} is updated for in-place filtering. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum1; + private int colNum2; + + public (int colNum1, int colNum2) { + this.colNum1 = colNum1; + this.colNum2 = colNum2; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + inputColVector1 = () batch.cols[colNum1]; + inputColVector2 = () batch.cols[colNum2]; + int[] sel = batch.selected; + boolean[] nullPos1 = inputColVector1.isNull; + boolean[] nullPos2 = inputColVector2.isNull; + int n = batch.size; + [] vector1 = inputColVector1.vector; + [] vector2 = inputColVector2.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector1.noNulls && inputColVector2.noNulls) { + if (inputColVector1.isRepeating && inputColVector2.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + if (!(vector1[0] vector2[0])) { + batch.size = 0; + } + } else if (inputColVector1.isRepeating) { + if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (vector1[0] vector2[i]) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (vector1[0] vector2[i]) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (inputColVector2.isRepeating) { + if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (vector1[i] vector2[0]) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (vector1[i] vector2[0]) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (vector1[i] vector2[i]) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (vector1[i] vector2[i]) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (inputColVector1.isRepeating && inputColVector2.isRepeating) { + if (nullPos1[0] || nullPos2[0]) { + batch.size = 0; + } + } else if (inputColVector1.isRepeating) { + if (nullPos1[0]) { + batch.size = 0; + } else { + if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos2[i]) { + if (vector1[0] vector2[i]) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos2[i]) { + if (vector1[0] vector2[i]) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + } else if (inputColVector2.isRepeating) { + if (nullPos2[0]) { + batch.size = 0; + } else { + if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos1[i]) { + if (vector1[i] vector2[0]) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos1[i]) { + if (vector1[i] vector2[0]) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos1[i] && !nullPos2[i]) { + if (vector1[i] vector2[i]) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos1[i] && !nullPos2[i]) { + if (vector1[i] vector2[i]) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + + @Override + public String getOutputType() { + return "boolean"; + } + + @Override + public int getOutputColumn() { + return -1; + } + + public int getColNum1() { + return colNum1; + } + + public void setColNum1(int colNum1) { + this.colNum1 = colNum1; + } + + public int getColNum2() { + return colNum2; + } + + public void setColNum2(int colNum2) { + this.colNum2 = colNum2; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/FilterColumnCompareScalar.txt ql/src/gen/vectorization/ExpressionTemplates/FilterColumnCompareScalar.txt new file mode 100644 index 0000000..bf02419 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/FilterColumnCompareScalar.txt @@ -0,0 +1,158 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * Generated from template FilterColumnCompareScalar.txt, which covers binary comparison + * expressions between a column and a scalar, however output is not produced in a separate column. + * The selected vector of the input {@link VectorizedRowBatch} is updated for in-place filtering. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private value; + + public (int colNum, value) { + this.colNum = colNum; + this.value = value; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + inputColVector = () batch.cols[colNum]; + int[] sel = batch.selected; + boolean[] nullPos = inputColVector.isNull; + int n = batch.size; + [] vector = inputColVector.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + if (!(vector[0] value)) { + //Entire batch is filtered out. + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (vector[i] value) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (vector[i] value) { + sel[newSize++] = i; + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else { + if (inputColVector.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + if (!nullPos[0]) { + if (!(vector[0] value)) { + //Entire batch is filtered out. + batch.size = 0; + } + } else { + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos[i]) { + if (vector[i] value) { + sel[newSize++] = i; + } + } + } + //Change the selected vector + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos[i]) { + if (vector[i] value) { + sel[newSize++] = i; + } + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + } + + @Override + public int getOutputColumn() { + return -1; + } + + @Override + public String getOutputType() { + return "boolean"; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public getValue() { + return value; + } + + public void setValue( value) { + this.value = value; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/FilterScalarCompareColumn.txt ql/src/gen/vectorization/ExpressionTemplates/FilterScalarCompareColumn.txt new file mode 100644 index 0000000..9a1d741 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/FilterScalarCompareColumn.txt @@ -0,0 +1,158 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * Generated from template FilterScalarCompareColumn.txt, which covers binary comparison + * expressions between a scalar and a column, however output is not produced in a separate column. + * The selected vector of the input {@link VectorizedRowBatch} is updated for in-place filtering. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private value; + + public (int colNum, value) { + this.colNum = colNum; + this.value = value; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + inputColVector = () batch.cols[colNum]; + int[] sel = batch.selected; + boolean[] nullPos = inputColVector.isNull; + int n = batch.size; + [] vector = inputColVector.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + if (!(value vector[0])) { + //Entire batch is filtered out. + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (value vector[i]) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (value vector[i]) { + sel[newSize++] = i; + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else { + if (inputColVector.isRepeating) { + //All must be selected otherwise size would be zero + //Repeating property will not change. + if (!nullPos[0]) { + if (!(value vector[0])) { + //Entire batch is filtered out. + batch.size = 0; + } + } else { + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos[i]) { + if (value vector[i]) { + sel[newSize++] = i; + } + } + } + //Change the selected vector + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos[i]) { + if (value vector[i]) { + sel[newSize++] = i; + } + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + } + + @Override + public int getOutputColumn() { + return -1; + } + + @Override + public String getOutputType() { + return "boolean"; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public getValue() { + return value; + } + + public void setValue( value) { + this.value = value; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/FilterStringColumnCompareColumn.txt ql/src/gen/vectorization/ExpressionTemplates/FilterStringColumnCompareColumn.txt new file mode 100644 index 0000000..449c010 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/FilterStringColumnCompareColumn.txt @@ -0,0 +1,477 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * Filter the rows in a batch by comparing one string column to another. + * This code is generated from a template. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum1; + private int colNum2; + + public (int colNum1, int colNum2) { + this.colNum1 = colNum1; + this.colNum2 = colNum2; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + BytesColumnVector inputColVector1 = (BytesColumnVector) batch.cols[colNum1]; + BytesColumnVector inputColVector2 = (BytesColumnVector) batch.cols[colNum2]; + int[] sel = batch.selected; + boolean[] nullPos1 = inputColVector1.isNull; + boolean[] nullPos2 = inputColVector2.isNull; + int n = batch.size; + byte[][] vector1 = inputColVector1.vector; + byte[][] vector2 = inputColVector2.vector; + int[] start1 = inputColVector1.start; + int[] start2 = inputColVector2.start; + int[] length1 = inputColVector1.length; + int[] length2 = inputColVector2.length; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + // handle case where neither input has nulls + if (inputColVector1.noNulls && inputColVector2.noNulls) { + if (inputColVector1.isRepeating && inputColVector2.isRepeating) { + + /* Either all must remain selected or all will be eliminated. + * Repeating property will not change. + */ + if (!(StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[0], start2[0], length2[0]) 0)) { + batch.size = 0; + } + } else if (inputColVector1.isRepeating) { + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (inputColVector2.isRepeating) { + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + + // handle case where only input 2 has nulls + } else if (inputColVector1.noNulls) { + if (inputColVector1.isRepeating && inputColVector2.isRepeating) { + if (nullPos2[0] || + !(StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[0], start2[0], length2[0]) 0)) { + batch.size = 0; + } + } else if (inputColVector1.isRepeating) { + + // no need to check for nulls in input 1 + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (!nullPos2[i]) { + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos2[i]) { + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (inputColVector2.isRepeating) { + if (nullPos2[0]) { + + // no values will qualify because every comparison will be with NULL + batch.size = 0; + return; + } + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else { // neither input is repeating + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (!nullPos2[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos2[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + + // handle case where only input 1 has nulls + } else if (inputColVector2.noNulls) { + if (inputColVector1.isRepeating && inputColVector2.isRepeating) { + if (nullPos1[0] || + !(StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[0], start2[0], length2[0]) 0)) { + batch.size = 0; + return; + } + } else if (inputColVector1.isRepeating) { + if (nullPos1[0]) { + + // if repeating value is null then every comparison will fail so nothing qualifies + batch.size = 0; + return; + } + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (inputColVector2.isRepeating) { + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (!nullPos1[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos2[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else { // neither input is repeating + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (!nullPos1[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos1[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + + // handle case where both inputs have nulls + } else { + if (inputColVector1.isRepeating && inputColVector2.isRepeating) { + if (nullPos1[0] || nullPos2[0] || + !(StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[0], start2[0], length2[0]) 0)) { + batch.size = 0; + } + } else if (inputColVector1.isRepeating) { + if (nullPos1[0]) { + batch.size = 0; + return; + } + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (!nullPos2[i]) { + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos2[i]) { + if (StringExpr.compare(vector1[0], start1[0], length1[0], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else if (inputColVector2.isRepeating) { + if (nullPos2[0]) { + batch.size = 0; + return; + } + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (!nullPos1[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos1[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[0], start2[0], length2[0]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else { // neither input is repeating + if (batch.selectedInUse) { + int newSize = 0; + for(int j = 0; j != n; j++) { + int i = sel[j]; + if (!nullPos1[i] && !nullPos2[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos1[i] && !nullPos2[i]) { + if (StringExpr.compare(vector1[i], start1[i], length1[i], + vector2[i], start2[i], length2[i]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < batch.size) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + } + } + + @Override + public String getOutputType() { + return "boolean"; + } + + @Override + public int getOutputColumn() { + return -1; + } + + public int getColNum1() { + return colNum1; + } + + public void setColNum1(int colNum1) { + this.colNum1 = colNum1; + } + + public int getColNum2() { + return colNum2; + } + + public void setColNum2(int colNum2) { + this.colNum2 = colNum2; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/FilterStringColumnCompareScalar.txt ql/src/gen/vectorization/ExpressionTemplates/FilterStringColumnCompareScalar.txt new file mode 100644 index 0000000..690dd3c --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/FilterStringColumnCompareScalar.txt @@ -0,0 +1,161 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * This is a generated class to evaluate a comparison on a vector of strings. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private byte[] value; + + public (int colNum, byte[] value) { + this.colNum = colNum; + this.value = value; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + if (childExpressions != null) { + super.evaluateChildren(batch); + } + BytesColumnVector inputColVector = (BytesColumnVector) batch.cols[colNum]; + int[] sel = batch.selected; + boolean[] nullPos = inputColVector.isNull; + int n = batch.size; + byte[][] vector = inputColVector.vector; + int[] length = inputColVector.length; + int[] start = inputColVector.start; + + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + + // All must be selected otherwise size would be zero. Repeating property will not change. + if (!(StringExpr.compare(vector[0], start[0], length[0], value, 0, value.length) 0)) { + + //Entire batch is filtered out. + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { + sel[newSize++] = i; + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else { + if (inputColVector.isRepeating) { + + // All must be selected otherwise size would be zero. Repeating property will not change. + if (!nullPos[0]) { + if (!(StringExpr.compare(vector[0], start[0], length[0], value, 0, value.length) 0)) { + + //Entire batch is filtered out. + batch.size = 0; + } + } else { + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos[i]) { + if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { + sel[newSize++] = i; + } + } + } + + //Change the selected vector + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos[i]) { + if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + } + + @Override + public int getOutputColumn() { + return -1; + } + + @Override + public String getOutputType() { + return "boolean"; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public byte[] getValue() { + return value; + } + + public void setValue(byte[] value) { + this.value = value; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/FilterStringScalarCompareColumn.txt ql/src/gen/vectorization/ExpressionTemplates/FilterStringScalarCompareColumn.txt new file mode 100644 index 0000000..5ba7703 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/FilterStringScalarCompareColumn.txt @@ -0,0 +1,162 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; + +/** + * This is a generated class to evaluate a comparison on a vector of strings. + * Do not edit the generated code directly. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private byte[] value; + + public (int colNum, byte[] value) { + this.colNum = colNum; + this.value = value; + } + + public () { + } + + @Override + public void evaluate(VectorizedRowBatch batch) { + if (childExpressions != null) { + super.evaluateChildren(batch); + } + BytesColumnVector inputColVector = (BytesColumnVector) batch.cols[colNum]; + int[] sel = batch.selected; + boolean[] nullPos = inputColVector.isNull; + int n = batch.size; + byte[][] vector = inputColVector.vector; + int[] length = inputColVector.length; + int[] start = inputColVector.start; + + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + + // All must be selected otherwise size would be zero. Repeating property will not change. + if (!(StringExpr.compare(value, 0, value.length, vector[0], start[0], length[0]) 0)) { + + //Entire batch is filtered out. + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { + sel[newSize++] = i; + } + } + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { + sel[newSize++] = i; + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } else { + if (inputColVector.isRepeating) { + + // All must be selected otherwise size would be zero. Repeating property will not change. + if (!nullPos[0]) { + if (!(StringExpr.compare(value, 0, value.length, vector[0], start[0], length[0]) 0)) { + + //Entire batch is filtered out. + batch.size = 0; + } + } else { + batch.size = 0; + } + } else if (batch.selectedInUse) { + int newSize = 0; + for(int j=0; j != n; j++) { + int i = sel[j]; + if (!nullPos[i]) { + if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { + sel[newSize++] = i; + } + } + } + + //Change the selected vector + batch.size = newSize; + } else { + int newSize = 0; + for(int i = 0; i != n; i++) { + if (!nullPos[i]) { + if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { + sel[newSize++] = i; + } + } + } + if (newSize < n) { + batch.size = newSize; + batch.selectedInUse = true; + } + } + } + } + + @Override + public int getOutputColumn() { + return -1; + } + + @Override + public String getOutputType() { + return "boolean"; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public byte[] getValue() { + return value; + } + + public void setValue(byte[] value) { + this.value = value; + } +} diff --git ql/src/gen/vectorization/ExpressionTemplates/ScalarArithmeticColumn.txt ql/src/gen/vectorization/ExpressionTemplates/ScalarArithmeticColumn.txt new file mode 100644 index 0000000..d9efbe7 --- /dev/null +++ ql/src/gen/vectorization/ExpressionTemplates/ScalarArithmeticColumn.txt @@ -0,0 +1,147 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; + +/* + * Because of the templatized nature of the code, either or both + * of these ColumnVector imports may be needed. Listing both of them + * rather than using ....vectorization.*; + */ +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil; + +/** + * Generated from template ScalarArithmeticColumn.txt. + * Implements a vectorized arithmetic operator with a scalar on the left and a + * column vector on the right. The result is output to an output column vector. + */ +public class extends VectorExpression { + + private static final long serialVersionUID = 1L; + + private int colNum; + private value; + private int outputColumn; + + public ( value, int colNum, int outputColumn) { + this.colNum = colNum; + this.value = value; + this.outputColumn = outputColumn; + } + + public () { + } + + @Override + /** + * Method to evaluate scalar-column operation in vectorized fashion. + * + * @batch a package of rows with each column stored in a vector + */ + public void evaluate(VectorizedRowBatch batch) { + + if (childExpressions != null) { + super.evaluateChildren(batch); + } + + inputColVector = () batch.cols[colNum]; + outputColVector = () batch.cols[outputColumn]; + int[] sel = batch.selected; + boolean[] inputIsNull = inputColVector.isNull; + boolean[] outputIsNull = outputColVector.isNull; + outputColVector.noNulls = inputColVector.noNulls; + outputColVector.isRepeating = inputColVector.isRepeating; + int n = batch.size; + [] vector = inputColVector.vector; + [] outputVector = outputColVector.vector; + + // return immediately if batch is empty + if (n == 0) { + return; + } + + if (inputColVector.isRepeating) { + outputVector[0] = value vector[0]; + + // Even if there are no nulls, we always copy over entry 0. Simplifies code. + outputIsNull[0] = inputIsNull[0]; + } else if (inputColVector.noNulls) { + if (batch.selectedInUse) { + for(int j = 0; j != n; j++) { + int i = sel[j]; + outputVector[i] = value vector[i]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = value vector[i]; + } + } + } else { /* there are nulls */ + if (batch.selectedInUse) { + for(int j = 0; j != n; j++) { + int i = sel[j]; + outputVector[i] = value vector[i]; + outputIsNull[i] = inputIsNull[i]; + } + } else { + for(int i = 0; i != n; i++) { + outputVector[i] = value vector[i]; + } + System.arraycopy(inputIsNull, 0, outputIsNull, 0, n); + } + } + + NullUtil.setNullOutputEntriesColScalar(outputColVector, batch.selectedInUse, sel, n); + } + + @Override + public int getOutputColumn() { + return outputColumn; + } + + @Override + public String getOutputType() { + return ""; + } + + public int getColNum() { + return colNum; + } + + public void setColNum(int colNum) { + this.colNum = colNum; + } + + public getValue() { + return value; + } + + public void setValue( value) { + this.value = value; + } + + public void setOutputColumn(int outputColumn) { + this.outputColumn = outputColumn; + } + +} diff --git ql/src/gen/vectorization/TestTemplates/TestClass.txt ql/src/gen/vectorization/TestTemplates/TestClass.txt new file mode 100644 index 0000000..c8de5de --- /dev/null +++ ql/src/gen/vectorization/TestTemplates/TestClass.txt @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; + +import static org.junit.Assert.assertEquals; +import java.util.Random; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.util.VectorizedRowGroupGenUtil; +import org.junit.Test; + + +/** + * + * . + * + */ +public class { + + private static final int BATCH_SIZE = 100; + private static final long SEED = 0xfa57; + + + +} + + diff --git ql/src/gen/vectorization/TestTemplates/TestColumnColumnFilterVectorExpressionEvaluation.txt ql/src/gen/vectorization/TestTemplates/TestColumnColumnFilterVectorExpressionEvaluation.txt new file mode 100644 index 0000000..2bb1aa3 --- /dev/null +++ ql/src/gen/vectorization/TestTemplates/TestColumnColumnFilterVectorExpressionEvaluation.txt @@ -0,0 +1,69 @@ + + @Test + public void () { + + Random rand = new Random(SEED); + + inputColumnVector1 = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + inputColumnVector2 = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(2, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector1; + rowBatch.cols[1] = inputColumnVector2; + + vectorExpression = + new (0, 1); + + vectorExpression.evaluate(rowBatch); + + int selectedIndex = 0; + for(int i = 0; i < BATCH_SIZE; i++) { + //null vector is safe to check, as it is always initialized to match the data vector + if(!inputColumnVector1.isNull[i] && !inputColumnVector2.isNull[i]) { + if(inputColumnVector1.vector[i] inputColumnVector2.vector[i]) { + assertEquals( + "Vector index that passes filter " + + inputColumnVector1.vector[i] + "" + + inputColumnVector2.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } \ No newline at end of file diff --git ql/src/gen/vectorization/TestTemplates/TestColumnColumnOperationVectorExpressionEvaluation.txt ql/src/gen/vectorization/TestTemplates/TestColumnColumnOperationVectorExpressionEvaluation.txt new file mode 100644 index 0000000..4ab3e76 --- /dev/null +++ ql/src/gen/vectorization/TestTemplates/TestColumnColumnOperationVectorExpressionEvaluation.txt @@ -0,0 +1,64 @@ + + @Test + public void () { + + Random rand = new Random(SEED); + + outputColumnVector = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + inputColumnVector1 = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + inputColumnVector2 = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(3, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector1; + rowBatch.cols[1] = inputColumnVector2; + rowBatch.cols[2] = outputColumnVector; + + vectorExpression = + new (0, 1, 2); + + vectorExpression.evaluate(rowBatch); + + assertEquals( + "Output column vector repeating state does not match operand columns", + (!inputColumnVector1.noNulls && inputColumnVector1.isRepeating) + || (!inputColumnVector2.noNulls && inputColumnVector2.isRepeating) + || inputColumnVector1.isRepeating && inputColumnVector2.isRepeating, + outputColumnVector.isRepeating); + + assertEquals( + "Output column vector no nulls state does not match operand columns", + inputColumnVector1.noNulls && inputColumnVector2.noNulls, outputColumnVector.noNulls); + + //if repeating, only the first value matters + if(!outputColumnVector.noNulls && !outputColumnVector.isRepeating) { + for(int i = 0; i < BATCH_SIZE; i++) { + //null vectors are safe to check, as they are always initialized to match the data vector + assertEquals("Output vector doesn't match input vectors' is null state for index", + inputColumnVector1.isNull[i] || inputColumnVector2.isNull[i], + outputColumnVector.isNull[i]); + } + } + } \ No newline at end of file diff --git ql/src/gen/vectorization/TestTemplates/TestColumnScalarFilterVectorExpressionEvaluation.txt ql/src/gen/vectorization/TestTemplates/TestColumnScalarFilterVectorExpressionEvaluation.txt new file mode 100644 index 0000000..af30490 --- /dev/null +++ ql/src/gen/vectorization/TestTemplates/TestColumnScalarFilterVectorExpressionEvaluation.txt @@ -0,0 +1,78 @@ + + @Test + public void () { + + Random rand = new Random(SEED); + + inputColumnVector = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + scalarValue = 0; + do { + scalarValue = rand.next(); + } while(scalarValue == 0); + + vectorExpression = + new (0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if( ) { + assertEquals( + "Vector index that passes filter " + + + "" + + + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } \ No newline at end of file diff --git ql/src/gen/vectorization/TestTemplates/TestColumnScalarOperationVectorExpressionEvaluation.txt ql/src/gen/vectorization/TestTemplates/TestColumnScalarOperationVectorExpressionEvaluation.txt new file mode 100644 index 0000000..e5f3f18 --- /dev/null +++ ql/src/gen/vectorization/TestTemplates/TestColumnScalarOperationVectorExpressionEvaluation.txt @@ -0,0 +1,59 @@ + + @Test + public void () { + + Random rand = new Random(SEED); + + outputColumnVector = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + inputColumnVector = + VectorizedRowGroupGenUtil.generate(, + , BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(2, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + rowBatch.cols[1] = outputColumnVector; + + scalarValue = 0; + do { + scalarValue = rand.next(); + } while(scalarValue == 0); + + vectorExpression = + new (, 1); + + vectorExpression.evaluate(rowBatch); + + assertEquals( + "Output column vector is repeating state does not match operand column", + inputColumnVector.isRepeating, outputColumnVector.isRepeating); + + assertEquals( + "Output column vector no nulls state does not match operand column", + inputColumnVector.noNulls, outputColumnVector.noNulls); + + if(!outputColumnVector.noNulls && !outputColumnVector.isRepeating) { + for(int i = 0; i < BATCH_SIZE; i++) { + //null vectors are safe to check, as they are always initialized to match the data vector + assertEquals("Output vector doesn't match input vector's is null state for index", + inputColumnVector.isNull[i], outputColumnVector.isNull[i]); + } + } + } \ No newline at end of file diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFAvg.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFAvg.txt new file mode 100644 index 0000000..cb94145 --- /dev/null +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFAvg.txt @@ -0,0 +1,474 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; +import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.plan.AggregationDesc; +import org.apache.hadoop.hive.ql.util.JavaDataModel; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.hive.serde2.io.DoubleWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; + +/** + * Generated from template VectorUDAFAvg.txt. + */ +@Description(name = "avg", + value = "_FUNC_(expr) - Returns the average value of expr (vectorized, type: )") +public class extends VectorAggregateExpression { + + private static final long serialVersionUID = 1L; + + /** class for storing the current aggregate value. */ + static class Aggregation implements AggregationBuffer { + + private static final long serialVersionUID = 1L; + + transient private double sum; + transient private long count; + transient private boolean isNull; + + public void sumValue( value) { + if (isNull) { + sum = value; + count = 1; + isNull = false; + } else { + sum += value; + count++; + } + } + + @Override + public int getVariableSize() { + throw new UnsupportedOperationException(); + } + } + + private VectorExpression inputExpression; + transient private Object[] partialResult; + transient private LongWritable resultCount; + transient private DoubleWritable resultSum; + transient private StructObjectInspector soi; + + public (VectorExpression inputExpression) { + this(); + this.inputExpression = inputExpression; + } + + public () { + super(); + partialResult = new Object[2]; + resultCount = new LongWritable(); + resultSum = new DoubleWritable(); + partialResult[0] = resultCount; + partialResult[1] = resultSum; + initPartialResultInspector(); + } + + private void initPartialResultInspector() { + List foi = new ArrayList(); + foi.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector); + foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); + List fname = new ArrayList(); + fname.add("count"); + fname.add("sum"); + soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi); + } + + private Aggregation getCurrentAggregationBuffer( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + int row) { + VectorAggregationBufferRow mySet = aggregationBufferSets[row]; + Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(bufferIndex); + return myagg; + } + + @Override + public void aggregateInputSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + VectorizedRowBatch batch) throws HiveException { + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + inputExpression.evaluate(batch); + + inputVector = ( )batch. + cols[this.inputExpression.getOutputColumn()]; + [] vector = inputVector.vector; + + if (inputVector.noNulls) { + if (inputVector.isRepeating) { + iterateNoNullsRepeatingWithAggregationSelection( + aggregationBufferSets, bufferIndex, + vector[0], batchSize); + } else { + if (batch.selectedInUse) { + iterateNoNullsSelectionWithAggregationSelection( + aggregationBufferSets, bufferIndex, + vector, batch.selected, batchSize); + } else { + iterateNoNullsWithAggregationSelection( + aggregationBufferSets, bufferIndex, + vector, batchSize); + } + } + } else { + if (inputVector.isRepeating) { + if (batch.selectedInUse) { + iterateHasNullsRepeatingSelectionWithAggregationSelection( + aggregationBufferSets, bufferIndex, + vector[0], batchSize, batch.selected, inputVector.isNull); + } else { + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, bufferIndex, + vector[0], batchSize, inputVector.isNull); + } + } else { + if (batch.selectedInUse) { + iterateHasNullsSelectionWithAggregationSelection( + aggregationBufferSets, bufferIndex, + vector, batchSize, batch.selected, inputVector.isNull); + } else { + iterateHasNullsWithAggregationSelection( + aggregationBufferSets, bufferIndex, + vector, batchSize, inputVector.isNull); + } + } + } + } + + private void iterateNoNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + value, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(value); + } + } + + private void iterateNoNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + [] values, + int[] selection, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(values[selection[i]]); + } + } + + private void iterateNoNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + [] values, + int batchSize) { + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(values[i]); + } + } + + private void iterateHasNullsRepeatingSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + value, + int batchSize, + int[] selection, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[selection[i]]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(value); + } + } + + } + + private void iterateHasNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + value, + int batchSize, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(value); + } + } + } + + private void iterateHasNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + [] values, + int batchSize, + int[] selection, + boolean[] isNull) { + + for (int j=0; j < batchSize; ++j) { + int i = selection[j]; + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + j); + myagg.sumValue(values[i]); + } + } + } + + private void iterateHasNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int bufferIndex, + [] values, + int batchSize, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(values[i]); + } + } + } + + + @Override + public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) + throws HiveException { + + inputExpression.evaluate(batch); + + inputVector = + ()batch.cols[this.inputExpression.getOutputColumn()]; + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + Aggregation myagg = (Aggregation)agg; + + [] vector = inputVector.vector; + + if (inputVector.isRepeating) { + if (inputVector.noNulls) { + if (myagg.isNull) { + myagg.isNull = false; + myagg.sum = 0; + myagg.count = 0; + } + myagg.sum += vector[0]*batchSize; + myagg.count += batchSize; + } + return; + } + + if (!batch.selectedInUse && inputVector.noNulls) { + iterateNoSelectionNoNulls(myagg, vector, batchSize); + } + else if (!batch.selectedInUse) { + iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); + } + else if (inputVector.noNulls){ + iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); + } + else { + iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); + } + } + + private void iterateSelectionHasNulls( + Aggregation myagg, + [] vector, + int batchSize, + boolean[] isNull, + int[] selected) { + + for (int j=0; j< batchSize; ++j) { + int i = selected[j]; + if (!isNull[i]) { + value = vector[i]; + if (myagg.isNull) { + myagg.isNull = false; + myagg.sum = 0; + myagg.count = 0; + } + myagg.sum += value; + myagg.count += 1; + } + } + } + + private void iterateSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize, + int[] selected) { + + if (myagg.isNull) { + myagg.isNull = false; + myagg.sum = 0; + myagg.count = 0; + } + + for (int i=0; i< batchSize; ++i) { + value = vector[selected[i]]; + myagg.sum += value; + myagg.count += 1; + } + } + + private void iterateNoSelectionHasNulls( + Aggregation myagg, + [] vector, + int batchSize, + boolean[] isNull) { + + for(int i=0;i value = vector[i]; + if (myagg.isNull) { + myagg.isNull = false; + myagg.sum = 0; + myagg.count = 0; + } + myagg.sum += value; + myagg.count += 1; + } + } + } + + private void iterateNoSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize) { + if (myagg.isNull) { + myagg.isNull = false; + myagg.sum = 0; + myagg.count = 0; + } + + for (int i=0;i value = vector[i]; + myagg.sum += value; + myagg.count += 1; + } + } + + @Override + public AggregationBuffer getNewAggregationBuffer() throws HiveException { + return new Aggregation(); + } + + @Override + public void reset(AggregationBuffer agg) throws HiveException { + Aggregation myAgg = (Aggregation) agg; + myAgg.isNull = true; + } + + @Override + public Object evaluateOutput( + AggregationBuffer agg) throws HiveException { + Aggregation myagg = (Aggregation) agg; + if (myagg.isNull) { + return null; + } + else { + assert(0 < myagg.count); + resultCount.set (myagg.count); + resultSum.set (myagg.sum); + return partialResult; + } + } + + @Override + public ObjectInspector getOutputObjectInspector() { + return soi; + } + + @Override + public int getAggregationBufferFixedSize() { + JavaDataModel model = JavaDataModel.get(); + return JavaDataModel.alignUp( + model.object() + + model.primitive2() * 2, + model.memoryAlign()); + } + + @Override + public void init(AggregationDesc desc) throws HiveException { + // No-op + } + + public VectorExpression getInputExpression() { + return inputExpression; + } + + public void setInputExpression(VectorExpression inputExpression) { + this.inputExpression = inputExpression; + } +} + diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt new file mode 100644 index 0000000..2b0364c --- /dev/null +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt @@ -0,0 +1,441 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; + +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter; +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriterFactory; +import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.plan.AggregationDesc; +import org.apache.hadoop.hive.ql.util.JavaDataModel; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; + +/** +* . Vectorized implementation for MIN/MAX aggregates. +*/ +@Description(name = "", + value = "") +public class extends VectorAggregateExpression { + + private static final long serialVersionUID = 1L; + + /** + * class for storing the current aggregate value. + */ + static private final class Aggregation implements AggregationBuffer { + + private static final long serialVersionUID = 1L; + + transient private value; + transient private boolean isNull; + + public void checkValue( value) { + if (isNull) { + isNull = false; + this.value = value; + } else if (value this.value) { + this.value = value; + } + } + + @Override + public int getVariableSize() { + throw new UnsupportedOperationException(); + } + } + + private VectorExpression inputExpression; + private transient VectorExpressionWriter resultWriter; + + public (VectorExpression inputExpression) { + this(); + this.inputExpression = inputExpression; + } + + public () { + super(); + } + + @Override + public void init(AggregationDesc desc) throws HiveException { + resultWriter = VectorExpressionWriterFactory.genVectorExpressionWritable( + desc.getParameters().get(0)); + } + + private Aggregation getCurrentAggregationBuffer( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + int row) { + VectorAggregationBufferRow mySet = aggregationBufferSets[row]; + Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregrateIndex); + return myagg; + } + + @Override + public void aggregateInputSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + VectorizedRowBatch batch) throws HiveException { + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + inputExpression.evaluate(batch); + + inputVector = ()batch. + cols[this.inputExpression.getOutputColumn()]; + [] vector = inputVector.vector; + + if (inputVector.noNulls) { + if (inputVector.isRepeating) { + iterateNoNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector[0], batchSize); + } else { + if (batch.selectedInUse) { + iterateNoNullsSelectionWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector, batch.selected, batchSize); + } else { + iterateNoNullsWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector, batchSize); + } + } + } else { + if (inputVector.isRepeating) { + if (batch.selectedInUse) { + iterateHasNullsRepeatingSelectionWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector[0], batchSize, batch.selected, inputVector.isNull); + } else { + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector[0], batchSize, inputVector.isNull); + } + } else { + if (batch.selectedInUse) { + iterateHasNullsSelectionWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector, batchSize, batch.selected, inputVector.isNull); + } else { + iterateHasNullsWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector, batchSize, inputVector.isNull); + } + } + } + } + + private void iterateNoNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + value, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(value); + } + } + + private void iterateNoNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + [] values, + int[] selection, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(values[selection[i]]); + } + } + + private void iterateNoNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + [] values, + int batchSize) { + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(values[i]); + } + } + + private void iterateHasNullsRepeatingSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + value, + int batchSize, + int[] selection, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[selection[i]]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(value); + } + } + + } + + private void iterateHasNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + value, + int batchSize, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(value); + } + } + } + + private void iterateHasNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + [] values, + int batchSize, + int[] selection, + boolean[] isNull) { + + for (int j=0; j < batchSize; ++j) { + int i = selection[j]; + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + j); + myagg.checkValue(values[i]); + } + } + } + + private void iterateHasNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + [] values, + int batchSize, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(values[i]); + } + } + } + + @Override + public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) + throws HiveException { + + inputExpression.evaluate(batch); + + inputVector = ()batch. + cols[this.inputExpression.getOutputColumn()]; + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + Aggregation myagg = (Aggregation)agg; + + [] vector = inputVector.vector; + + if (inputVector.isRepeating) { + if (inputVector.noNulls && + (myagg.isNull || (vector[0] myagg.value))) { + myagg.isNull = false; + myagg.value = vector[0]; + } + return; + } + + if (!batch.selectedInUse && inputVector.noNulls) { + iterateNoSelectionNoNulls(myagg, vector, batchSize); + } + else if (!batch.selectedInUse) { + iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); + } + else if (inputVector.noNulls){ + iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); + } + else { + iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); + } + } + + private void iterateSelectionHasNulls( + Aggregation myagg, + [] vector, + int batchSize, + boolean[] isNull, + int[] selected) { + + for (int j=0; j< batchSize; ++j) { + int i = selected[j]; + if (!isNull[i]) { + value = vector[i]; + if (myagg.isNull) { + myagg.isNull = false; + myagg.value = value; + } + else if (value myagg.value) { + myagg.value = value; + } + } + } + } + + private void iterateSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize, + int[] selected) { + + if (myagg.isNull) { + myagg.value = vector[selected[0]]; + myagg.isNull = false; + } + + for (int i=0; i< batchSize; ++i) { + value = vector[selected[i]]; + if (value myagg.value) { + myagg.value = value; + } + } + } + + private void iterateNoSelectionHasNulls( + Aggregation myagg, + [] vector, + int batchSize, + boolean[] isNull) { + + for(int i=0;i value = vector[i]; + if (myagg.isNull) { + myagg.value = value; + myagg.isNull = false; + } + else if (value myagg.value) { + myagg.value = value; + } + } + } + } + + private void iterateNoSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize) { + if (myagg.isNull) { + myagg.value = vector[0]; + myagg.isNull = false; + } + + for (int i=0;i value = vector[i]; + if (value myagg.value) { + myagg.value = value; + } + } + } + + @Override + public AggregationBuffer getNewAggregationBuffer() throws HiveException { + return new Aggregation(); + } + + @Override + public void reset(AggregationBuffer agg) throws HiveException { + Aggregation myAgg = (Aggregation) agg; + myAgg.isNull = true; + } + + @Override + public Object evaluateOutput( + AggregationBuffer agg) throws HiveException { + Aggregation myagg = (Aggregation) agg; + if (myagg.isNull) { + return null; + } + else { + return resultWriter.writeValue(myagg.value); + } + } + + @Override + public ObjectInspector getOutputObjectInspector() { + return resultWriter.getObjectInspector(); + } + + @Override + public int getAggregationBufferFixedSize() { + JavaDataModel model = JavaDataModel.get(); + return JavaDataModel.alignUp( + model.object() + + model.primitive2(), + model.memoryAlign()); + } + + public VectorExpression getInputExpression() { + return inputExpression; + } + + public void setInputExpression(VectorExpression inputExpression) { + this.inputExpression = inputExpression; + } +} + diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxString.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxString.txt new file mode 100644 index 0000000..36f483e --- /dev/null +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxString.txt @@ -0,0 +1,400 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; + +import java.util.ArrayList; +import java.util.Arrays; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; +import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; +import org.apache.hadoop.hive.ql.plan.AggregationDesc; +import org.apache.hadoop.hive.ql.util.JavaDataModel; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.io.Text; + +/** +* . Vectorized implementation for MIN/MAX aggregates. +*/ +@Description(name = "", + value = "") +public class extends VectorAggregateExpression { + + private static final long serialVersionUID = 1L; + + /** + * class for storing the current aggregate value. + */ + static private final class Aggregation implements AggregationBuffer { + + private static final long serialVersionUID = 1L; + + transient private final static int MIN_BUFFER_SIZE = 16; + transient private byte[] bytes = new byte[MIN_BUFFER_SIZE]; + transient private int length; + transient private boolean isNull; + + public void checkValue(byte[] bytes, int start, int length) { + if (isNull) { + isNull = false; + assign(bytes, start, length); + } else if (StringExpr.compare( + bytes, start, length, + this.bytes, 0, this.length) 0) { + assign(bytes, start, length); + } + } + + public void assign(byte[] bytes, int start, int length) { + // Avoid new allocation if possible + if (this.bytes.length < length) { + this.bytes = new byte[length]; + } + System.arraycopy(bytes, start, this.bytes, 0, length); + this.length = length; + } + @Override + public int getVariableSize() { + JavaDataModel model = JavaDataModel.get(); + return model.lengthForByteArrayOfSize(bytes.length); + } + } + + private VectorExpression inputExpression; + transient private Text result; + + public (VectorExpression inputExpression) { + this(); + this.inputExpression = inputExpression; + } + + public () { + super(); + result = new Text(); + } + + private Aggregation getCurrentAggregationBuffer( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + int row) { + VectorAggregationBufferRow mySet = aggregationBufferSets[row]; + Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregrateIndex); + return myagg; + } + +@Override + public void aggregateInputSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + VectorizedRowBatch batch) throws HiveException { + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + inputExpression.evaluate(batch); + + BytesColumnVector inputColumn = (BytesColumnVector)batch. + cols[this.inputExpression.getOutputColumn()]; + + if (inputColumn.noNulls) { + if (inputColumn.isRepeating) { + iterateNoNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColumn, batchSize); + } else { + if (batch.selectedInUse) { + iterateNoNullsSelectionWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColumn, batch.selected, batchSize); + } else { + iterateNoNullsWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColumn, batchSize); + } + } + } else { + if (inputColumn.isRepeating) { + // All nulls, no-op for min/max + } else { + if (batch.selectedInUse) { + iterateHasNullsSelectionWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColumn, batchSize, batch.selected); + } else { + iterateHasNullsWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColumn, batchSize); + } + } + } + } + + private void iterateNoNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + BytesColumnVector inputColumn, + int batchSize) { + + byte[] bytes = inputColumn.vector[0]; + int start = inputColumn.start[0]; + int length = inputColumn.length[0]; + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(bytes, start, length); + } + } + + private void iterateNoNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + BytesColumnVector inputColumn, + int[] selection, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + int row = selection[i]; + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(inputColumn.vector[row], + inputColumn.start[row], + inputColumn.length[row]); + } + } + + private void iterateNoNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + BytesColumnVector inputColumn, + int batchSize) { + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(inputColumn.vector[i], + inputColumn.start[i], + inputColumn.length[i]); + } + } + + private void iterateHasNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + BytesColumnVector inputColumn, + int batchSize, + int[] selection) { + + for (int i=0; i < batchSize; ++i) { + int row = selection[i]; + if (!inputColumn.isNull[row]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(inputColumn.vector[row], + inputColumn.start[row], + inputColumn.length[row]); + } + } + } + + private void iterateHasNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + BytesColumnVector inputColumn, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + if (!inputColumn.isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(inputColumn.vector[i], + inputColumn.start[i], + inputColumn.length[i]); + } + } + } + + @Override + public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) + throws HiveException { + + inputExpression.evaluate(batch); + + BytesColumnVector inputColumn = (BytesColumnVector)batch. + cols[this.inputExpression.getOutputColumn()]; + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + Aggregation myagg = (Aggregation)agg; + + if (inputColumn.isRepeating) { + if (inputColumn.noNulls) { + myagg.checkValue(inputColumn.vector[0], + inputColumn.start[0], + inputColumn.length[0]); + } + return; + } + + if (!batch.selectedInUse && inputColumn.noNulls) { + iterateNoSelectionNoNulls(myagg, inputColumn, batchSize); + } + else if (!batch.selectedInUse) { + iterateNoSelectionHasNulls(myagg, inputColumn, batchSize); + } + else if (inputColumn.noNulls){ + iterateSelectionNoNulls(myagg, inputColumn, batchSize, batch.selected); + } + else { + iterateSelectionHasNulls(myagg, inputColumn, batchSize, batch.selected); + } + } + + private void iterateSelectionHasNulls( + Aggregation myagg, + BytesColumnVector inputColumn, + int batchSize, + int[] selected) { + + for (int j=0; j< batchSize; ++j) { + int i = selected[j]; + if (!inputColumn.isNull[i]) { + myagg.checkValue(inputColumn.vector[i], + inputColumn.start[i], + inputColumn.length[i]); + } + } + } + + private void iterateSelectionNoNulls( + Aggregation myagg, + BytesColumnVector inputColumn, + int batchSize, + int[] selected) { + + for (int i=0; i< batchSize; ++i) { + myagg.checkValue(inputColumn.vector[i], + inputColumn.start[i], + inputColumn.length[i]); + } + } + + private void iterateNoSelectionHasNulls( + Aggregation myagg, + BytesColumnVector inputColumn, + int batchSize) { + + for (int i=0; i< batchSize; ++i) { + if (!inputColumn.isNull[i]) { + myagg.checkValue(inputColumn.vector[i], + inputColumn.start[i], + inputColumn.length[i]); + } + } + } + + private void iterateNoSelectionNoNulls( + Aggregation myagg, + BytesColumnVector inputColumn, + int batchSize) { + for (int i=0; i< batchSize; ++i) { + myagg.checkValue(inputColumn.vector[i], + inputColumn.start[i], + inputColumn.length[i]); + } + } + + @Override + public AggregationBuffer getNewAggregationBuffer() throws HiveException { + return new Aggregation(); + } + + @Override + public void reset(AggregationBuffer agg) throws HiveException { + Aggregation myAgg = (Aggregation) agg; + myAgg.isNull = true; + } + + @Override + public Object evaluateOutput( + AggregationBuffer agg) throws HiveException { + Aggregation myagg = (Aggregation) agg; + if (myagg.isNull) { + return null; + } + else { + result.set(myagg.bytes, 0, myagg.length); + return result; + } + } + + @Override + public ObjectInspector getOutputObjectInspector() { + return PrimitiveObjectInspectorFactory.writableStringObjectInspector; + } + + @Override + public int getAggregationBufferFixedSize() { + JavaDataModel model = JavaDataModel.get(); + return JavaDataModel.alignUp( + model.object() + + model.ref()+ + model.primitive1()*2, + model.memoryAlign()); + } + + @Override + public boolean hasVariableSize() { + return true; + } + + @Override + public void init(AggregationDesc desc) throws HiveException { + // No-op + } + + public VectorExpression getInputExpression() { + return inputExpression; + } + + public void setInputExpression(VectorExpression inputExpression) { + this.inputExpression = inputExpression; + } +} + diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFSum.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFSum.txt new file mode 100644 index 0000000..3573997 --- /dev/null +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFSum.txt @@ -0,0 +1,436 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; + +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; +import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.plan.AggregationDesc; +import org.apache.hadoop.hive.ql.util.JavaDataModel; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.hive.serde2.io.DoubleWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; + +/** +* . Vectorized implementation for SUM aggregates. +*/ +@Description(name = "sum", + value = "_FUNC_(expr) - Returns the sum value of expr (vectorized, type: )") +public class extends VectorAggregateExpression { + + private static final long serialVersionUID = 1L; + + /** + * class for storing the current aggregate value. + */ + private static final class Aggregation implements AggregationBuffer { + + private static final long serialVersionUID = 1L; + + transient private sum; + transient private boolean isNull; + + public void sumValue( value) { + if (isNull) { + sum = value; + isNull = false; + } else { + sum += value; + } + } + + @Override + public int getVariableSize() { + throw new UnsupportedOperationException(); + } + } + + private VectorExpression inputExpression; + transient private final result; + + public (VectorExpression inputExpression) { + this(); + this.inputExpression = inputExpression; + } + + public () { + super(); + result = new (); + } + + private Aggregation getCurrentAggregationBuffer( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + int row) { + VectorAggregationBufferRow mySet = aggregationBufferSets[row]; + Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregateIndex); + return myagg; + } + + @Override + public void aggregateInputSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + VectorizedRowBatch batch) throws HiveException { + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + inputExpression.evaluate(batch); + + inputVector = ()batch. + cols[this.inputExpression.getOutputColumn()]; + [] vector = inputVector.vector; + + if (inputVector.noNulls) { + if (inputVector.isRepeating) { + iterateNoNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregateIndex, + vector[0], batchSize); + } else { + if (batch.selectedInUse) { + iterateNoNullsSelectionWithAggregationSelection( + aggregationBufferSets, aggregateIndex, + vector, batch.selected, batchSize); + } else { + iterateNoNullsWithAggregationSelection( + aggregationBufferSets, aggregateIndex, + vector, batchSize); + } + } + } else { + if (inputVector.isRepeating) { + if (batch.selectedInUse) { + iterateHasNullsRepeatingSelectionWithAggregationSelection( + aggregationBufferSets, aggregateIndex, + vector[0], batchSize, batch.selected, inputVector.isNull); + } else { + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregateIndex, + vector[0], batchSize, inputVector.isNull); + } + } else { + if (batch.selectedInUse) { + iterateHasNullsSelectionWithAggregationSelection( + aggregationBufferSets, aggregateIndex, + vector, batchSize, batch.selected, inputVector.isNull); + } else { + iterateHasNullsWithAggregationSelection( + aggregationBufferSets, aggregateIndex, + vector, batchSize, inputVector.isNull); + } + } + } + } + + private void iterateNoNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + value, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(value); + } + } + + private void iterateNoNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] values, + int[] selection, + int batchSize) { + + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(values[selection[i]]); + } + } + + private void iterateNoNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] values, + int batchSize) { + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(values[i]); + } + } + + private void iterateHasNullsRepeatingSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + value, + int batchSize, + int[] selection, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[selection[i]]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(value); + } + } + + } + + private void iterateHasNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + value, + int batchSize, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(value); + } + } + } + + private void iterateHasNullsSelectionWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] values, + int batchSize, + int[] selection, + boolean[] isNull) { + + for (int j=0; j < batchSize; ++j) { + int i = selection[j]; + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + j); + myagg.sumValue(values[i]); + } + } + } + + private void iterateHasNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] values, + int batchSize, + boolean[] isNull) { + + for (int i=0; i < batchSize; ++i) { + if (!isNull[i]) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(values[i]); + } + } + } + + + @Override + public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) + throws HiveException { + + inputExpression.evaluate(batch); + + inputVector = ()batch. + cols[this.inputExpression.getOutputColumn()]; + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + Aggregation myagg = (Aggregation)agg; + + [] vector = inputVector.vector; + + if (inputVector.isRepeating) { + if (inputVector.noNulls) { + if (myagg.isNull) { + myagg.isNull = false; + myagg.sum = 0; + } + myagg.sum += vector[0]*batchSize; + } + return; + } + + if (!batch.selectedInUse && inputVector.noNulls) { + iterateNoSelectionNoNulls(myagg, vector, batchSize); + } + else if (!batch.selectedInUse) { + iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); + } + else if (inputVector.noNulls){ + iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); + } + else { + iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); + } + } + + private void iterateSelectionHasNulls( + Aggregation myagg, + [] vector, + int batchSize, + boolean[] isNull, + int[] selected) { + + for (int j=0; j< batchSize; ++j) { + int i = selected[j]; + if (!isNull[i]) { + value = vector[i]; + if (myagg.isNull) { + myagg.isNull = false; + myagg.sum = 0; + } + myagg.sum += value; + } + } + } + + private void iterateSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize, + int[] selected) { + + if (myagg.isNull) { + myagg.sum = 0; + myagg.isNull = false; + } + + for (int i=0; i< batchSize; ++i) { + value = vector[selected[i]]; + myagg.sum += value; + } + } + + private void iterateNoSelectionHasNulls( + Aggregation myagg, + [] vector, + int batchSize, + boolean[] isNull) { + + for(int i=0;i value = vector[i]; + if (myagg.isNull) { + myagg.sum = 0; + myagg.isNull = false; + } + myagg.sum += value; + } + } + } + + private void iterateNoSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize) { + if (myagg.isNull) { + myagg.sum = 0; + myagg.isNull = false; + } + + for (int i=0;i value = vector[i]; + myagg.sum += value; + } + } + + @Override + public AggregationBuffer getNewAggregationBuffer() throws HiveException { + return new Aggregation(); + } + + @Override + public void reset(AggregationBuffer agg) throws HiveException { + Aggregation myAgg = (Aggregation) agg; + myAgg.isNull = true; + } + + @Override + public Object evaluateOutput(AggregationBuffer agg) throws HiveException { + Aggregation myagg = (Aggregation) agg; + if (myagg.isNull) { + return null; + } + else { + result.set(myagg.sum); + return result; + } + } + + @Override + public ObjectInspector getOutputObjectInspector() { + return ; + } + + @Override + public int getAggregationBufferFixedSize() { + JavaDataModel model = JavaDataModel.get(); + return JavaDataModel.alignUp( + model.object(), + model.memoryAlign()); + } + + @Override + public void init(AggregationDesc desc) throws HiveException { + // No-op + } + + public VectorExpression getInputExpression() { + return inputExpression; + } + + public void setInputExpression(VectorExpression inputExpression) { + this.inputExpression = inputExpression; + } +} + diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFVar.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFVar.txt new file mode 100644 index 0000000..7c0e58f --- /dev/null +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFVar.txt @@ -0,0 +1,520 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; +import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; +import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.plan.AggregationDesc; +import org.apache.hadoop.hive.ql.util.JavaDataModel; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.hive.serde2.io.DoubleWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; + +/** +* . Vectorized implementation for VARIANCE aggregates. +*/ +@Description(name = "", + value = "") +public class extends VectorAggregateExpression { + + private static final long serialVersionUID = 1L; + + /** + /* class for storing the current aggregate value. + */ + private static final class Aggregation implements AggregationBuffer { + + private static final long serialVersionUID = 1L; + + transient private double sum; + transient private long count; + transient private double variance; + transient private boolean isNull; + + public void init() { + isNull = false; + sum = 0; + count = 0; + variance = 0; + } + + @Override + public int getVariableSize() { + throw new UnsupportedOperationException(); + } + } + + private VectorExpression inputExpression; + transient private LongWritable resultCount; + transient private DoubleWritable resultSum; + transient private DoubleWritable resultVariance; + transient private Object[] partialResult; + + transient private ObjectInspector soi; + + + public (VectorExpression inputExpression) { + this(); + this.inputExpression = inputExpression; + } + + public () { + super(); + partialResult = new Object[3]; + resultCount = new LongWritable(); + resultSum = new DoubleWritable(); + resultVariance = new DoubleWritable(); + partialResult[0] = resultCount; + partialResult[1] = resultSum; + partialResult[2] = resultVariance; + initPartialResultInspector(); + } + + private void initPartialResultInspector() { + List foi = new ArrayList(); + foi.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector); + foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); + foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); + + List fname = new ArrayList(); + fname.add("count"); + fname.add("sum"); + fname.add("variance"); + + soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi); + } + + private Aggregation getCurrentAggregationBuffer( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + int row) { + VectorAggregationBufferRow mySet = aggregationBufferSets[row]; + Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregateIndex); + return myagg; + } + + + @Override + public void aggregateInputSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + VectorizedRowBatch batch) throws HiveException { + + inputExpression.evaluate(batch); + + inputVector = ()batch. + cols[this.inputExpression.getOutputColumn()]; + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + [] vector = inputVector.vector; + + if (inputVector.isRepeating) { + if (inputVector.noNulls || !inputVector.isNull[0]) { + iterateRepeatingNoNullsWithAggregationSelection( + aggregationBufferSets, aggregateIndex, vector[0], batchSize); + } + } + else if (!batch.selectedInUse && inputVector.noNulls) { + iterateNoSelectionNoNullsWithAggregationSelection( + aggregationBufferSets, aggregateIndex, vector, batchSize); + } + else if (!batch.selectedInUse) { + iterateNoSelectionHasNullsWithAggregationSelection( + aggregationBufferSets, aggregateIndex, vector, batchSize, inputVector.isNull); + } + else if (inputVector.noNulls){ + iterateSelectionNoNullsWithAggregationSelection( + aggregationBufferSets, aggregateIndex, vector, batchSize, batch.selected); + } + else { + iterateSelectionHasNullsWithAggregationSelection( + aggregationBufferSets, aggregateIndex, vector, batchSize, + inputVector.isNull, batch.selected); + } + + } + + private void iterateRepeatingNoNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + double value, + int batchSize) { + + for (int i=0; i 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + } + + private void iterateSelectionHasNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] vector, + int batchSize, + boolean[] isNull, + int[] selected) { + + for (int j=0; j< batchSize; ++j) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + j); + int i = selected[j]; + if (!isNull[i]) { + double value = vector[i]; + if (myagg.isNull) { + myagg.init (); + } + myagg.sum += value; + myagg.count += 1; + if(myagg.count > 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + } + } + + private void iterateSelectionNoNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] vector, + int batchSize, + int[] selected) { + + for (int i=0; i< batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + double value = vector[selected[i]]; + if (myagg.isNull) { + myagg.init (); + } + myagg.sum += value; + myagg.count += 1; + if(myagg.count > 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + } + + private void iterateNoSelectionHasNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] vector, + int batchSize, + boolean[] isNull) { + + for(int i=0;i 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + } + } + + private void iterateNoSelectionNoNullsWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregateIndex, + [] vector, + int batchSize) { + + for (int i=0; i 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + } + + @Override + public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) + throws HiveException { + + inputExpression.evaluate(batch); + + inputVector = ()batch. + cols[this.inputExpression.getOutputColumn()]; + + int batchSize = batch.size; + + if (batchSize == 0) { + return; + } + + Aggregation myagg = (Aggregation)agg; + + [] vector = inputVector.vector; + + if (inputVector.isRepeating) { + if (inputVector.noNulls) { + iterateRepeatingNoNulls(myagg, vector[0], batchSize); + } + } + else if (!batch.selectedInUse && inputVector.noNulls) { + iterateNoSelectionNoNulls(myagg, vector, batchSize); + } + else if (!batch.selectedInUse) { + iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); + } + else if (inputVector.noNulls){ + iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); + } + else { + iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); + } + } + + private void iterateRepeatingNoNulls( + Aggregation myagg, + double value, + int batchSize) { + + if (myagg.isNull) { + myagg.init (); + } + + // TODO: conjure a formula w/o iterating + // + + myagg.sum += value; + myagg.count += 1; + if(myagg.count > 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + + // We pulled out i=0 so we can remove the count > 1 check in the loop + for (int i=1; i[] vector, + int batchSize, + boolean[] isNull, + int[] selected) { + + for (int j=0; j< batchSize; ++j) { + int i = selected[j]; + if (!isNull[i]) { + double value = vector[i]; + if (myagg.isNull) { + myagg.init (); + } + myagg.sum += value; + myagg.count += 1; + if(myagg.count > 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + } + } + + private void iterateSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize, + int[] selected) { + + if (myagg.isNull) { + myagg.init (); + } + + double value = vector[selected[0]]; + myagg.sum += value; + myagg.count += 1; + if(myagg.count > 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + + // i=0 was pulled out to remove the count > 1 check in the loop + // + for (int i=1; i< batchSize; ++i) { + value = vector[selected[i]]; + myagg.sum += value; + myagg.count += 1; + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + + private void iterateNoSelectionHasNulls( + Aggregation myagg, + [] vector, + int batchSize, + boolean[] isNull) { + + for(int i=0;i 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + } + } + } + + private void iterateNoSelectionNoNulls( + Aggregation myagg, + [] vector, + int batchSize) { + + if (myagg.isNull) { + myagg.init (); + } + + double value = vector[0]; + myagg.sum += value; + myagg.count += 1; + + if(myagg.count > 1) { + double t = myagg.count*value - myagg.sum; + myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); + } + + // i=0 was pulled out to remove count > 1 check + for (int i=1; i"}, + {"ColumnCompareScalar", "Greater", "double", "double", ">"}, + {"ColumnCompareScalar", "GreaterEqual", "long", "double", ">="}, + {"ColumnCompareScalar", "GreaterEqual", "double", "double", ">="}, + + {"FilterColumnCompareScalar", "Equal", "long", "double", "=="}, + {"FilterColumnCompareScalar", "Equal", "double", "double", "=="}, + {"FilterColumnCompareScalar", "NotEqual", "long", "double", "!="}, + {"FilterColumnCompareScalar", "NotEqual", "double", "double", "!="}, + {"FilterColumnCompareScalar", "Less", "long", "double", "<"}, + {"FilterColumnCompareScalar", "Less", "double", "double", "<"}, + {"FilterColumnCompareScalar", "LessEqual", "long", "double", "<="}, + {"FilterColumnCompareScalar", "LessEqual", "double", "double", "<="}, + {"FilterColumnCompareScalar", "Greater", "long", "double", ">"}, + {"FilterColumnCompareScalar", "Greater", "double", "double", ">"}, + {"FilterColumnCompareScalar", "GreaterEqual", "long", "double", ">="}, + {"FilterColumnCompareScalar", "GreaterEqual", "double", "double", ">="}, + + {"FilterColumnCompareScalar", "Equal", "long", "long", "=="}, + {"FilterColumnCompareScalar", "Equal", "double", "long", "=="}, + {"FilterColumnCompareScalar", "NotEqual", "long", "long", "!="}, + {"FilterColumnCompareScalar", "NotEqual", "double", "long", "!="}, + {"FilterColumnCompareScalar", "Less", "long", "long", "<"}, + {"FilterColumnCompareScalar", "Less", "double", "long", "<"}, + {"FilterColumnCompareScalar", "LessEqual", "long", "long", "<="}, + {"FilterColumnCompareScalar", "LessEqual", "double", "long", "<="}, + {"FilterColumnCompareScalar", "Greater", "long", "long", ">"}, + {"FilterColumnCompareScalar", "Greater", "double", "long", ">"}, + {"FilterColumnCompareScalar", "GreaterEqual", "long", "long", ">="}, + {"FilterColumnCompareScalar", "GreaterEqual", "double", "long", ">="}, + + {"FilterScalarCompareColumn", "Equal", "long", "double", "=="}, + {"FilterScalarCompareColumn", "Equal", "double", "double", "=="}, + {"FilterScalarCompareColumn", "NotEqual", "long", "double", "!="}, + {"FilterScalarCompareColumn", "NotEqual", "double", "double", "!="}, + {"FilterScalarCompareColumn", "Less", "long", "double", "<"}, + {"FilterScalarCompareColumn", "Less", "double", "double", "<"}, + {"FilterScalarCompareColumn", "LessEqual", "long", "double", "<="}, + {"FilterScalarCompareColumn", "LessEqual", "double", "double", "<="}, + {"FilterScalarCompareColumn", "Greater", "long", "double", ">"}, + {"FilterScalarCompareColumn", "Greater", "double", "double", ">"}, + {"FilterScalarCompareColumn", "GreaterEqual", "long", "double", ">="}, + {"FilterScalarCompareColumn", "GreaterEqual", "double", "double", ">="}, + + {"FilterScalarCompareColumn", "Equal", "long", "long", "=="}, + {"FilterScalarCompareColumn", "Equal", "double", "long", "=="}, + {"FilterScalarCompareColumn", "NotEqual", "long", "long", "!="}, + {"FilterScalarCompareColumn", "NotEqual", "double", "long", "!="}, + {"FilterScalarCompareColumn", "Less", "long", "long", "<"}, + {"FilterScalarCompareColumn", "Less", "double", "long", "<"}, + {"FilterScalarCompareColumn", "LessEqual", "long", "long", "<="}, + {"FilterScalarCompareColumn", "LessEqual", "double", "long", "<="}, + {"FilterScalarCompareColumn", "Greater", "long", "long", ">"}, + {"FilterScalarCompareColumn", "Greater", "double", "long", ">"}, + {"FilterScalarCompareColumn", "GreaterEqual", "long", "long", ">="}, + {"FilterScalarCompareColumn", "GreaterEqual", "double", "long", ">="}, + + {"FilterStringColumnCompareScalar", "Equal", "=="}, + {"FilterStringColumnCompareScalar", "NotEqual", "!="}, + {"FilterStringColumnCompareScalar", "Less", "<"}, + {"FilterStringColumnCompareScalar", "LessEqual", "<="}, + {"FilterStringColumnCompareScalar", "Greater", ">"}, + {"FilterStringColumnCompareScalar", "GreaterEqual", ">="}, + + {"FilterStringScalarCompareColumn", "Equal", "=="}, + {"FilterStringScalarCompareColumn", "NotEqual", "!="}, + {"FilterStringScalarCompareColumn", "Less", "<"}, + {"FilterStringScalarCompareColumn", "LessEqual", "<="}, + {"FilterStringScalarCompareColumn", "Greater", ">"}, + {"FilterStringScalarCompareColumn", "GreaterEqual", ">="}, + + {"FilterStringColumnCompareColumn", "Equal", "=="}, + {"FilterStringColumnCompareColumn", "NotEqual", "!="}, + {"FilterStringColumnCompareColumn", "Less", "<"}, + {"FilterStringColumnCompareColumn", "LessEqual", "<="}, + {"FilterStringColumnCompareColumn", "Greater", ">"}, + {"FilterStringColumnCompareColumn", "GreaterEqual", ">="}, + + {"FilterColumnCompareColumn", "Equal", "long", "double", "=="}, + {"FilterColumnCompareColumn", "Equal", "double", "double", "=="}, + {"FilterColumnCompareColumn", "NotEqual", "long", "double", "!="}, + {"FilterColumnCompareColumn", "NotEqual", "double", "double", "!="}, + {"FilterColumnCompareColumn", "Less", "long", "double", "<"}, + {"FilterColumnCompareColumn", "Less", "double", "double", "<"}, + {"FilterColumnCompareColumn", "LessEqual", "long", "double", "<="}, + {"FilterColumnCompareColumn", "LessEqual", "double", "double", "<="}, + {"FilterColumnCompareColumn", "Greater", "long", "double", ">"}, + {"FilterColumnCompareColumn", "Greater", "double", "double", ">"}, + {"FilterColumnCompareColumn", "GreaterEqual", "long", "double", ">="}, + {"FilterColumnCompareColumn", "GreaterEqual", "double", "double", ">="}, + + {"FilterColumnCompareColumn", "Equal", "long", "long", "=="}, + {"FilterColumnCompareColumn", "Equal", "double", "long", "=="}, + {"FilterColumnCompareColumn", "NotEqual", "long", "long", "!="}, + {"FilterColumnCompareColumn", "NotEqual", "double", "long", "!="}, + {"FilterColumnCompareColumn", "Less", "long", "long", "<"}, + {"FilterColumnCompareColumn", "Less", "double", "long", "<"}, + {"FilterColumnCompareColumn", "LessEqual", "long", "long", "<="}, + {"FilterColumnCompareColumn", "LessEqual", "double", "long", "<="}, + {"FilterColumnCompareColumn", "Greater", "long", "long", ">"}, + {"FilterColumnCompareColumn", "Greater", "double", "long", ">"}, + {"FilterColumnCompareColumn", "GreaterEqual", "long", "long", ">="}, + {"FilterColumnCompareColumn", "GreaterEqual", "double", "long", ">="}, + + {"ColumnUnaryMinus", "long"}, + {"ColumnUnaryMinus", "double"}, + + // template, , , , , + {"VectorUDAFMinMax", "VectorUDAFMinLong", "long", "<", "min", + "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: long)"}, + {"VectorUDAFMinMax", "VectorUDAFMinDouble", "double", "<", "min", + "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: double)"}, + {"VectorUDAFMinMax", "VectorUDAFMaxLong", "long", ">", "max", + "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: long)"}, + {"VectorUDAFMinMax", "VectorUDAFMaxDouble", "double", ">", "max", + "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: double)"}, + + {"VectorUDAFMinMaxString", "VectorUDAFMinString", "<", "min", + "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: string)"}, + {"VectorUDAFMinMaxString", "VectorUDAFMaxString", ">", "max", + "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: string)"}, + + //template, , + {"VectorUDAFSum", "VectorUDAFSumLong", "long"}, + {"VectorUDAFSum", "VectorUDAFSumDouble", "double"}, + {"VectorUDAFAvg", "VectorUDAFAvgLong", "long"}, + {"VectorUDAFAvg", "VectorUDAFAvgDouble", "double"}, + + // template, , , , , + // + {"VectorUDAFVar", "VectorUDAFVarPopLong", "long", "myagg.variance / myagg.count", + "variance, var_pop", + "_FUNC_(x) - Returns the variance of a set of numbers (vectorized, long)"}, + {"VectorUDAFVar", "VectorUDAFVarPopDouble", "double", "myagg.variance / myagg.count", + "variance, var_pop", + "_FUNC_(x) - Returns the variance of a set of numbers (vectorized, double)"}, + {"VectorUDAFVar", "VectorUDAFVarSampLong", "long", "myagg.variance / (myagg.count-1.0)", + "var_samp", + "_FUNC_(x) - Returns the sample variance of a set of numbers (vectorized, long)"}, + {"VectorUDAFVar", "VectorUDAFVarSampDouble", "double", "myagg.variance / (myagg.count-1.0)", + "var_samp", + "_FUNC_(x) - Returns the sample variance of a set of numbers (vectorized, double)"}, + {"VectorUDAFVar", "VectorUDAFStdPopLong", "long", + "Math.sqrt(myagg.variance / (myagg.count))", "std,stddev,stddev_pop", + "_FUNC_(x) - Returns the standard deviation of a set of numbers (vectorized, long)"}, + {"VectorUDAFVar", "VectorUDAFStdPopDouble", "double", + "Math.sqrt(myagg.variance / (myagg.count))", "std,stddev,stddev_pop", + "_FUNC_(x) - Returns the standard deviation of a set of numbers (vectorized, double)"}, + {"VectorUDAFVar", "VectorUDAFStdSampLong", "long", + "Math.sqrt(myagg.variance / (myagg.count-1.0))", "stddev_samp", + "_FUNC_(x) - Returns the sample standard deviation of a set of numbers (vectorized, long)"}, + {"VectorUDAFVar", "VectorUDAFStdSampDouble", "double", + "Math.sqrt(myagg.variance / (myagg.count-1.0))", "stddev_samp", + "_FUNC_(x) - Returns the sample standard deviation of a set of numbers (vectorized, double)"}, + + }; + + + private final String expressionOutputDirectory; + private final String expressionTemplateDirectory; + private final String udafOutputDirectory; + private final String udafTemplateDirectory; + private final TestCodeGen testCodeGen; + + static String joinPath(String...parts) { + String path = parts[0]; + for (int i=1; i < parts.length; ++i) { + path += File.separatorChar + parts[i]; + } + return path; + } + + public CodeGen() { + File generationDirectory = new File(System.getProperty("user.dir")); + + expressionOutputDirectory = + new File( + joinPath( + generationDirectory.getAbsolutePath(),"..", "..", "java", "org", + "apache", "hadoop", "hive", "ql", "exec", "vector", + "expressions", "gen")).getAbsolutePath(); + + expressionTemplateDirectory = + joinPath(generationDirectory.getAbsolutePath(), "ExpressionTemplates"); + + udafOutputDirectory = + new File( + joinPath( + generationDirectory.getAbsolutePath(),"..", "..", "java", "org", + "apache", "hadoop", "hive", "ql", "exec", "vector", + "expressions", "aggregates", "gen")).getAbsolutePath(); + + udafTemplateDirectory = + joinPath(generationDirectory.getAbsolutePath(), "udafTemplates"); + + testCodeGen = new TestCodeGen( + new File( + joinPath( + generationDirectory.getAbsolutePath(), "..", "..","test", "org", + "apache", "hadoop", "hive", "ql", "exec", "vector", + "expressions", "gen")).getAbsolutePath(), + joinPath(generationDirectory.getAbsolutePath(), "TestTemplates")); + } + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + CodeGen gen = new CodeGen(); + gen.generate(); + } + + private void generate() throws Exception { + + for (String [] tdesc : templateExpansions) { + if (tdesc[0].equals("ColumnArithmeticScalar")) { + generateColumnArithmeticScalar(tdesc); + } else if (tdesc[0].equals("ColumnCompareScalar")) { + generateColumnCompareScalar(tdesc); + } else if (tdesc[0].equals("FilterColumnCompareScalar")) { + generateFilterColumnCompareScalar(tdesc); + } else if (tdesc[0].equals("FilterScalarCompareColumn")) { + generateFilterScalarCompareColumn(tdesc); + } else if (tdesc[0].equals("ScalarArithmeticColumn")) { + generateScalarArithmeticColumn(tdesc); + } else if (tdesc[0].equals("FilterColumnCompareColumn")) { + generateFilterColumnCompareColumn(tdesc); + } else if (tdesc[0].equals("ColumnArithmeticColumn")) { + generateColumnArithmeticColumn(tdesc); + } else if (tdesc[0].equals("ColumnUnaryMinus")) { + generateColumnUnaryMinus(tdesc); + } else if (tdesc[0].equals("VectorUDAFMinMax")) { + generateVectorUDAFMinMax(tdesc); + } else if (tdesc[0].equals("VectorUDAFMinMaxString")) { + generateVectorUDAFMinMaxString(tdesc); + } else if (tdesc[0].equals("VectorUDAFSum")) { + generateVectorUDAFSum(tdesc); + } else if (tdesc[0].equals("VectorUDAFAvg")) { + generateVectorUDAFAvg(tdesc); + } else if (tdesc[0].equals("VectorUDAFVar")) { + generateVectorUDAFVar(tdesc); + } else if (tdesc[0].equals("FilterStringColumnCompareScalar")) { + generateFilterStringColumnCompareScalar(tdesc); + } else if (tdesc[0].equals("FilterStringScalarCompareColumn")) { + generateFilterStringScalarCompareColumn(tdesc); + } else if (tdesc[0].equals("FilterStringColumnCompareColumn")) { + generateFilterStringColumnCompareColumn(tdesc); + } else { + continue; + } + } + testCodeGen.generateTestSuites(); + } + + private void generateVectorUDAFMinMax(String[] tdesc) throws Exception { + String className = tdesc[1]; + String valueType = tdesc[2]; + String operatorSymbol = tdesc[3]; + String descName = tdesc[4]; + String descValue = tdesc[5]; + String columnType = getColumnVectorType(valueType); + String writableType = getOutputWritableType(valueType); + String inspectorType = getOutputObjectInspector(valueType); + + String outputFile = joinPath(this.udafOutputDirectory, className + ".java"); + String templateFile = joinPath(this.udafTemplateDirectory, tdesc[0] + ".txt"); + + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", valueType); + templateString = templateString.replaceAll("", operatorSymbol); + templateString = templateString.replaceAll("", columnType); + templateString = templateString.replaceAll("", descName); + templateString = templateString.replaceAll("", descValue); + templateString = templateString.replaceAll("", writableType); + templateString = templateString.replaceAll("", inspectorType); + writeFile(outputFile, templateString); + + } + + private void generateVectorUDAFMinMaxString(String[] tdesc) throws Exception { + String className = tdesc[1]; + String operatorSymbol = tdesc[2]; + String descName = tdesc[3]; + String descValue = tdesc[4]; + + String outputFile = joinPath(this.udafOutputDirectory, className + ".java"); + String templateFile = joinPath(this.udafTemplateDirectory, tdesc[0] + ".txt"); + + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", operatorSymbol); + templateString = templateString.replaceAll("", descName); + templateString = templateString.replaceAll("", descValue); + writeFile(outputFile, templateString); + + } + + private void generateVectorUDAFSum(String[] tdesc) throws Exception { + //template, , , , + String className = tdesc[1]; + String valueType = tdesc[2]; + String columnType = getColumnVectorType(valueType); + String writableType = getOutputWritableType(valueType); + String inspectorType = getOutputObjectInspector(valueType); + + String outputFile = joinPath(this.udafOutputDirectory, className + ".java"); + String templateFile = joinPath(this.udafTemplateDirectory, tdesc[0] + ".txt"); + + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", valueType); + templateString = templateString.replaceAll("", columnType); + templateString = templateString.replaceAll("", writableType); + templateString = templateString.replaceAll("", inspectorType); + writeFile(outputFile, templateString); + } + + private void generateVectorUDAFAvg(String[] tdesc) throws IOException { + String className = tdesc[1]; + String valueType = tdesc[2]; + String columnType = getColumnVectorType(valueType); + + String outputFile = joinPath(this.udafOutputDirectory, className + ".java"); + String templateFile = joinPath(this.udafTemplateDirectory, tdesc[0] + ".txt"); + + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", valueType); + templateString = templateString.replaceAll("", columnType); + writeFile(outputFile, templateString); + } + + private void generateVectorUDAFVar(String[] tdesc) throws IOException { + String className = tdesc[1]; + String valueType = tdesc[2]; + String varianceFormula = tdesc[3]; + String descriptionName = tdesc[4]; + String descriptionValue = tdesc[5]; + String columnType = getColumnVectorType(valueType); + + String outputFile = joinPath(this.udafOutputDirectory, className + ".java"); + String templateFile = joinPath(this.udafTemplateDirectory, tdesc[0] + ".txt"); + + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", valueType); + templateString = templateString.replaceAll("", columnType); + templateString = templateString.replaceAll("", varianceFormula); + templateString = templateString.replaceAll("", descriptionName); + templateString = templateString.replaceAll("", descriptionValue); + writeFile(outputFile, templateString); + } + + private void generateFilterStringScalarCompareColumn(String[] tdesc) throws IOException { + String operatorName = tdesc[1]; + String className = "FilterStringScalar" + operatorName + "StringColumn"; + + // Template expansion logic is the same for both column-scalar and scalar-column cases. + generateFilterStringColumnCompareScalar(tdesc, className); + } + + private void generateFilterStringColumnCompareScalar(String[] tdesc) throws IOException { + String operatorName = tdesc[1]; + String className = "FilterStringCol" + operatorName + "StringScalar"; + generateFilterStringColumnCompareScalar(tdesc, className); + } + + private void generateFilterStringColumnCompareColumn(String[] tdesc) throws IOException { + String operatorName = tdesc[1]; + String className = "FilterStringCol" + operatorName + "StringColumn"; + generateFilterStringColumnCompareScalar(tdesc, className); + } + + private void generateFilterStringColumnCompareScalar(String[] tdesc, String className) + throws IOException { + String operatorSymbol = tdesc[2]; + String outputFile = joinPath(this.expressionOutputDirectory, className + ".java"); + // Read the template into a string; + String templateFile = joinPath(this.expressionTemplateDirectory, tdesc[0] + ".txt"); + String templateString = readFile(templateFile); + // Expand, and write result + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", operatorSymbol); + writeFile(outputFile, templateString); + } + + private void generateFilterColumnCompareColumn(String[] tdesc) throws IOException { + //The variables are all same as ColumnCompareScalar except that + //this template doesn't need a return type. Pass anything as return type. + String operatorName = tdesc[1]; + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String className = "Filter" + getCamelCaseType(operandType1) + + "Col" + operatorName + getCamelCaseType(operandType2) + "Column"; + generateColumnBinaryOperatorColumn(tdesc, null, className); + } + + private void generateColumnUnaryMinus(String[] tdesc) throws IOException { + String operandType = tdesc[1]; + String inputColumnVectorType = this.getColumnVectorType(operandType); + String outputColumnVectorType = inputColumnVectorType; + String returnType = operandType; + String className = getCamelCaseType(operandType) + "ColUnaryMinus"; + String outputFile = joinPath(this.expressionOutputDirectory, className + ".java"); + String templateFile = joinPath(this.expressionTemplateDirectory, tdesc[0] + ".txt"); + String templateString = readFile(templateFile); + // Expand, and write result + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", inputColumnVectorType); + templateString = templateString.replaceAll("", outputColumnVectorType); + templateString = templateString.replaceAll("", operandType); + templateString = templateString.replaceAll("", returnType); + writeFile(outputFile, templateString); + } + + private void generateColumnArithmeticColumn(String [] tdesc) throws IOException { + String operatorName = tdesc[1]; + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String className = getCamelCaseType(operandType1) + + "Col" + operatorName + getCamelCaseType(operandType2) + "Column"; + String returnType = getArithmeticReturnType(operandType1, operandType2); + generateColumnBinaryOperatorColumn(tdesc, returnType, className); + } + + private void generateFilterColumnCompareScalar(String[] tdesc) throws IOException { + //The variables are all same as ColumnCompareScalar except that + //this template doesn't need a return type. Pass anything as return type. + String operatorName = tdesc[1]; + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String className = "Filter" + getCamelCaseType(operandType1) + + "Col" + operatorName + getCamelCaseType(operandType2) + "Scalar"; + generateColumnBinaryOperatorScalar(tdesc, null, className); + } + + private void generateFilterScalarCompareColumn(String[] tdesc) throws IOException { + //this template doesn't need a return type. Pass anything as return type. + String operatorName = tdesc[1]; + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String className = "Filter" + getCamelCaseType(operandType1) + + "Scalar" + operatorName + getCamelCaseType(operandType2) + "Column"; + generateScalarBinaryOperatorColumn(tdesc, null, className); + } + + private void generateColumnCompareScalar(String[] tdesc) throws IOException { + String operatorName = tdesc[1]; + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String returnType = "long"; + String className = getCamelCaseType(operandType1) + + "Col" + operatorName + getCamelCaseType(operandType2) + "Scalar"; + generateColumnBinaryOperatorScalar(tdesc, returnType, className); + } + + private void generateColumnBinaryOperatorColumn(String[] tdesc, String returnType, + String className) throws IOException { + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String outputColumnVectorType = this.getColumnVectorType(returnType); + String inputColumnVectorType1 = this.getColumnVectorType(operandType1); + String inputColumnVectorType2 = this.getColumnVectorType(operandType2); + String operatorSymbol = tdesc[4]; + String outputFile = joinPath(this.expressionOutputDirectory, className + ".java"); + + //Read the template into a string; + String templateFile = joinPath(this.expressionTemplateDirectory, tdesc[0] + ".txt"); + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", inputColumnVectorType1); + templateString = templateString.replaceAll("", inputColumnVectorType2); + templateString = templateString.replaceAll("", outputColumnVectorType); + templateString = templateString.replaceAll("", operatorSymbol); + templateString = templateString.replaceAll("", operandType1); + templateString = templateString.replaceAll("", operandType2); + templateString = templateString.replaceAll("", returnType); + templateString = templateString.replaceAll("", getCamelCaseType(returnType)); + writeFile(outputFile, templateString); + + if(returnType==null){ + testCodeGen.addColumnColumnFilterTestCases( + className, + inputColumnVectorType1, + inputColumnVectorType2, + operatorSymbol); + }else{ + testCodeGen.addColumnColumnOperationTestCases( + className, + inputColumnVectorType1, + inputColumnVectorType2, + outputColumnVectorType); + } + } + + private void generateColumnBinaryOperatorScalar(String[] tdesc, String returnType, + String className) throws IOException { + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String outputColumnVectorType = this.getColumnVectorType(returnType); + String inputColumnVectorType = this.getColumnVectorType(operandType1); + String operatorSymbol = tdesc[4]; + String outputFile = joinPath(this.expressionOutputDirectory, className + ".java"); + + //Read the template into a string; + String templateFile = joinPath(this.expressionTemplateDirectory, tdesc[0] + ".txt"); + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", inputColumnVectorType); + templateString = templateString.replaceAll("", outputColumnVectorType); + templateString = templateString.replaceAll("", operatorSymbol); + templateString = templateString.replaceAll("", operandType1); + templateString = templateString.replaceAll("", operandType2); + templateString = templateString.replaceAll("", returnType); + writeFile(outputFile, templateString); + + if(returnType==null) { + testCodeGen.addColumnScalarFilterTestCases( + true, + className, + inputColumnVectorType, + operandType2, + operatorSymbol); + } else { + testCodeGen.addColumnScalarOperationTestCases( + true, + className, + inputColumnVectorType, + outputColumnVectorType, + operandType2); + } + } + + private void generateScalarBinaryOperatorColumn(String[] tdesc, String returnType, + String className) throws IOException { + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String outputColumnVectorType = this.getColumnVectorType(returnType); + String inputColumnVectorType = this.getColumnVectorType(operandType2); + String operatorSymbol = tdesc[4]; + String outputFile = joinPath(this.expressionOutputDirectory, className + ".java"); + + //Read the template into a string; + String templateFile = joinPath(this.expressionTemplateDirectory, tdesc[0] + ".txt"); + String templateString = readFile(templateFile); + templateString = templateString.replaceAll("", className); + templateString = templateString.replaceAll("", inputColumnVectorType); + templateString = templateString.replaceAll("", outputColumnVectorType); + templateString = templateString.replaceAll("", operatorSymbol); + templateString = templateString.replaceAll("", operandType1); + templateString = templateString.replaceAll("", operandType2); + templateString = templateString.replaceAll("", returnType); + writeFile(outputFile, templateString); + + if(returnType==null) { + testCodeGen.addColumnScalarFilterTestCases( + false, + className, + inputColumnVectorType, + operandType1, + operatorSymbol); + } else { + testCodeGen.addColumnScalarOperationTestCases( + false, + className, + inputColumnVectorType, + outputColumnVectorType, + operandType1); + } + } + + //Binary arithmetic operator + private void generateColumnArithmeticScalar(String[] tdesc) throws IOException { + String operatorName = tdesc[1]; + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String className = getCamelCaseType(operandType1) + + "Col" + operatorName + getCamelCaseType(operandType2) + "Scalar"; + String returnType = getArithmeticReturnType(operandType1, operandType2); + generateColumnBinaryOperatorScalar(tdesc, returnType, className); + } + + private void generateScalarArithmeticColumn(String[] tdesc) throws IOException { + String operatorName = tdesc[1]; + String operandType1 = tdesc[2]; + String operandType2 = tdesc[3]; + String className = getCamelCaseType(operandType1) + + "Scalar" + operatorName + getCamelCaseType(operandType2) + "Column"; + String returnType = getArithmeticReturnType(operandType1, operandType2); + generateScalarBinaryOperatorColumn(tdesc, returnType, className); + } + + + static void writeFile(String outputFile, String str) throws IOException { + BufferedWriter w = new BufferedWriter(new FileWriter(outputFile)); + w.write(str); + w.close(); + } + + static String readFile(String templateFile) throws IOException { + BufferedReader r = new BufferedReader(new FileReader(templateFile)); + String line = r.readLine(); + StringBuilder b = new StringBuilder(); + while (line != null) { + b.append(line); + b.append("\n"); + line = r.readLine(); + } + r.close(); + return b.toString(); + } + + static String getCamelCaseType(String type) { + if (type == null) { + return null; + } + if (type.equals("long")) { + return "Long"; + } else if (type.equals("double")) { + return "Double"; + } else { + return type; + } + } + + private String getArithmeticReturnType(String operandType1, + String operandType2) { + if (operandType1.equals("double") || + operandType2.equals("double")) { + return "double"; + } else { + return "long"; + } + } + + private String getColumnVectorType(String primitiveType) { + if(primitiveType!=null && primitiveType.equals("double")) { + return "DoubleColumnVector"; + } + return "LongColumnVector"; + } + + private String getOutputWritableType(String primitiveType) throws Exception { + if (primitiveType.equals("long")) { + return "LongWritable"; + } else if (primitiveType.equals("double")) { + return "DoubleWritable"; + } + throw new Exception("Unimplemented primitive output writable: " + primitiveType); + } + + private String getOutputObjectInspector(String primitiveType) throws Exception { + if (primitiveType.equals("long")) { + return "PrimitiveObjectInspectorFactory.writableLongObjectInspector"; + } else if (primitiveType.equals("double")) { + return "PrimitiveObjectInspectorFactory.writableDoubleObjectInspector"; + } + throw new Exception("Unimplemented primitive output inspector: " + primitiveType); + } +} + diff --git ql/src/gen/vectorization/org/apache/hadoop/hive/ql/exec/vector/gen/TestCodeGen.java ql/src/gen/vectorization/org/apache/hadoop/hive/ql/exec/vector/gen/TestCodeGen.java new file mode 100644 index 0000000..908b8e8 --- /dev/null +++ ql/src/gen/vectorization/org/apache/hadoop/hive/ql/exec/vector/gen/TestCodeGen.java @@ -0,0 +1,258 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.exec.vector.gen; + +import java.io.IOException; +import java.util.HashMap; + +/** + * + * TestCodeGen. + * This class is mutable and maintains a hashmap of TestSuiteClassName to test cases. + * The tests cases are added over the course of vectorized expressions class generation, + * with test classes being outputted at the end. For each column vector (inputs and/or outputs) + * a matrix of pairwise covering Booleans is used to generate test cases across nulls and + * repeating dimensions. Based on the input column vector(s) nulls and repeating states + * the states of the output column vector (if there is one) is validated, along with the null + * vector. For filter operations the selection vector is validated against the generated + * data. Each template corresponds to a class representing a test suite. + */ +public class TestCodeGen { + + public enum TestSuiteClassName{ + TestColumnScalarOperationVectorExpressionEvaluation, + TestColumnScalarFilterVectorExpressionEvaluation, + TestColumnColumnOperationVectorExpressionEvaluation, + TestColumnColumnFilterVectorExpressionEvaluation, + } + + private final String testOutputDir; + private final String testTemplateDirectory; + private final HashMap testsuites; + + public TestCodeGen(String testOutputDir, String testTemplateDirectory) { + this.testOutputDir = testOutputDir; + this.testTemplateDirectory = testTemplateDirectory; + testsuites = new HashMap(); + + for(TestSuiteClassName className : TestSuiteClassName.values()) { + testsuites.put(className,new StringBuilder()); + } + + } + + public void addColumnScalarOperationTestCases(boolean op1IsCol, String vectorExpClassName, + String inputColumnVectorType, String outputColumnVectorType, String scalarType) + throws IOException { + + TestSuiteClassName template = + TestSuiteClassName.TestColumnScalarOperationVectorExpressionEvaluation; + + //Read the template into a string; + String templateFile = CodeGen.joinPath(this.testTemplateDirectory,template.toString()+".txt"); + String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); + + for(Boolean[] testMatrix :new Boolean[][]{ + // Pairwise: InitOuputColHasNulls, InitOuputColIsRepeating, ColumnHasNulls, ColumnIsRepeating + {false, true, true, true}, + {false, false, false, false}, + {true, false, true, false}, + {true, true, false, false}, + {true, false, false, true}}) { + String testCase = templateString; + testCase = testCase.replaceAll("", + "test" + + vectorExpClassName + + createNullRepeatingNameFragment("Out", testMatrix[0], testMatrix[1]) + + createNullRepeatingNameFragment("Col", testMatrix[2], testMatrix[3])); + testCase = testCase.replaceAll("", vectorExpClassName); + testCase = testCase.replaceAll("", inputColumnVectorType); + testCase = testCase.replaceAll("", outputColumnVectorType); + testCase = testCase.replaceAll("", scalarType); + testCase = testCase.replaceAll("", CodeGen.getCamelCaseType(scalarType)); + testCase = testCase.replaceAll("", testMatrix[0].toString()); + testCase = testCase.replaceAll("", testMatrix[1].toString()); + testCase = testCase.replaceAll("", testMatrix[2].toString()); + testCase = testCase.replaceAll("", testMatrix[3].toString()); + + if(op1IsCol){ + testCase = testCase.replaceAll("","0, scalarValue"); + }else{ + testCase = testCase.replaceAll("","scalarValue, 0"); + } + + testsuites.get(template).append(testCase); + } + } + + public void addColumnScalarFilterTestCases(boolean op1IsCol, String vectorExpClassName, + String inputColumnVectorType, String scalarType, String operatorSymbol) + throws IOException { + + TestSuiteClassName template = + TestSuiteClassName.TestColumnScalarFilterVectorExpressionEvaluation; + + //Read the template into a string; + String templateFile = CodeGen.joinPath(this.testTemplateDirectory,template.toString()+".txt"); + String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); + + for(Boolean[] testMatrix : new Boolean[][]{ + // Pairwise: ColumnHasNulls, ColumnIsRepeating + {true, true}, + {true, false}, + {false, false}, + {false, true}}) { + String testCase = templateString; + testCase = testCase.replaceAll("", + "test" + + vectorExpClassName + + createNullRepeatingNameFragment("Col", testMatrix[0], testMatrix[1])); + testCase = testCase.replaceAll("", vectorExpClassName); + testCase = testCase.replaceAll("", inputColumnVectorType); + testCase = testCase.replaceAll("", scalarType); + testCase = testCase.replaceAll("", CodeGen.getCamelCaseType(scalarType)); + testCase = testCase.replaceAll("", testMatrix[0].toString()); + testCase = testCase.replaceAll("", testMatrix[1].toString()); + testCase = testCase.replaceAll("", operatorSymbol); + + if(op1IsCol){ + testCase = testCase.replaceAll("","inputColumnVector.vector[i]"); + testCase = testCase.replaceAll("","scalarValue"); + }else{ + testCase = testCase.replaceAll("","scalarValue"); + testCase = testCase.replaceAll("","inputColumnVector.vector[i]"); + } + + testsuites.get(template).append(testCase); + } + } + + public void addColumnColumnOperationTestCases(String vectorExpClassName, + String inputColumnVectorType1, String inputColumnVectorType2, String outputColumnVectorType) + throws IOException { + + TestSuiteClassName template= + TestSuiteClassName.TestColumnColumnOperationVectorExpressionEvaluation; + + //Read the template into a string; + String templateFile = CodeGen.joinPath(this.testTemplateDirectory,template.toString()+".txt"); + String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); + + for(Boolean[] testMatrix : new Boolean[][]{ + // Pairwise: InitOuputColHasNulls, InitOuputColIsRepeating, Column1HasNulls, + // Column1IsRepeating, Column2HasNulls, Column2IsRepeating + {true, true, false, true, true, true}, + {false, false, true, false, false, false}, + {true, false, true, false, true, true}, + {true, true, true, true, false, false}, + {false, false, false, true, true, false}, + {false, true, false, false, false, true}}) { + String testCase = templateString; + testCase = testCase.replaceAll("", + "test" + + vectorExpClassName + + createNullRepeatingNameFragment("Out", testMatrix[0], testMatrix[1]) + + createNullRepeatingNameFragment("C1", testMatrix[2], testMatrix[3]) + + createNullRepeatingNameFragment("C2", testMatrix[4], testMatrix[5])); + testCase = testCase.replaceAll("", vectorExpClassName); + testCase = testCase.replaceAll("", inputColumnVectorType1); + testCase = testCase.replaceAll("", inputColumnVectorType2); + testCase = testCase.replaceAll("", outputColumnVectorType); + testCase = testCase.replaceAll("", testMatrix[0].toString()); + testCase = testCase.replaceAll("", testMatrix[1].toString()); + testCase = testCase.replaceAll("", testMatrix[2].toString()); + testCase = testCase.replaceAll("", testMatrix[3].toString()); + testCase = testCase.replaceAll("", testMatrix[4].toString()); + testCase = testCase.replaceAll("", testMatrix[5].toString()); + + testsuites.get(template).append(testCase); + } + } + + public void addColumnColumnFilterTestCases(String vectorExpClassName, + String inputColumnVectorType1, String inputColumnVectorType2, String operatorSymbol) + throws IOException { + + TestSuiteClassName template= + TestSuiteClassName.TestColumnColumnFilterVectorExpressionEvaluation; + + //Read the template into a string; + String templateFile = CodeGen.joinPath(this.testTemplateDirectory,template.toString()+".txt"); + String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); + + for(Boolean[] testMatrix : new Boolean[][]{ + // Pairwise: Column1HasNulls, Column1IsRepeating, Column2HasNulls, Column2IsRepeating + {false, true, true, true}, + {false, false, false, false}, + {true, false, true, false}, + {true, true, false, false}, + {true, false, false, true}}) { + String testCase = templateString; + testCase = testCase.replaceAll("", + "test" + + vectorExpClassName + + createNullRepeatingNameFragment("C1", testMatrix[0], testMatrix[1]) + + createNullRepeatingNameFragment("C2", testMatrix[2], testMatrix[3])); + testCase = testCase.replaceAll("", vectorExpClassName); + testCase = testCase.replaceAll("", inputColumnVectorType1); + testCase = testCase.replaceAll("", inputColumnVectorType2); + testCase = testCase.replaceAll("", testMatrix[0].toString()); + testCase = testCase.replaceAll("", testMatrix[1].toString()); + testCase = testCase.replaceAll("", testMatrix[2].toString()); + testCase = testCase.replaceAll("", testMatrix[3].toString()); + testCase = testCase.replaceAll("", operatorSymbol); + + testsuites.get(template).append(testCase); + } + } + + public void generateTestSuites() throws IOException { + + String templateFile = CodeGen.joinPath(this.testTemplateDirectory, "TestClass.txt"); + for(TestSuiteClassName testClass : testsuites.keySet()) { + + String templateString = CodeGen.readFile(templateFile); + templateString = templateString.replaceAll("", testClass.toString()); + templateString = templateString.replaceAll("", testsuites.get(testClass).toString()); + + String outputFile = CodeGen.joinPath(this.testOutputDir, testClass + ".java"); + + CodeGen.writeFile(outputFile, templateString); + } + } + + private static String createNullRepeatingNameFragment(String idenitfier, boolean nulls, boolean repeating) + { + if(nulls || repeating){ + if(nulls){ + idenitfier+="Nulls"; + } + if(repeating){ + idenitfier+="Repeats"; + } + return idenitfier; + } + + return ""; + } + + private static String removeTemplateComments(String templateString){ + return templateString.replaceAll("(?s)", ""); + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java index f0c3f78..e6890cb 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java @@ -22,20 +22,21 @@ import java.util.List; import org.apache.hadoop.hive.ql.exec.Description; -import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; +import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; +import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; +import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; +import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.plan.AggregationDesc; import org.apache.hadoop.hive.ql.util.JavaDataModel; +import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.hive.serde2.io.DoubleWritable; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; -import org.apache.hadoop.io.LongWritable; /** * Generated from template VectorUDAFAvg.txt. @@ -45,19 +46,19 @@ public class VectorUDAFAvgLong extends VectorAggregateExpression { private static final long serialVersionUID = 1L; - + /** class for storing the current aggregate value. */ static class Aggregation implements AggregationBuffer { private static final long serialVersionUID = 1L; - transient private double sum = 0; - transient private long count = 0; + transient private double sum; + transient private long count; transient private boolean isNull; - + public void sumValue(long value) { if (isNull) { - sum = value; + sum = value; count = 1; isNull = false; } else { @@ -71,13 +72,13 @@ public int getVariableSize() { throw new UnsupportedOperationException(); } } - + private VectorExpression inputExpression; transient private Object[] partialResult; transient private LongWritable resultCount; transient private DoubleWritable resultSum; transient private StructObjectInspector soi; - + public VectorUDAFAvgLong(VectorExpression inputExpression) { this(); this.inputExpression = inputExpression; @@ -102,7 +103,7 @@ private void initPartialResultInspector() { fname.add("sum"); soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi); } - + private Aggregation getCurrentAggregationBuffer( VectorAggregationBufferRow[] aggregationBufferSets, int bufferIndex, @@ -111,21 +112,21 @@ private Aggregation getCurrentAggregationBuffer( Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(bufferIndex); return myagg; } - + @Override public void aggregateInputSelection( VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, + int bufferIndex, VectorizedRowBatch batch) throws HiveException { - + int batchSize = batch.size; - + if (batchSize == 0) { return; } - + inputExpression.evaluate(batch); - + LongColumnVector inputVector = ( LongColumnVector)batch. cols[this.inputExpression.getOutputColumn()]; long[] vector = inputVector.vector; @@ -179,12 +180,12 @@ private void iterateNoNullsRepeatingWithAggregationSelection( for (int i=0; i < batchSize; ++i) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, bufferIndex, i); myagg.sumValue(value); } - } + } private void iterateNoNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, @@ -192,10 +193,10 @@ private void iterateNoNullsSelectionWithAggregationSelection( long[] values, int[] selection, int batchSize) { - + for (int i=0; i < batchSize; ++i) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, bufferIndex, i); myagg.sumValue(values[selection[i]]); @@ -209,7 +210,7 @@ private void iterateNoNullsWithAggregationSelection( int batchSize) { for (int i=0; i < batchSize; ++i) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, bufferIndex, i); myagg.sumValue(values[i]); @@ -223,17 +224,17 @@ private void iterateHasNullsRepeatingSelectionWithAggregationSelection( int batchSize, int[] selection, boolean[] isNull) { - + for (int i=0; i < batchSize; ++i) { if (!isNull[selection[i]]) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, bufferIndex, i); myagg.sumValue(value); } } - + } private void iterateHasNullsRepeatingWithAggregationSelection( @@ -246,7 +247,7 @@ private void iterateHasNullsRepeatingWithAggregationSelection( for (int i=0; i < batchSize; ++i) { if (!isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, bufferIndex, i); myagg.sumValue(value); @@ -266,7 +267,7 @@ private void iterateHasNullsSelectionWithAggregationSelection( int i = selection[j]; if (!isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, bufferIndex, j); myagg.sumValue(values[i]); @@ -284,7 +285,7 @@ private void iterateHasNullsWithAggregationSelection( for (int i=0; i < batchSize; ++i) { if (!isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, bufferIndex, i); myagg.sumValue(values[i]); @@ -292,26 +293,26 @@ private void iterateHasNullsWithAggregationSelection( } } - + @Override - public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) + public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) throws HiveException { - + inputExpression.evaluate(batch); - - LongColumnVector inputVector = + + LongColumnVector inputVector = (LongColumnVector)batch.cols[this.inputExpression.getOutputColumn()]; - + int batchSize = batch.size; - + if (batchSize == 0) { return; } - + Aggregation myagg = (Aggregation)agg; - + long[] vector = inputVector.vector; - + if (inputVector.isRepeating) { if (inputVector.noNulls) { if (myagg.isNull) { @@ -324,7 +325,7 @@ public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) } return; } - + if (!batch.selectedInUse && inputVector.noNulls) { iterateNoSelectionNoNulls(myagg, vector, batchSize); } @@ -338,14 +339,14 @@ else if (inputVector.noNulls){ iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); } } - + private void iterateSelectionHasNulls( - Aggregation myagg, - long[] vector, + Aggregation myagg, + long[] vector, int batchSize, - boolean[] isNull, + boolean[] isNull, int[] selected) { - + for (int j=0; j< batchSize; ++j) { int i = selected[j]; if (!isNull[i]) { @@ -362,17 +363,17 @@ private void iterateSelectionHasNulls( } private void iterateSelectionNoNulls( - Aggregation myagg, - long[] vector, - int batchSize, + Aggregation myagg, + long[] vector, + int batchSize, int[] selected) { - + if (myagg.isNull) { myagg.isNull = false; myagg.sum = 0; myagg.count = 0; } - + for (int i=0; i< batchSize; ++i) { long value = vector[selected[i]]; myagg.sum += value; @@ -381,15 +382,15 @@ private void iterateSelectionNoNulls( } private void iterateNoSelectionHasNulls( - Aggregation myagg, - long[] vector, + Aggregation myagg, + long[] vector, int batchSize, boolean[] isNull) { - + for(int i=0;i"}, - {"ColumnCompareScalar", "Greater", "double", "double", ">"}, - {"ColumnCompareScalar", "GreaterEqual", "long", "double", ">="}, - {"ColumnCompareScalar", "GreaterEqual", "double", "double", ">="}, - - {"FilterColumnCompareScalar", "Equal", "long", "double", "=="}, - {"FilterColumnCompareScalar", "Equal", "double", "double", "=="}, - {"FilterColumnCompareScalar", "NotEqual", "long", "double", "!="}, - {"FilterColumnCompareScalar", "NotEqual", "double", "double", "!="}, - {"FilterColumnCompareScalar", "Less", "long", "double", "<"}, - {"FilterColumnCompareScalar", "Less", "double", "double", "<"}, - {"FilterColumnCompareScalar", "LessEqual", "long", "double", "<="}, - {"FilterColumnCompareScalar", "LessEqual", "double", "double", "<="}, - {"FilterColumnCompareScalar", "Greater", "long", "double", ">"}, - {"FilterColumnCompareScalar", "Greater", "double", "double", ">"}, - {"FilterColumnCompareScalar", "GreaterEqual", "long", "double", ">="}, - {"FilterColumnCompareScalar", "GreaterEqual", "double", "double", ">="}, - - {"FilterColumnCompareScalar", "Equal", "long", "long", "=="}, - {"FilterColumnCompareScalar", "Equal", "double", "long", "=="}, - {"FilterColumnCompareScalar", "NotEqual", "long", "long", "!="}, - {"FilterColumnCompareScalar", "NotEqual", "double", "long", "!="}, - {"FilterColumnCompareScalar", "Less", "long", "long", "<"}, - {"FilterColumnCompareScalar", "Less", "double", "long", "<"}, - {"FilterColumnCompareScalar", "LessEqual", "long", "long", "<="}, - {"FilterColumnCompareScalar", "LessEqual", "double", "long", "<="}, - {"FilterColumnCompareScalar", "Greater", "long", "long", ">"}, - {"FilterColumnCompareScalar", "Greater", "double", "long", ">"}, - {"FilterColumnCompareScalar", "GreaterEqual", "long", "long", ">="}, - {"FilterColumnCompareScalar", "GreaterEqual", "double", "long", ">="}, - - {"FilterScalarCompareColumn", "Equal", "long", "double", "=="}, - {"FilterScalarCompareColumn", "Equal", "double", "double", "=="}, - {"FilterScalarCompareColumn", "NotEqual", "long", "double", "!="}, - {"FilterScalarCompareColumn", "NotEqual", "double", "double", "!="}, - {"FilterScalarCompareColumn", "Less", "long", "double", "<"}, - {"FilterScalarCompareColumn", "Less", "double", "double", "<"}, - {"FilterScalarCompareColumn", "LessEqual", "long", "double", "<="}, - {"FilterScalarCompareColumn", "LessEqual", "double", "double", "<="}, - {"FilterScalarCompareColumn", "Greater", "long", "double", ">"}, - {"FilterScalarCompareColumn", "Greater", "double", "double", ">"}, - {"FilterScalarCompareColumn", "GreaterEqual", "long", "double", ">="}, - {"FilterScalarCompareColumn", "GreaterEqual", "double", "double", ">="}, - - {"FilterScalarCompareColumn", "Equal", "long", "long", "=="}, - {"FilterScalarCompareColumn", "Equal", "double", "long", "=="}, - {"FilterScalarCompareColumn", "NotEqual", "long", "long", "!="}, - {"FilterScalarCompareColumn", "NotEqual", "double", "long", "!="}, - {"FilterScalarCompareColumn", "Less", "long", "long", "<"}, - {"FilterScalarCompareColumn", "Less", "double", "long", "<"}, - {"FilterScalarCompareColumn", "LessEqual", "long", "long", "<="}, - {"FilterScalarCompareColumn", "LessEqual", "double", "long", "<="}, - {"FilterScalarCompareColumn", "Greater", "long", "long", ">"}, - {"FilterScalarCompareColumn", "Greater", "double", "long", ">"}, - {"FilterScalarCompareColumn", "GreaterEqual", "long", "long", ">="}, - {"FilterScalarCompareColumn", "GreaterEqual", "double", "long", ">="}, - - {"FilterStringColumnCompareScalar", "Equal", "=="}, - {"FilterStringColumnCompareScalar", "NotEqual", "!="}, - {"FilterStringColumnCompareScalar", "Less", "<"}, - {"FilterStringColumnCompareScalar", "LessEqual", "<="}, - {"FilterStringColumnCompareScalar", "Greater", ">"}, - {"FilterStringColumnCompareScalar", "GreaterEqual", ">="}, - - {"FilterStringScalarCompareColumn", "Equal", "=="}, - {"FilterStringScalarCompareColumn", "NotEqual", "!="}, - {"FilterStringScalarCompareColumn", "Less", "<"}, - {"FilterStringScalarCompareColumn", "LessEqual", "<="}, - {"FilterStringScalarCompareColumn", "Greater", ">"}, - {"FilterStringScalarCompareColumn", "GreaterEqual", ">="}, - - {"FilterStringColumnCompareColumn", "Equal", "=="}, - {"FilterStringColumnCompareColumn", "NotEqual", "!="}, - {"FilterStringColumnCompareColumn", "Less", "<"}, - {"FilterStringColumnCompareColumn", "LessEqual", "<="}, - {"FilterStringColumnCompareColumn", "Greater", ">"}, - {"FilterStringColumnCompareColumn", "GreaterEqual", ">="}, - - {"FilterColumnCompareColumn", "Equal", "long", "double", "=="}, - {"FilterColumnCompareColumn", "Equal", "double", "double", "=="}, - {"FilterColumnCompareColumn", "NotEqual", "long", "double", "!="}, - {"FilterColumnCompareColumn", "NotEqual", "double", "double", "!="}, - {"FilterColumnCompareColumn", "Less", "long", "double", "<"}, - {"FilterColumnCompareColumn", "Less", "double", "double", "<"}, - {"FilterColumnCompareColumn", "LessEqual", "long", "double", "<="}, - {"FilterColumnCompareColumn", "LessEqual", "double", "double", "<="}, - {"FilterColumnCompareColumn", "Greater", "long", "double", ">"}, - {"FilterColumnCompareColumn", "Greater", "double", "double", ">"}, - {"FilterColumnCompareColumn", "GreaterEqual", "long", "double", ">="}, - {"FilterColumnCompareColumn", "GreaterEqual", "double", "double", ">="}, - - {"FilterColumnCompareColumn", "Equal", "long", "long", "=="}, - {"FilterColumnCompareColumn", "Equal", "double", "long", "=="}, - {"FilterColumnCompareColumn", "NotEqual", "long", "long", "!="}, - {"FilterColumnCompareColumn", "NotEqual", "double", "long", "!="}, - {"FilterColumnCompareColumn", "Less", "long", "long", "<"}, - {"FilterColumnCompareColumn", "Less", "double", "long", "<"}, - {"FilterColumnCompareColumn", "LessEqual", "long", "long", "<="}, - {"FilterColumnCompareColumn", "LessEqual", "double", "long", "<="}, - {"FilterColumnCompareColumn", "Greater", "long", "long", ">"}, - {"FilterColumnCompareColumn", "Greater", "double", "long", ">"}, - {"FilterColumnCompareColumn", "GreaterEqual", "long", "long", ">="}, - {"FilterColumnCompareColumn", "GreaterEqual", "double", "long", ">="}, - - {"ColumnUnaryMinus", "long"}, - {"ColumnUnaryMinus", "double"}, - - // template, , , , , - {"VectorUDAFMinMax", "VectorUDAFMinLong", "long", "<", "min", - "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: long)"}, - {"VectorUDAFMinMax", "VectorUDAFMinDouble", "double", "<", "min", - "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: double)"}, - {"VectorUDAFMinMax", "VectorUDAFMaxLong", "long", ">", "max", - "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: long)"}, - {"VectorUDAFMinMax", "VectorUDAFMaxDouble", "double", ">", "max", - "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: double)"}, - - {"VectorUDAFMinMaxString", "VectorUDAFMinString", "<", "min", - "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: string)"}, - {"VectorUDAFMinMaxString", "VectorUDAFMaxString", ">", "max", - "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: string)"}, - - //template, , - {"VectorUDAFSum", "VectorUDAFSumLong", "long"}, - {"VectorUDAFSum", "VectorUDAFSumDouble", "double"}, - {"VectorUDAFAvg", "VectorUDAFAvgLong", "long"}, - {"VectorUDAFAvg", "VectorUDAFAvgDouble", "double"}, - - // template, , , , , - // - {"VectorUDAFVar", "VectorUDAFVarPopLong", "long", "myagg.variance / myagg.count", - "variance, var_pop", - "_FUNC_(x) - Returns the variance of a set of numbers (vectorized, long)"}, - {"VectorUDAFVar", "VectorUDAFVarPopDouble", "double", "myagg.variance / myagg.count", - "variance, var_pop", - "_FUNC_(x) - Returns the variance of a set of numbers (vectorized, double)"}, - {"VectorUDAFVar", "VectorUDAFVarSampLong", "long", "myagg.variance / (myagg.count-1.0)", - "var_samp", - "_FUNC_(x) - Returns the sample variance of a set of numbers (vectorized, long)"}, - {"VectorUDAFVar", "VectorUDAFVarSampDouble", "double", "myagg.variance / (myagg.count-1.0)", - "var_samp", - "_FUNC_(x) - Returns the sample variance of a set of numbers (vectorized, double)"}, - {"VectorUDAFVar", "VectorUDAFStdPopLong", "long", - "Math.sqrt(myagg.variance / (myagg.count))", "std,stddev,stddev_pop", - "_FUNC_(x) - Returns the standard deviation of a set of numbers (vectorized, long)"}, - {"VectorUDAFVar", "VectorUDAFStdPopDouble", "double", - "Math.sqrt(myagg.variance / (myagg.count))", "std,stddev,stddev_pop", - "_FUNC_(x) - Returns the standard deviation of a set of numbers (vectorized, double)"}, - {"VectorUDAFVar", "VectorUDAFStdSampLong", "long", - "Math.sqrt(myagg.variance / (myagg.count-1.0))", "stddev_samp", - "_FUNC_(x) - Returns the sample standard deviation of a set of numbers (vectorized, long)"}, - {"VectorUDAFVar", "VectorUDAFStdSampDouble", "double", - "Math.sqrt(myagg.variance / (myagg.count-1.0))", "stddev_samp", - "_FUNC_(x) - Returns the sample standard deviation of a set of numbers (vectorized, double)"}, - - }; - - - private final String templateDirectory; - private final String outputDirectory; - private final TestCodeGen testCodeGen; - - static String joinPath(String...parts) { - String path = parts[0]; - for (int i=1; i < parts.length; ++i) { - path += File.separatorChar + parts[i]; - } - return path; - } - - public CodeGen() { - templateDirectory = System.getProperty("user.dir"); - File f = new File(templateDirectory); - outputDirectory = joinPath(f.getParent(), "gen"); - testCodeGen = new TestCodeGen(joinPath(f.getParent(), "test"), templateDirectory); - } - - public CodeGen(String templateDirectory, String outputDirectory, String testOutputDirectory) { - this.templateDirectory = templateDirectory; - this.outputDirectory = outputDirectory; - testCodeGen = new TestCodeGen(testOutputDirectory, templateDirectory); - } - - /** - * @param args - * @throws Exception - */ - public static void main(String[] args) throws Exception { - CodeGen gen; - if (args == null || args.length==0) { - gen = new CodeGen(); - } else if (args.length==3) { - gen = new CodeGen(args[0], args[1], args[2]); - }else{ - System.out.println("args: "); - return; - } - gen.generate(); - } - - private void generate() throws Exception { - - for (String [] tdesc : templateExpansions) { - if (tdesc[0].equals("ColumnArithmeticScalar")) { - generateColumnArithmeticScalar(tdesc); - } else if (tdesc[0].equals("ColumnCompareScalar")) { - generateColumnCompareScalar(tdesc); - } else if (tdesc[0].equals("FilterColumnCompareScalar")) { - generateFilterColumnCompareScalar(tdesc); - } else if (tdesc[0].equals("FilterScalarCompareColumn")) { - generateFilterScalarCompareColumn(tdesc); - } else if (tdesc[0].equals("ScalarArithmeticColumn")) { - generateScalarArithmeticColumn(tdesc); - } else if (tdesc[0].equals("FilterColumnCompareColumn")) { - generateFilterColumnCompareColumn(tdesc); - } else if (tdesc[0].equals("ColumnArithmeticColumn")) { - generateColumnArithmeticColumn(tdesc); - } else if (tdesc[0].equals("ColumnUnaryMinus")) { - generateColumnUnaryMinus(tdesc); - } else if (tdesc[0].equals("VectorUDAFMinMax")) { - generateVectorUDAFMinMax(tdesc); - } else if (tdesc[0].equals("VectorUDAFMinMaxString")) { - generateVectorUDAFMinMaxString(tdesc); - } else if (tdesc[0].equals("VectorUDAFSum")) { - generateVectorUDAFSum(tdesc); - } else if (tdesc[0].equals("VectorUDAFAvg")) { - generateVectorUDAFAvg(tdesc); - } else if (tdesc[0].equals("VectorUDAFVar")) { - generateVectorUDAFVar(tdesc); - } else if (tdesc[0].equals("FilterStringColumnCompareScalar")) { - generateFilterStringColumnCompareScalar(tdesc); - } else if (tdesc[0].equals("FilterStringScalarCompareColumn")) { - generateFilterStringScalarCompareColumn(tdesc); - } else if (tdesc[0].equals("FilterStringColumnCompareColumn")) { - generateFilterStringColumnCompareColumn(tdesc); - } else { - continue; - } - } - testCodeGen.generateTestSuites(); - } - - private void generateVectorUDAFMinMax(String[] tdesc) throws Exception { - String className = tdesc[1]; - String valueType = tdesc[2]; - String operatorSymbol = tdesc[3]; - String descName = tdesc[4]; - String descValue = tdesc[5]; - String columnType = getColumnVectorType(valueType); - String writableType = getOutputWritableType(valueType); - String inspectorType = getOutputObjectInspector(valueType); - - String outputFile = joinPath(this.outputDirectory, className + ".java"); - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", valueType); - templateString = templateString.replaceAll("", operatorSymbol); - templateString = templateString.replaceAll("", columnType); - templateString = templateString.replaceAll("", descName); - templateString = templateString.replaceAll("", descValue); - templateString = templateString.replaceAll("", writableType); - templateString = templateString.replaceAll("", inspectorType); - writeFile(outputFile, templateString); - - } - - private void generateVectorUDAFMinMaxString(String[] tdesc) throws Exception { - String className = tdesc[1]; - String operatorSymbol = tdesc[2]; - String descName = tdesc[3]; - String descValue = tdesc[4]; - - String outputFile = joinPath(this.outputDirectory, className + ".java"); - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", operatorSymbol); - templateString = templateString.replaceAll("", descName); - templateString = templateString.replaceAll("", descValue); - writeFile(outputFile, templateString); - - } - - private void generateVectorUDAFSum(String[] tdesc) throws Exception { - //template, , , , - String className = tdesc[1]; - String valueType = tdesc[2]; - String columnType = getColumnVectorType(valueType); - String writableType = getOutputWritableType(valueType); - String inspectorType = getOutputObjectInspector(valueType); - - String outputFile = joinPath(this.outputDirectory, className + ".java"); - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", valueType); - templateString = templateString.replaceAll("", columnType); - templateString = templateString.replaceAll("", writableType); - templateString = templateString.replaceAll("", inspectorType); - writeFile(outputFile, templateString); - } - - private void generateVectorUDAFAvg(String[] tdesc) throws IOException { - String className = tdesc[1]; - String valueType = tdesc[2]; - String columnType = getColumnVectorType(valueType); - - String outputFile = joinPath(this.outputDirectory, className + ".java"); - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", valueType); - templateString = templateString.replaceAll("", columnType); - writeFile(outputFile, templateString); - } - - private void generateVectorUDAFVar(String[] tdesc) throws IOException { - String className = tdesc[1]; - String valueType = tdesc[2]; - String varianceFormula = tdesc[3]; - String descriptionName = tdesc[4]; - String descriptionValue = tdesc[5]; - String columnType = getColumnVectorType(valueType); - - String outputFile = joinPath(this.outputDirectory, className + ".java"); - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", valueType); - templateString = templateString.replaceAll("", columnType); - templateString = templateString.replaceAll("", varianceFormula); - templateString = templateString.replaceAll("", descriptionName); - templateString = templateString.replaceAll("", descriptionValue); - writeFile(outputFile, templateString); - } - - private void generateFilterStringScalarCompareColumn(String[] tdesc) throws IOException { - String operatorName = tdesc[1]; - String className = "FilterStringScalar" + operatorName + "StringColumn"; - - // Template expansion logic is the same for both column-scalar and scalar-column cases. - generateFilterStringColumnCompareScalar(tdesc, className); - } - - private void generateFilterStringColumnCompareScalar(String[] tdesc) throws IOException { - String operatorName = tdesc[1]; - String className = "FilterStringCol" + operatorName + "StringScalar"; - generateFilterStringColumnCompareScalar(tdesc, className); - } - - private void generateFilterStringColumnCompareColumn(String[] tdesc) throws IOException { - String operatorName = tdesc[1]; - String className = "FilterStringCol" + operatorName + "StringColumn"; - generateFilterStringColumnCompareScalar(tdesc, className); - } - - private void generateFilterStringColumnCompareScalar(String[] tdesc, String className) - throws IOException { - String operatorSymbol = tdesc[2]; - String outputFile = joinPath(this.outputDirectory, className + ".java"); - // Read the template into a string; - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - String templateString = readFile(templateFile); - // Expand, and write result - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", operatorSymbol); - writeFile(outputFile, templateString); - } - - private void generateFilterColumnCompareColumn(String[] tdesc) throws IOException { - //The variables are all same as ColumnCompareScalar except that - //this template doesn't need a return type. Pass anything as return type. - String operatorName = tdesc[1]; - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String className = "Filter" + getCamelCaseType(operandType1) - + "Col" + operatorName + getCamelCaseType(operandType2) + "Column"; - generateColumnBinaryOperatorColumn(tdesc, null, className); - } - - private void generateColumnUnaryMinus(String[] tdesc) throws IOException { - String operandType = tdesc[1]; - String inputColumnVectorType = this.getColumnVectorType(operandType); - String outputColumnVectorType = inputColumnVectorType; - String returnType = operandType; - String className = getCamelCaseType(operandType) + "ColUnaryMinus"; - String outputFile = joinPath(this.outputDirectory, className + ".java"); - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - String templateString = readFile(templateFile); - // Expand, and write result - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", inputColumnVectorType); - templateString = templateString.replaceAll("", outputColumnVectorType); - templateString = templateString.replaceAll("", operandType); - templateString = templateString.replaceAll("", returnType); - writeFile(outputFile, templateString); - } - - private void generateColumnArithmeticColumn(String [] tdesc) throws IOException { - String operatorName = tdesc[1]; - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String className = getCamelCaseType(operandType1) - + "Col" + operatorName + getCamelCaseType(operandType2) + "Column"; - String returnType = getArithmeticReturnType(operandType1, operandType2); - generateColumnBinaryOperatorColumn(tdesc, returnType, className); - } - - private void generateFilterColumnCompareScalar(String[] tdesc) throws IOException { - //The variables are all same as ColumnCompareScalar except that - //this template doesn't need a return type. Pass anything as return type. - String operatorName = tdesc[1]; - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String className = "Filter" + getCamelCaseType(operandType1) - + "Col" + operatorName + getCamelCaseType(operandType2) + "Scalar"; - generateColumnBinaryOperatorScalar(tdesc, null, className); - } - - private void generateFilterScalarCompareColumn(String[] tdesc) throws IOException { - //this template doesn't need a return type. Pass anything as return type. - String operatorName = tdesc[1]; - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String className = "Filter" + getCamelCaseType(operandType1) - + "Scalar" + operatorName + getCamelCaseType(operandType2) + "Column"; - generateScalarBinaryOperatorColumn(tdesc, null, className); - } - - private void generateColumnCompareScalar(String[] tdesc) throws IOException { - String operatorName = tdesc[1]; - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String returnType = "long"; - String className = getCamelCaseType(operandType1) - + "Col" + operatorName + getCamelCaseType(operandType2) + "Scalar"; - generateColumnBinaryOperatorScalar(tdesc, returnType, className); - } - - private void generateColumnBinaryOperatorColumn(String[] tdesc, String returnType, - String className) throws IOException { - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String outputColumnVectorType = this.getColumnVectorType(returnType); - String inputColumnVectorType1 = this.getColumnVectorType(operandType1); - String inputColumnVectorType2 = this.getColumnVectorType(operandType2); - String operatorSymbol = tdesc[4]; - String outputFile = joinPath(this.outputDirectory, className + ".java"); - - //Read the template into a string; - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", inputColumnVectorType1); - templateString = templateString.replaceAll("", inputColumnVectorType2); - templateString = templateString.replaceAll("", outputColumnVectorType); - templateString = templateString.replaceAll("", operatorSymbol); - templateString = templateString.replaceAll("", operandType1); - templateString = templateString.replaceAll("", operandType2); - templateString = templateString.replaceAll("", returnType); - templateString = templateString.replaceAll("", getCamelCaseType(returnType)); - writeFile(outputFile, templateString); - - if(returnType==null){ - testCodeGen.addColumnColumnFilterTestCases( - className, - inputColumnVectorType1, - inputColumnVectorType2, - operatorSymbol); - }else{ - testCodeGen.addColumnColumnOperationTestCases( - className, - inputColumnVectorType1, - inputColumnVectorType2, - outputColumnVectorType); - } - } - - private void generateColumnBinaryOperatorScalar(String[] tdesc, String returnType, - String className) throws IOException { - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String outputColumnVectorType = this.getColumnVectorType(returnType); - String inputColumnVectorType = this.getColumnVectorType(operandType1); - String operatorSymbol = tdesc[4]; - String outputFile = joinPath(this.outputDirectory, className + ".java"); - - //Read the template into a string; - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", inputColumnVectorType); - templateString = templateString.replaceAll("", outputColumnVectorType); - templateString = templateString.replaceAll("", operatorSymbol); - templateString = templateString.replaceAll("", operandType1); - templateString = templateString.replaceAll("", operandType2); - templateString = templateString.replaceAll("", returnType); - writeFile(outputFile, templateString); - - if(returnType==null) { - testCodeGen.addColumnScalarFilterTestCases( - true, - className, - inputColumnVectorType, - operandType2, - operatorSymbol); - } else { - testCodeGen.addColumnScalarOperationTestCases( - true, - className, - inputColumnVectorType, - outputColumnVectorType, - operandType2); - } - } - - private void generateScalarBinaryOperatorColumn(String[] tdesc, String returnType, - String className) throws IOException { - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String outputColumnVectorType = this.getColumnVectorType(returnType); - String inputColumnVectorType = this.getColumnVectorType(operandType2); - String operatorSymbol = tdesc[4]; - String outputFile = joinPath(this.outputDirectory, className + ".java"); - - //Read the template into a string; - String templateFile = joinPath(this.templateDirectory, tdesc[0] + ".txt"); - String templateString = readFile(templateFile); - templateString = templateString.replaceAll("", className); - templateString = templateString.replaceAll("", inputColumnVectorType); - templateString = templateString.replaceAll("", outputColumnVectorType); - templateString = templateString.replaceAll("", operatorSymbol); - templateString = templateString.replaceAll("", operandType1); - templateString = templateString.replaceAll("", operandType2); - templateString = templateString.replaceAll("", returnType); - writeFile(outputFile, templateString); - - if(returnType==null) { - testCodeGen.addColumnScalarFilterTestCases( - false, - className, - inputColumnVectorType, - operandType1, - operatorSymbol); - } else { - testCodeGen.addColumnScalarOperationTestCases( - false, - className, - inputColumnVectorType, - outputColumnVectorType, - operandType1); - } - } - - //Binary arithmetic operator - private void generateColumnArithmeticScalar(String[] tdesc) throws IOException { - String operatorName = tdesc[1]; - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String className = getCamelCaseType(operandType1) - + "Col" + operatorName + getCamelCaseType(operandType2) + "Scalar"; - String returnType = getArithmeticReturnType(operandType1, operandType2); - generateColumnBinaryOperatorScalar(tdesc, returnType, className); - } - - private void generateScalarArithmeticColumn(String[] tdesc) throws IOException { - String operatorName = tdesc[1]; - String operandType1 = tdesc[2]; - String operandType2 = tdesc[3]; - String className = getCamelCaseType(operandType1) - + "Scalar" + operatorName + getCamelCaseType(operandType2) + "Column"; - String returnType = getArithmeticReturnType(operandType1, operandType2); - generateScalarBinaryOperatorColumn(tdesc, returnType, className); - } - - - static void writeFile(String outputFile, String str) throws IOException { - BufferedWriter w = new BufferedWriter(new FileWriter(outputFile)); - w.write(str); - w.close(); - } - - static String readFile(String templateFile) throws IOException { - BufferedReader r = new BufferedReader(new FileReader(templateFile)); - String line = r.readLine(); - StringBuilder b = new StringBuilder(); - while (line != null) { - b.append(line); - b.append("\n"); - line = r.readLine(); - } - r.close(); - return b.toString(); - } - - static String getCamelCaseType(String type) { - if (type == null) { - return null; - } - if (type.equals("long")) { - return "Long"; - } else if (type.equals("double")) { - return "Double"; - } else { - return type; - } - } - - private String getArithmeticReturnType(String operandType1, - String operandType2) { - if (operandType1.equals("double") || - operandType2.equals("double")) { - return "double"; - } else { - return "long"; - } - } - - private String getColumnVectorType(String primitiveType) { - if(primitiveType!=null && primitiveType.equals("double")) { - return "DoubleColumnVector"; - } - return "LongColumnVector"; - } - - private String getOutputWritableType(String primitiveType) throws Exception { - if (primitiveType.equals("long")) { - return "LongWritable"; - } else if (primitiveType.equals("double")) { - return "DoubleWritable"; - } - throw new Exception("Unimplemented primitive output writable: " + primitiveType); - } - - private String getOutputObjectInspector(String primitiveType) throws Exception { - if (primitiveType.equals("long")) { - return "PrimitiveObjectInspectorFactory.writableLongObjectInspector"; - } else if (primitiveType.equals("double")) { - return "PrimitiveObjectInspectorFactory.writableDoubleObjectInspector"; - } - throw new Exception("Unimplemented primitive output inspector: " + primitiveType); - } -} - diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnArithmeticColumn.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnArithmeticColumn.txt deleted file mode 100644 index 2ab4aec..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnArithmeticColumn.txt +++ /dev/null @@ -1,157 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil; -import org.apache.hadoop.hive.ql.exec.vector.*; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * Generated from template ColumnArithmeticColumn.txt, which covers binary arithmetic - * expressions between columns. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum1; - private int colNum2; - private int outputColumn; - - public (int colNum1, int colNum2, int outputColumn) { - this.colNum1 = colNum1; - this.colNum2 = colNum2; - this.outputColumn = outputColumn; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - inputColVector1 = () batch.cols[colNum1]; - inputColVector2 = () batch.cols[colNum2]; - outputColVector = () batch.cols[outputColumn]; - int[] sel = batch.selected; - int n = batch.size; - [] vector1 = inputColVector1.vector; - [] vector2 = inputColVector2.vector; - [] outputVector = outputColVector.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - outputColVector.isRepeating = - inputColVector1.isRepeating && inputColVector2.isRepeating - || inputColVector1.isRepeating && !inputColVector1.noNulls && inputColVector1.isNull[0] - || inputColVector2.isRepeating && !inputColVector2.noNulls && inputColVector2.isNull[0]; - - // Handle nulls first - NullUtil.propagateNullsColCol( - inputColVector1, inputColVector2, outputColVector, sel, n, batch.selectedInUse); - - /* Disregard nulls for processing. In other words, - * the arithmetic operation is performed even if one or - * more inputs are null. This is to improve speed by avoiding - * conditional checks in the inner loop. - */ - if (inputColVector1.isRepeating && inputColVector2.isRepeating) { - outputVector[0] = vector1[0] vector2[0]; - } else if (inputColVector1.isRepeating) { - if (batch.selectedInUse) { - for(int j = 0; j != n; j++) { - int i = sel[j]; - outputVector[i] = vector1[0] vector2[i]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = vector1[0] vector2[i]; - } - } - } else if (inputColVector2.isRepeating) { - if (batch.selectedInUse) { - for(int j = 0; j != n; j++) { - int i = sel[j]; - outputVector[i] = vector1[i] vector2[0]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = vector1[i] vector2[0]; - } - } - } else { - if (batch.selectedInUse) { - for(int j = 0; j != n; j++) { - int i = sel[j]; - outputVector[i] = vector1[i] vector2[i]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = vector1[i] vector2[i]; - } - } - } - - /* For the case when the output can have null values, follow - * the convention that the data values must be 1 for long and - * NaN for double. This is to prevent possible later zero-divide errors - * in complex arithmetic expressions like col2 / (col1 - 1) - * in the case when some col1 entries are null. - */ - NullUtil.setNullDataEntries(outputColVector, batch.selectedInUse, sel, n); - } - - @Override - public int getOutputColumn() { - return outputColumn; - } - - @Override - public String getOutputType() { - return ""; - } - - public int getColNum1() { - return colNum1; - } - - public void setColNum1(int colNum1) { - this.colNum1 = colNum1; - } - - public int getColNum2() { - return colNum2; - } - - public void setColNum2(int colNum2) { - this.colNum2 = colNum2; - } - - public void setOutputColumn(int outputColumn) { - this.outputColumn = outputColumn; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnArithmeticScalar.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnArithmeticScalar.txt deleted file mode 100644 index 35890f8..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnArithmeticScalar.txt +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.; -import org.apache.hadoop.hive.ql.exec.vector.; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil; - -/** - * Generated from template ColumnArithmeticScalar.txt, which covers binary arithmetic - * expressions between a column and a scalar. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private value; - private int outputColumn; - - public (int colNum, value, int outputColumn) { - this.colNum = colNum; - this.value = value; - this.outputColumn = outputColumn; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - inputColVector = () batch.cols[colNum]; - outputColVector = () batch.cols[outputColumn]; - int[] sel = batch.selected; - boolean[] inputIsNull = inputColVector.isNull; - boolean[] outputIsNull = outputColVector.isNull; - outputColVector.noNulls = inputColVector.noNulls; - outputColVector.isRepeating = inputColVector.isRepeating; - int n = batch.size; - [] vector = inputColVector.vector; - [] outputVector = outputColVector.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector.isRepeating) { - outputVector[0] = vector[0] value; - - // Even if there are no nulls, we always copy over entry 0. Simplifies code. - outputIsNull[0] = inputIsNull[0]; - } else if (inputColVector.noNulls) { - if (batch.selectedInUse) { - for(int j = 0; j != n; j++) { - int i = sel[j]; - outputVector[i] = vector[i] value; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = vector[i] value; - } - } - } else /* there are nulls */ { - if (batch.selectedInUse) { - for(int j = 0; j != n; j++) { - int i = sel[j]; - outputVector[i] = vector[i] value; - outputIsNull[i] = inputIsNull[i]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = vector[i] value; - } - System.arraycopy(inputIsNull, 0, outputIsNull, 0, n); - } - } - - NullUtil.setNullOutputEntriesColScalar(outputColVector, batch.selectedInUse, sel, n); - } - - @Override - public int getOutputColumn() { - return outputColumn; - } - - @Override - public String getOutputType() { - return ""; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public getValue() { - return value; - } - - public void setValue( value) { - this.value = value; - } - - public void setOutputColumn(int outputColumn) { - this.outputColumn = outputColumn; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnCompareScalar.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnCompareScalar.txt deleted file mode 100644 index e333224..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnCompareScalar.txt +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.; -import org.apache.hadoop.hive.ql.exec.vector.; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * Generated from template ColumnCompareScalar.txt, which covers binary comparison - * expressions between a column and a scalar. The boolean output is stored in a - * separate boolean column. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private value; - private int outputColumn; - - public (int colNum, value, int outputColumn) { - this.colNum = colNum; - this.value = value; - this.outputColumn = outputColumn; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - inputColVector = () batch.cols[colNum]; - outputColVector = () batch.cols[outputColumn]; - int[] sel = batch.selected; - boolean[] nullPos = inputColVector.isNull; - boolean[] outNulls = outputColVector.isNull; - int n = batch.size; - [] vector = inputColVector.vector; - [] outputVector = outputColVector.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - outputColVector.isRepeating = false; - outputColVector.noNulls = inputColVector.noNulls; - if (inputColVector.noNulls) { - if (inputColVector.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - outputVector[0] = vector[0] value ? 1 : 0; - outputColVector.isRepeating = true; - } else if (batch.selectedInUse) { - for(int j=0; j != n; j++) { - int i = sel[j]; - outputVector[i] = vector[i] value ? 1 : 0; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = vector[i] value ? 1 : 0; - } - } - } else { - if (inputColVector.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - if (!nullPos[0]) { - outputVector[0] = vector[0] value ? 1 : 0; - outNulls[0] = false; - } else { - outNulls[0] = true; - } - outputColVector.isRepeating = true; - } else if (batch.selectedInUse) { - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos[i]) { - outputVector[i] = vector[i] value ? 1 : 0; - outNulls[i] = false; - } else { - //comparison with null is null - outNulls[i] = true; - } - } - } else { - System.arraycopy(nullPos, 0, outNulls, 0, n); - for(int i = 0; i != n; i++) { - if (!nullPos[i]) { - outputVector[i] = vector[i] value ? 1 : 0; - } - } - } - } - } - - @Override - public int getOutputColumn() { - return outputColumn; - } - - @Override - public String getOutputType() { - return ""; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public getValue() { - return value; - } - - public void setValue( value) { - this.value = value; - } - - public void setOutputColumn(int outputColumn) { - this.outputColumn = outputColumn; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnUnaryMinus.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnUnaryMinus.txt deleted file mode 100644 index 085145a..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ColumnUnaryMinus.txt +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.*; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * Generated from template ColumnUnaryMinus.txt, which covers unary negation operator. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private int outputColumn; - - public (int colNum, int outputColumn) { - this.colNum = colNum; - this.outputColumn = outputColumn; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - this.evaluateChildren(batch); - } - - inputColVector = () batch.cols[colNum]; - outputColVector = () batch.cols[outputColumn]; - int[] sel = batch.selected; - boolean[] inputIsNull = inputColVector.isNull; - boolean[] outputIsNull = outputColVector.isNull; - outputColVector.noNulls = inputColVector.noNulls; - int n = batch.size; - [] vector = inputColVector.vector; - [] outputVector = outputColVector.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - outputVector[0] = - vector[0]; - // Even if there are no nulls, we always copy over entry 0. Simplifies code. - outputIsNull[0] = inputIsNull[0]; - outputColVector.isRepeating = true; - } else if (inputColVector.noNulls) { - if (batch.selectedInUse) { - for(int j=0; j != n; j++) { - int i = sel[j]; - outputVector[i] = -vector[i]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = -vector[i]; - } - } - outputColVector.isRepeating = false; - } else /* there are nulls */ { - if (batch.selectedInUse) { - for(int j=0; j != n; j++) { - int i = sel[j]; - outputVector[i] = -vector[i]; - outputIsNull[i] = inputIsNull[i]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = -vector[i]; - } - System.arraycopy(inputIsNull, 0, outputIsNull, 0, n); - } - outputColVector.isRepeating = false; - } - } - - @Override - public int getOutputColumn() { - return outputColumn; - } - - @Override - public String getOutputType() { - return ""; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public void setOutputColumn(int outputColumn) { - this.outputColumn = outputColumn; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterColumnCompareColumn.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterColumnCompareColumn.txt deleted file mode 100644 index 1c16816..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterColumnCompareColumn.txt +++ /dev/null @@ -1,254 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.*; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * Generated from template FilterColumnCompareColumn.txt, which covers binary comparison - * expressions between two columns, however output is not produced in a separate column. - * The selected vector of the input {@link VectorizedRowBatch} is updated for in-place filtering. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum1; - private int colNum2; - - public (int colNum1, int colNum2) { - this.colNum1 = colNum1; - this.colNum2 = colNum2; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - inputColVector1 = () batch.cols[colNum1]; - inputColVector2 = () batch.cols[colNum2]; - int[] sel = batch.selected; - boolean[] nullPos1 = inputColVector1.isNull; - boolean[] nullPos2 = inputColVector2.isNull; - int n = batch.size; - [] vector1 = inputColVector1.vector; - [] vector2 = inputColVector2.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector1.noNulls && inputColVector2.noNulls) { - if (inputColVector1.isRepeating && inputColVector2.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - if (!(vector1[0] vector2[0])) { - batch.size = 0; - } - } else if (inputColVector1.isRepeating) { - if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (vector1[0] vector2[i]) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (vector1[0] vector2[i]) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (inputColVector2.isRepeating) { - if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (vector1[i] vector2[0]) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (vector1[i] vector2[0]) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (vector1[i] vector2[i]) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (vector1[i] vector2[i]) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (inputColVector1.isRepeating && inputColVector2.isRepeating) { - if (nullPos1[0] || nullPos2[0]) { - batch.size = 0; - } - } else if (inputColVector1.isRepeating) { - if (nullPos1[0]) { - batch.size = 0; - } else { - if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos2[i]) { - if (vector1[0] vector2[i]) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos2[i]) { - if (vector1[0] vector2[i]) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - } else if (inputColVector2.isRepeating) { - if (nullPos2[0]) { - batch.size = 0; - } else { - if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos1[i]) { - if (vector1[i] vector2[0]) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos1[i]) { - if (vector1[i] vector2[0]) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos1[i] && !nullPos2[i]) { - if (vector1[i] vector2[i]) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos1[i] && !nullPos2[i]) { - if (vector1[i] vector2[i]) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - - @Override - public String getOutputType() { - return "boolean"; - } - - @Override - public int getOutputColumn() { - return -1; - } - - public int getColNum1() { - return colNum1; - } - - public void setColNum1(int colNum1) { - this.colNum1 = colNum1; - } - - public int getColNum2() { - return colNum2; - } - - public void setColNum2(int colNum2) { - this.colNum2 = colNum2; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterColumnCompareScalar.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterColumnCompareScalar.txt deleted file mode 100644 index bf02419..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterColumnCompareScalar.txt +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * Generated from template FilterColumnCompareScalar.txt, which covers binary comparison - * expressions between a column and a scalar, however output is not produced in a separate column. - * The selected vector of the input {@link VectorizedRowBatch} is updated for in-place filtering. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private value; - - public (int colNum, value) { - this.colNum = colNum; - this.value = value; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - inputColVector = () batch.cols[colNum]; - int[] sel = batch.selected; - boolean[] nullPos = inputColVector.isNull; - int n = batch.size; - [] vector = inputColVector.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector.noNulls) { - if (inputColVector.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - if (!(vector[0] value)) { - //Entire batch is filtered out. - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (vector[i] value) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (vector[i] value) { - sel[newSize++] = i; - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else { - if (inputColVector.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - if (!nullPos[0]) { - if (!(vector[0] value)) { - //Entire batch is filtered out. - batch.size = 0; - } - } else { - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos[i]) { - if (vector[i] value) { - sel[newSize++] = i; - } - } - } - //Change the selected vector - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos[i]) { - if (vector[i] value) { - sel[newSize++] = i; - } - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - } - - @Override - public int getOutputColumn() { - return -1; - } - - @Override - public String getOutputType() { - return "boolean"; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public getValue() { - return value; - } - - public void setValue( value) { - this.value = value; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterScalarCompareColumn.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterScalarCompareColumn.txt deleted file mode 100644 index 9a1d741..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterScalarCompareColumn.txt +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * Generated from template FilterScalarCompareColumn.txt, which covers binary comparison - * expressions between a scalar and a column, however output is not produced in a separate column. - * The selected vector of the input {@link VectorizedRowBatch} is updated for in-place filtering. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private value; - - public (int colNum, value) { - this.colNum = colNum; - this.value = value; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - inputColVector = () batch.cols[colNum]; - int[] sel = batch.selected; - boolean[] nullPos = inputColVector.isNull; - int n = batch.size; - [] vector = inputColVector.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector.noNulls) { - if (inputColVector.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - if (!(value vector[0])) { - //Entire batch is filtered out. - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (value vector[i]) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (value vector[i]) { - sel[newSize++] = i; - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else { - if (inputColVector.isRepeating) { - //All must be selected otherwise size would be zero - //Repeating property will not change. - if (!nullPos[0]) { - if (!(value vector[0])) { - //Entire batch is filtered out. - batch.size = 0; - } - } else { - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos[i]) { - if (value vector[i]) { - sel[newSize++] = i; - } - } - } - //Change the selected vector - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos[i]) { - if (value vector[i]) { - sel[newSize++] = i; - } - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - } - - @Override - public int getOutputColumn() { - return -1; - } - - @Override - public String getOutputType() { - return "boolean"; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public getValue() { - return value; - } - - public void setValue( value) { - this.value = value; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareColumn.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareColumn.txt deleted file mode 100644 index 449c010..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareColumn.txt +++ /dev/null @@ -1,477 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; -import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * Filter the rows in a batch by comparing one string column to another. - * This code is generated from a template. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum1; - private int colNum2; - - public (int colNum1, int colNum2) { - this.colNum1 = colNum1; - this.colNum2 = colNum2; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - BytesColumnVector inputColVector1 = (BytesColumnVector) batch.cols[colNum1]; - BytesColumnVector inputColVector2 = (BytesColumnVector) batch.cols[colNum2]; - int[] sel = batch.selected; - boolean[] nullPos1 = inputColVector1.isNull; - boolean[] nullPos2 = inputColVector2.isNull; - int n = batch.size; - byte[][] vector1 = inputColVector1.vector; - byte[][] vector2 = inputColVector2.vector; - int[] start1 = inputColVector1.start; - int[] start2 = inputColVector2.start; - int[] length1 = inputColVector1.length; - int[] length2 = inputColVector2.length; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - // handle case where neither input has nulls - if (inputColVector1.noNulls && inputColVector2.noNulls) { - if (inputColVector1.isRepeating && inputColVector2.isRepeating) { - - /* Either all must remain selected or all will be eliminated. - * Repeating property will not change. - */ - if (!(StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[0], start2[0], length2[0]) 0)) { - batch.size = 0; - } - } else if (inputColVector1.isRepeating) { - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (inputColVector2.isRepeating) { - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - - // handle case where only input 2 has nulls - } else if (inputColVector1.noNulls) { - if (inputColVector1.isRepeating && inputColVector2.isRepeating) { - if (nullPos2[0] || - !(StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[0], start2[0], length2[0]) 0)) { - batch.size = 0; - } - } else if (inputColVector1.isRepeating) { - - // no need to check for nulls in input 1 - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (!nullPos2[i]) { - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos2[i]) { - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (inputColVector2.isRepeating) { - if (nullPos2[0]) { - - // no values will qualify because every comparison will be with NULL - batch.size = 0; - return; - } - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else { // neither input is repeating - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (!nullPos2[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos2[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - - // handle case where only input 1 has nulls - } else if (inputColVector2.noNulls) { - if (inputColVector1.isRepeating && inputColVector2.isRepeating) { - if (nullPos1[0] || - !(StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[0], start2[0], length2[0]) 0)) { - batch.size = 0; - return; - } - } else if (inputColVector1.isRepeating) { - if (nullPos1[0]) { - - // if repeating value is null then every comparison will fail so nothing qualifies - batch.size = 0; - return; - } - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (inputColVector2.isRepeating) { - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (!nullPos1[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos2[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else { // neither input is repeating - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (!nullPos1[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos1[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - - // handle case where both inputs have nulls - } else { - if (inputColVector1.isRepeating && inputColVector2.isRepeating) { - if (nullPos1[0] || nullPos2[0] || - !(StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[0], start2[0], length2[0]) 0)) { - batch.size = 0; - } - } else if (inputColVector1.isRepeating) { - if (nullPos1[0]) { - batch.size = 0; - return; - } - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (!nullPos2[i]) { - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos2[i]) { - if (StringExpr.compare(vector1[0], start1[0], length1[0], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else if (inputColVector2.isRepeating) { - if (nullPos2[0]) { - batch.size = 0; - return; - } - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (!nullPos1[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos1[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[0], start2[0], length2[0]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else { // neither input is repeating - if (batch.selectedInUse) { - int newSize = 0; - for(int j = 0; j != n; j++) { - int i = sel[j]; - if (!nullPos1[i] && !nullPos2[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos1[i] && !nullPos2[i]) { - if (StringExpr.compare(vector1[i], start1[i], length1[i], - vector2[i], start2[i], length2[i]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < batch.size) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - } - } - - @Override - public String getOutputType() { - return "boolean"; - } - - @Override - public int getOutputColumn() { - return -1; - } - - public int getColNum1() { - return colNum1; - } - - public void setColNum1(int colNum1) { - this.colNum1 = colNum1; - } - - public int getColNum2() { - return colNum2; - } - - public void setColNum2(int colNum2) { - this.colNum2 = colNum2; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareScalar.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareScalar.txt deleted file mode 100644 index 690dd3c..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringColumnCompareScalar.txt +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; -import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * This is a generated class to evaluate a comparison on a vector of strings. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private byte[] value; - - public (int colNum, byte[] value) { - this.colNum = colNum; - this.value = value; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - if (childExpressions != null) { - super.evaluateChildren(batch); - } - BytesColumnVector inputColVector = (BytesColumnVector) batch.cols[colNum]; - int[] sel = batch.selected; - boolean[] nullPos = inputColVector.isNull; - int n = batch.size; - byte[][] vector = inputColVector.vector; - int[] length = inputColVector.length; - int[] start = inputColVector.start; - - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector.noNulls) { - if (inputColVector.isRepeating) { - - // All must be selected otherwise size would be zero. Repeating property will not change. - if (!(StringExpr.compare(vector[0], start[0], length[0], value, 0, value.length) 0)) { - - //Entire batch is filtered out. - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { - sel[newSize++] = i; - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else { - if (inputColVector.isRepeating) { - - // All must be selected otherwise size would be zero. Repeating property will not change. - if (!nullPos[0]) { - if (!(StringExpr.compare(vector[0], start[0], length[0], value, 0, value.length) 0)) { - - //Entire batch is filtered out. - batch.size = 0; - } - } else { - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos[i]) { - if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { - sel[newSize++] = i; - } - } - } - - //Change the selected vector - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos[i]) { - if (StringExpr.compare(vector[i], start[i], length[i], value, 0, value.length) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - } - - @Override - public int getOutputColumn() { - return -1; - } - - @Override - public String getOutputType() { - return "boolean"; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public byte[] getValue() { - return value; - } - - public void setValue(byte[] value) { - this.value = value; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringScalarCompareColumn.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringScalarCompareColumn.txt deleted file mode 100644 index 5ba7703..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/FilterStringScalarCompareColumn.txt +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; -import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; - -/** - * This is a generated class to evaluate a comparison on a vector of strings. - * Do not edit the generated code directly. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private byte[] value; - - public (int colNum, byte[] value) { - this.colNum = colNum; - this.value = value; - } - - public () { - } - - @Override - public void evaluate(VectorizedRowBatch batch) { - if (childExpressions != null) { - super.evaluateChildren(batch); - } - BytesColumnVector inputColVector = (BytesColumnVector) batch.cols[colNum]; - int[] sel = batch.selected; - boolean[] nullPos = inputColVector.isNull; - int n = batch.size; - byte[][] vector = inputColVector.vector; - int[] length = inputColVector.length; - int[] start = inputColVector.start; - - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector.noNulls) { - if (inputColVector.isRepeating) { - - // All must be selected otherwise size would be zero. Repeating property will not change. - if (!(StringExpr.compare(value, 0, value.length, vector[0], start[0], length[0]) 0)) { - - //Entire batch is filtered out. - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { - sel[newSize++] = i; - } - } - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { - sel[newSize++] = i; - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } else { - if (inputColVector.isRepeating) { - - // All must be selected otherwise size would be zero. Repeating property will not change. - if (!nullPos[0]) { - if (!(StringExpr.compare(value, 0, value.length, vector[0], start[0], length[0]) 0)) { - - //Entire batch is filtered out. - batch.size = 0; - } - } else { - batch.size = 0; - } - } else if (batch.selectedInUse) { - int newSize = 0; - for(int j=0; j != n; j++) { - int i = sel[j]; - if (!nullPos[i]) { - if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { - sel[newSize++] = i; - } - } - } - - //Change the selected vector - batch.size = newSize; - } else { - int newSize = 0; - for(int i = 0; i != n; i++) { - if (!nullPos[i]) { - if (StringExpr.compare(value, 0, value.length, vector[i], start[i], length[i]) 0) { - sel[newSize++] = i; - } - } - } - if (newSize < n) { - batch.size = newSize; - batch.selectedInUse = true; - } - } - } - } - - @Override - public int getOutputColumn() { - return -1; - } - - @Override - public String getOutputType() { - return "boolean"; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public byte[] getValue() { - return value; - } - - public void setValue(byte[] value) { - this.value = value; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ScalarArithmeticColumn.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ScalarArithmeticColumn.txt deleted file mode 100644 index d9efbe7..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/ScalarArithmeticColumn.txt +++ /dev/null @@ -1,147 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; - -/* - * Because of the templatized nature of the code, either or both - * of these ColumnVector imports may be needed. Listing both of them - * rather than using ....vectorization.*; - */ -import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil; - -/** - * Generated from template ScalarArithmeticColumn.txt. - * Implements a vectorized arithmetic operator with a scalar on the left and a - * column vector on the right. The result is output to an output column vector. - */ -public class extends VectorExpression { - - private static final long serialVersionUID = 1L; - - private int colNum; - private value; - private int outputColumn; - - public ( value, int colNum, int outputColumn) { - this.colNum = colNum; - this.value = value; - this.outputColumn = outputColumn; - } - - public () { - } - - @Override - /** - * Method to evaluate scalar-column operation in vectorized fashion. - * - * @batch a package of rows with each column stored in a vector - */ - public void evaluate(VectorizedRowBatch batch) { - - if (childExpressions != null) { - super.evaluateChildren(batch); - } - - inputColVector = () batch.cols[colNum]; - outputColVector = () batch.cols[outputColumn]; - int[] sel = batch.selected; - boolean[] inputIsNull = inputColVector.isNull; - boolean[] outputIsNull = outputColVector.isNull; - outputColVector.noNulls = inputColVector.noNulls; - outputColVector.isRepeating = inputColVector.isRepeating; - int n = batch.size; - [] vector = inputColVector.vector; - [] outputVector = outputColVector.vector; - - // return immediately if batch is empty - if (n == 0) { - return; - } - - if (inputColVector.isRepeating) { - outputVector[0] = value vector[0]; - - // Even if there are no nulls, we always copy over entry 0. Simplifies code. - outputIsNull[0] = inputIsNull[0]; - } else if (inputColVector.noNulls) { - if (batch.selectedInUse) { - for(int j = 0; j != n; j++) { - int i = sel[j]; - outputVector[i] = value vector[i]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = value vector[i]; - } - } - } else { /* there are nulls */ - if (batch.selectedInUse) { - for(int j = 0; j != n; j++) { - int i = sel[j]; - outputVector[i] = value vector[i]; - outputIsNull[i] = inputIsNull[i]; - } - } else { - for(int i = 0; i != n; i++) { - outputVector[i] = value vector[i]; - } - System.arraycopy(inputIsNull, 0, outputIsNull, 0, n); - } - } - - NullUtil.setNullOutputEntriesColScalar(outputColVector, batch.selectedInUse, sel, n); - } - - @Override - public int getOutputColumn() { - return outputColumn; - } - - @Override - public String getOutputType() { - return ""; - } - - public int getColNum() { - return colNum; - } - - public void setColNum(int colNum) { - this.colNum = colNum; - } - - public getValue() { - return value; - } - - public void setValue( value) { - this.value = value; - } - - public void setOutputColumn(int outputColumn) { - this.outputColumn = outputColumn; - } - -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestClass.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestClass.txt deleted file mode 100644 index c8de5de..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestClass.txt +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.gen; - -import static org.junit.Assert.assertEquals; -import java.util.Random; -import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.util.VectorizedRowGroupGenUtil; -import org.junit.Test; - - -/** - * - * . - * - */ -public class { - - private static final int BATCH_SIZE = 100; - private static final long SEED = 0xfa57; - - - -} - - diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestCodeGen.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestCodeGen.java deleted file mode 100644 index 34c093c..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestCodeGen.java +++ /dev/null @@ -1,256 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.templates; - -import java.io.IOException; -import java.util.HashMap; - -/** - * - * TestCodeGen. - * This class is mutable and maintains a hashmap of TestSuiteClassName to test cases. - * The tests cases are added over the course of vectorized expressions class generation, - * with test classes being outputted at the end. For each column vector (inputs and/or outputs) - * a matrix of pairwise covering Booleans is used to generate test cases across nulls and - * repeating dimensions. Based on the input column vector(s) nulls and repeating states - * the states of the output column vector (if there is one) is validated, along with the null - * vector. For filter operations the selection vector is validated against the generated - * data. Each template corresponds to a class representing a test suite. - */ -public class TestCodeGen { - - public enum TestSuiteClassName{ - TestColumnScalarOperationVectorExpressionEvaluation, - TestColumnScalarFilterVectorExpressionEvaluation, - TestColumnColumnOperationVectorExpressionEvaluation, - TestColumnColumnFilterVectorExpressionEvaluation, - } - - private final String testOutputDir; - private final String templateDirectory; - private final HashMap testsuites; - - public TestCodeGen(String testOutputDir, String templateDirectory) { - this.testOutputDir = testOutputDir; - this.templateDirectory = templateDirectory; - testsuites = new HashMap(); - - for(TestSuiteClassName className : TestSuiteClassName.values()) { - testsuites.put(className,new StringBuilder()); - } - - } - - public void addColumnScalarOperationTestCases(boolean op1IsCol, String vectorExpClassName, - String inputColumnVectorType, String outputColumnVectorType, String scalarType) - throws IOException { - - TestSuiteClassName template = - TestSuiteClassName.TestColumnScalarOperationVectorExpressionEvaluation; - - //Read the template into a string; - String templateFile = CodeGen.joinPath(this.templateDirectory,template.toString()+".txt"); - String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); - - for(Boolean[] testMatrix :new Boolean[][]{ - // Pairwise: InitOuputColHasNulls, InitOuputColIsRepeating, ColumnHasNulls, ColumnIsRepeating - {false, true, true, true}, - {false, false, false, false}, - {true, false, true, false}, - {true, true, false, false}, - {true, false, false, true}}) { - String testCase = templateString; - testCase = testCase.replaceAll("", - "test" - + vectorExpClassName - + createNullRepeatingNameFragment("Out", testMatrix[0], testMatrix[1]) - + createNullRepeatingNameFragment("Col", testMatrix[2], testMatrix[3])); - testCase = testCase.replaceAll("", vectorExpClassName); - testCase = testCase.replaceAll("", inputColumnVectorType); - testCase = testCase.replaceAll("", outputColumnVectorType); - testCase = testCase.replaceAll("", scalarType); - testCase = testCase.replaceAll("", CodeGen.getCamelCaseType(scalarType)); - testCase = testCase.replaceAll("", testMatrix[0].toString()); - testCase = testCase.replaceAll("", testMatrix[1].toString()); - testCase = testCase.replaceAll("", testMatrix[2].toString()); - testCase = testCase.replaceAll("", testMatrix[3].toString()); - - if(op1IsCol){ - testCase = testCase.replaceAll("","0, scalarValue"); - }else{ - testCase = testCase.replaceAll("","scalarValue, 0"); - } - - testsuites.get(template).append(testCase); - } - } - - public void addColumnScalarFilterTestCases(boolean op1IsCol, String vectorExpClassName, - String inputColumnVectorType, String scalarType, String operatorSymbol) - throws IOException { - - TestSuiteClassName template = - TestSuiteClassName.TestColumnScalarFilterVectorExpressionEvaluation; - - //Read the template into a string; - String templateFile = CodeGen.joinPath(this.templateDirectory,template.toString()+".txt"); - String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); - - for(Boolean[] testMatrix : new Boolean[][]{ - // Pairwise: ColumnHasNulls, ColumnIsRepeating - {true, true}, - {true, false}, - {false, false}, - {false, true}}) { - String testCase = templateString; - testCase = testCase.replaceAll("", - "test" - + vectorExpClassName - + createNullRepeatingNameFragment("Col", testMatrix[0], testMatrix[1])); - testCase = testCase.replaceAll("", vectorExpClassName); - testCase = testCase.replaceAll("", inputColumnVectorType); - testCase = testCase.replaceAll("", scalarType); - testCase = testCase.replaceAll("", CodeGen.getCamelCaseType(scalarType)); - testCase = testCase.replaceAll("", testMatrix[0].toString()); - testCase = testCase.replaceAll("", testMatrix[1].toString()); - testCase = testCase.replaceAll("", operatorSymbol); - - if(op1IsCol){ - testCase = testCase.replaceAll("","0, scalarValue"); - }else{ - testCase = testCase.replaceAll("","scalarValue, 0"); - } - - testsuites.get(template).append(testCase); - } - } - - public void addColumnColumnOperationTestCases(String vectorExpClassName, - String inputColumnVectorType1, String inputColumnVectorType2, String outputColumnVectorType) - throws IOException { - - TestSuiteClassName template= - TestSuiteClassName.TestColumnColumnOperationVectorExpressionEvaluation; - - //Read the template into a string; - String templateFile = CodeGen.joinPath(this.templateDirectory,template.toString()+".txt"); - String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); - - for(Boolean[] testMatrix : new Boolean[][]{ - // Pairwise: InitOuputColHasNulls, InitOuputColIsRepeating, Column1HasNulls, - // Column1IsRepeating, Column2HasNulls, Column2IsRepeating - {true, true, false, true, true, true}, - {false, false, true, false, false, false}, - {true, false, true, false, true, true}, - {true, true, true, true, false, false}, - {false, false, false, true, true, false}, - {false, true, false, false, false, true}}) { - String testCase = templateString; - testCase = testCase.replaceAll("", - "test" - + vectorExpClassName - + createNullRepeatingNameFragment("Out", testMatrix[0], testMatrix[1]) - + createNullRepeatingNameFragment("C1", testMatrix[2], testMatrix[3]) - + createNullRepeatingNameFragment("C2", testMatrix[4], testMatrix[5])); - testCase = testCase.replaceAll("", vectorExpClassName); - testCase = testCase.replaceAll("", inputColumnVectorType1); - testCase = testCase.replaceAll("", inputColumnVectorType2); - testCase = testCase.replaceAll("", outputColumnVectorType); - testCase = testCase.replaceAll("", testMatrix[0].toString()); - testCase = testCase.replaceAll("", testMatrix[1].toString()); - testCase = testCase.replaceAll("", testMatrix[2].toString()); - testCase = testCase.replaceAll("", testMatrix[3].toString()); - testCase = testCase.replaceAll("", testMatrix[4].toString()); - testCase = testCase.replaceAll("", testMatrix[5].toString()); - - testsuites.get(template).append(testCase); - } - } - - public void addColumnColumnFilterTestCases(String vectorExpClassName, - String inputColumnVectorType1, String inputColumnVectorType2, String operatorSymbol) - throws IOException { - - TestSuiteClassName template= - TestSuiteClassName.TestColumnColumnFilterVectorExpressionEvaluation; - - //Read the template into a string; - String templateFile = CodeGen.joinPath(this.templateDirectory,template.toString()+".txt"); - String templateString = removeTemplateComments(CodeGen.readFile(templateFile)); - - for(Boolean[] testMatrix : new Boolean[][]{ - // Pairwise: Column1HasNulls, Column1IsRepeating, Column2HasNulls, Column2IsRepeating - {false, true, true, true}, - {false, false, false, false}, - {true, false, true, false}, - {true, true, false, false}, - {true, false, false, true}}) { - String testCase = templateString; - testCase = testCase.replaceAll("", - "test" - + vectorExpClassName - + createNullRepeatingNameFragment("C1", testMatrix[0], testMatrix[1]) - + createNullRepeatingNameFragment("C2", testMatrix[2], testMatrix[3])); - testCase = testCase.replaceAll("", vectorExpClassName); - testCase = testCase.replaceAll("", inputColumnVectorType1); - testCase = testCase.replaceAll("", inputColumnVectorType2); - testCase = testCase.replaceAll("", testMatrix[0].toString()); - testCase = testCase.replaceAll("", testMatrix[1].toString()); - testCase = testCase.replaceAll("", testMatrix[2].toString()); - testCase = testCase.replaceAll("", testMatrix[3].toString()); - testCase = testCase.replaceAll("", operatorSymbol); - - testsuites.get(template).append(testCase); - } - } - - public void generateTestSuites() throws IOException { - - String templateFile = CodeGen.joinPath(this.templateDirectory, "TestClass.txt"); - for(TestSuiteClassName testClass : testsuites.keySet()) { - - String templateString = CodeGen.readFile(templateFile); - templateString = templateString.replaceAll("", testClass.toString()); - templateString = templateString.replaceAll("", testsuites.get(testClass).toString()); - - String outputFile = CodeGen.joinPath(this.testOutputDir, testClass + ".java"); - - CodeGen.writeFile(outputFile, templateString); - } - } - - private static String createNullRepeatingNameFragment(String idenitfier, boolean nulls, boolean repeating) - { - if(nulls || repeating){ - if(nulls){ - idenitfier+="Nulls"; - } - if(repeating){ - idenitfier+="Repeats"; - } - return idenitfier; - } - - return ""; - } - - private static String removeTemplateComments(String templateString){ - return templateString.replaceAll("(?s)", ""); - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnColumnFilterVectorExpressionEvaluation.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnColumnFilterVectorExpressionEvaluation.txt deleted file mode 100644 index 2bb1aa3..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnColumnFilterVectorExpressionEvaluation.txt +++ /dev/null @@ -1,69 +0,0 @@ - - @Test - public void () { - - Random rand = new Random(SEED); - - inputColumnVector1 = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - inputColumnVector2 = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - VectorizedRowBatch rowBatch = new VectorizedRowBatch(2, BATCH_SIZE); - rowBatch.cols[0] = inputColumnVector1; - rowBatch.cols[1] = inputColumnVector2; - - vectorExpression = - new (0, 1); - - vectorExpression.evaluate(rowBatch); - - int selectedIndex = 0; - for(int i = 0; i < BATCH_SIZE; i++) { - //null vector is safe to check, as it is always initialized to match the data vector - if(!inputColumnVector1.isNull[i] && !inputColumnVector2.isNull[i]) { - if(inputColumnVector1.vector[i] inputColumnVector2.vector[i]) { - assertEquals( - "Vector index that passes filter " - + inputColumnVector1.vector[i] + "" - + inputColumnVector2.vector[i] + " is not in rowBatch selected index", - i, - rowBatch.selected[selectedIndex]); - selectedIndex++; - } - } - } - - assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, - selectedIndex, rowBatch.size); - - if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { - assertEquals( - "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " - + selectedIndex, - true, rowBatch.selectedInUse); - } else if(selectedIndex == BATCH_SIZE) { - assertEquals( - "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " - + selectedIndex, - false, rowBatch.selectedInUse); - } - } \ No newline at end of file diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnColumnOperationVectorExpressionEvaluation.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnColumnOperationVectorExpressionEvaluation.txt deleted file mode 100644 index 4ab3e76..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnColumnOperationVectorExpressionEvaluation.txt +++ /dev/null @@ -1,64 +0,0 @@ - - @Test - public void () { - - Random rand = new Random(SEED); - - outputColumnVector = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - inputColumnVector1 = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - inputColumnVector2 = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - VectorizedRowBatch rowBatch = new VectorizedRowBatch(3, BATCH_SIZE); - rowBatch.cols[0] = inputColumnVector1; - rowBatch.cols[1] = inputColumnVector2; - rowBatch.cols[2] = outputColumnVector; - - vectorExpression = - new (0, 1, 2); - - vectorExpression.evaluate(rowBatch); - - assertEquals( - "Output column vector repeating state does not match operand columns", - (!inputColumnVector1.noNulls && inputColumnVector1.isRepeating) - || (!inputColumnVector2.noNulls && inputColumnVector2.isRepeating) - || inputColumnVector1.isRepeating && inputColumnVector2.isRepeating, - outputColumnVector.isRepeating); - - assertEquals( - "Output column vector no nulls state does not match operand columns", - inputColumnVector1.noNulls && inputColumnVector2.noNulls, outputColumnVector.noNulls); - - //if repeating, only the first value matters - if(!outputColumnVector.noNulls && !outputColumnVector.isRepeating) { - for(int i = 0; i < BATCH_SIZE; i++) { - //null vectors are safe to check, as they are always initialized to match the data vector - assertEquals("Output vector doesn't match input vectors' is null state for index", - inputColumnVector1.isNull[i] || inputColumnVector2.isNull[i], - outputColumnVector.isNull[i]); - } - } - } \ No newline at end of file diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnScalarFilterVectorExpressionEvaluation.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnScalarFilterVectorExpressionEvaluation.txt deleted file mode 100644 index 5b53d6a..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnScalarFilterVectorExpressionEvaluation.txt +++ /dev/null @@ -1,76 +0,0 @@ - - @Test - public void () { - - Random rand = new Random(SEED); - - inputColumnVector = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); - rowBatch.cols[0] = inputColumnVector; - - scalarValue = 0; - do { - scalarValue = rand.next(); - } while(scalarValue == 0); - - vectorExpression = - new (); - - vectorExpression.evaluate(rowBatch); - - int selectedIndex = 0; - //check for isRepeating optimization - if(inputColumnVector.isRepeating) { - //null vector is safe to check, as it is always initialized to match the data vector - selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] scalarValue - ? BATCH_SIZE : 0; - } else { - for(int i = 0; i < BATCH_SIZE; i++) { - if(!inputColumnVector.isNull[i]) { - if(inputColumnVector.vector[i] scalarValue) { - assertEquals( - "Vector index that passes filter " - + inputColumnVector.vector[i] + "" - + scalarValue + " is not in rowBatch selected index", - i, - rowBatch.selected[selectedIndex]); - selectedIndex++; - } - } - } - } - - assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, - selectedIndex, rowBatch.size); - - if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { - assertEquals( - "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " - + selectedIndex, - true, rowBatch.selectedInUse); - } else if(selectedIndex == BATCH_SIZE) { - assertEquals( - "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " - + selectedIndex, - false, rowBatch.selectedInUse); - } - } \ No newline at end of file diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnScalarOperationVectorExpressionEvaluation.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnScalarOperationVectorExpressionEvaluation.txt deleted file mode 100644 index e5f3f18..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/TestColumnScalarOperationVectorExpressionEvaluation.txt +++ /dev/null @@ -1,59 +0,0 @@ - - @Test - public void () { - - Random rand = new Random(SEED); - - outputColumnVector = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - inputColumnVector = - VectorizedRowGroupGenUtil.generate(, - , BATCH_SIZE, rand); - - VectorizedRowBatch rowBatch = new VectorizedRowBatch(2, BATCH_SIZE); - rowBatch.cols[0] = inputColumnVector; - rowBatch.cols[1] = outputColumnVector; - - scalarValue = 0; - do { - scalarValue = rand.next(); - } while(scalarValue == 0); - - vectorExpression = - new (, 1); - - vectorExpression.evaluate(rowBatch); - - assertEquals( - "Output column vector is repeating state does not match operand column", - inputColumnVector.isRepeating, outputColumnVector.isRepeating); - - assertEquals( - "Output column vector no nulls state does not match operand column", - inputColumnVector.noNulls, outputColumnVector.noNulls); - - if(!outputColumnVector.noNulls && !outputColumnVector.isRepeating) { - for(int i = 0; i < BATCH_SIZE; i++) { - //null vectors are safe to check, as they are always initialized to match the data vector - assertEquals("Output vector doesn't match input vector's is null state for index", - inputColumnVector.isNull[i], outputColumnVector.isNull[i]); - } - } - } \ No newline at end of file diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFAvg.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFAvg.txt deleted file mode 100644 index cb94145..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFAvg.txt +++ /dev/null @@ -1,474 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.hadoop.hive.ql.exec.Description; -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; -import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; -import org.apache.hadoop.hive.ql.metadata.HiveException; -import org.apache.hadoop.hive.ql.plan.AggregationDesc; -import org.apache.hadoop.hive.ql.util.JavaDataModel; -import org.apache.hadoop.io.LongWritable; -import org.apache.hadoop.hive.serde2.io.DoubleWritable; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; -import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; - -/** - * Generated from template VectorUDAFAvg.txt. - */ -@Description(name = "avg", - value = "_FUNC_(expr) - Returns the average value of expr (vectorized, type: )") -public class extends VectorAggregateExpression { - - private static final long serialVersionUID = 1L; - - /** class for storing the current aggregate value. */ - static class Aggregation implements AggregationBuffer { - - private static final long serialVersionUID = 1L; - - transient private double sum; - transient private long count; - transient private boolean isNull; - - public void sumValue( value) { - if (isNull) { - sum = value; - count = 1; - isNull = false; - } else { - sum += value; - count++; - } - } - - @Override - public int getVariableSize() { - throw new UnsupportedOperationException(); - } - } - - private VectorExpression inputExpression; - transient private Object[] partialResult; - transient private LongWritable resultCount; - transient private DoubleWritable resultSum; - transient private StructObjectInspector soi; - - public (VectorExpression inputExpression) { - this(); - this.inputExpression = inputExpression; - } - - public () { - super(); - partialResult = new Object[2]; - resultCount = new LongWritable(); - resultSum = new DoubleWritable(); - partialResult[0] = resultCount; - partialResult[1] = resultSum; - initPartialResultInspector(); - } - - private void initPartialResultInspector() { - List foi = new ArrayList(); - foi.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector); - foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); - List fname = new ArrayList(); - fname.add("count"); - fname.add("sum"); - soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi); - } - - private Aggregation getCurrentAggregationBuffer( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - int row) { - VectorAggregationBufferRow mySet = aggregationBufferSets[row]; - Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(bufferIndex); - return myagg; - } - - @Override - public void aggregateInputSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - VectorizedRowBatch batch) throws HiveException { - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - inputExpression.evaluate(batch); - - inputVector = ( )batch. - cols[this.inputExpression.getOutputColumn()]; - [] vector = inputVector.vector; - - if (inputVector.noNulls) { - if (inputVector.isRepeating) { - iterateNoNullsRepeatingWithAggregationSelection( - aggregationBufferSets, bufferIndex, - vector[0], batchSize); - } else { - if (batch.selectedInUse) { - iterateNoNullsSelectionWithAggregationSelection( - aggregationBufferSets, bufferIndex, - vector, batch.selected, batchSize); - } else { - iterateNoNullsWithAggregationSelection( - aggregationBufferSets, bufferIndex, - vector, batchSize); - } - } - } else { - if (inputVector.isRepeating) { - if (batch.selectedInUse) { - iterateHasNullsRepeatingSelectionWithAggregationSelection( - aggregationBufferSets, bufferIndex, - vector[0], batchSize, batch.selected, inputVector.isNull); - } else { - iterateHasNullsRepeatingWithAggregationSelection( - aggregationBufferSets, bufferIndex, - vector[0], batchSize, inputVector.isNull); - } - } else { - if (batch.selectedInUse) { - iterateHasNullsSelectionWithAggregationSelection( - aggregationBufferSets, bufferIndex, - vector, batchSize, batch.selected, inputVector.isNull); - } else { - iterateHasNullsWithAggregationSelection( - aggregationBufferSets, bufferIndex, - vector, batchSize, inputVector.isNull); - } - } - } - } - - private void iterateNoNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - value, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(value); - } - } - - private void iterateNoNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - [] values, - int[] selection, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(values[selection[i]]); - } - } - - private void iterateNoNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - [] values, - int batchSize) { - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(values[i]); - } - } - - private void iterateHasNullsRepeatingSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - value, - int batchSize, - int[] selection, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(value); - } - } - - } - - private void iterateHasNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - value, - int batchSize, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(value); - } - } - } - - private void iterateHasNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - [] values, - int batchSize, - int[] selection, - boolean[] isNull) { - - for (int j=0; j < batchSize; ++j) { - int i = selection[j]; - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - j); - myagg.sumValue(values[i]); - } - } - } - - private void iterateHasNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int bufferIndex, - [] values, - int batchSize, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(values[i]); - } - } - } - - - @Override - public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) - throws HiveException { - - inputExpression.evaluate(batch); - - inputVector = - ()batch.cols[this.inputExpression.getOutputColumn()]; - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - Aggregation myagg = (Aggregation)agg; - - [] vector = inputVector.vector; - - if (inputVector.isRepeating) { - if (inputVector.noNulls) { - if (myagg.isNull) { - myagg.isNull = false; - myagg.sum = 0; - myagg.count = 0; - } - myagg.sum += vector[0]*batchSize; - myagg.count += batchSize; - } - return; - } - - if (!batch.selectedInUse && inputVector.noNulls) { - iterateNoSelectionNoNulls(myagg, vector, batchSize); - } - else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); - } - else if (inputVector.noNulls){ - iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); - } - else { - iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); - } - } - - private void iterateSelectionHasNulls( - Aggregation myagg, - [] vector, - int batchSize, - boolean[] isNull, - int[] selected) { - - for (int j=0; j< batchSize; ++j) { - int i = selected[j]; - if (!isNull[i]) { - value = vector[i]; - if (myagg.isNull) { - myagg.isNull = false; - myagg.sum = 0; - myagg.count = 0; - } - myagg.sum += value; - myagg.count += 1; - } - } - } - - private void iterateSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize, - int[] selected) { - - if (myagg.isNull) { - myagg.isNull = false; - myagg.sum = 0; - myagg.count = 0; - } - - for (int i=0; i< batchSize; ++i) { - value = vector[selected[i]]; - myagg.sum += value; - myagg.count += 1; - } - } - - private void iterateNoSelectionHasNulls( - Aggregation myagg, - [] vector, - int batchSize, - boolean[] isNull) { - - for(int i=0;i value = vector[i]; - if (myagg.isNull) { - myagg.isNull = false; - myagg.sum = 0; - myagg.count = 0; - } - myagg.sum += value; - myagg.count += 1; - } - } - } - - private void iterateNoSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize) { - if (myagg.isNull) { - myagg.isNull = false; - myagg.sum = 0; - myagg.count = 0; - } - - for (int i=0;i value = vector[i]; - myagg.sum += value; - myagg.count += 1; - } - } - - @Override - public AggregationBuffer getNewAggregationBuffer() throws HiveException { - return new Aggregation(); - } - - @Override - public void reset(AggregationBuffer agg) throws HiveException { - Aggregation myAgg = (Aggregation) agg; - myAgg.isNull = true; - } - - @Override - public Object evaluateOutput( - AggregationBuffer agg) throws HiveException { - Aggregation myagg = (Aggregation) agg; - if (myagg.isNull) { - return null; - } - else { - assert(0 < myagg.count); - resultCount.set (myagg.count); - resultSum.set (myagg.sum); - return partialResult; - } - } - - @Override - public ObjectInspector getOutputObjectInspector() { - return soi; - } - - @Override - public int getAggregationBufferFixedSize() { - JavaDataModel model = JavaDataModel.get(); - return JavaDataModel.alignUp( - model.object() + - model.primitive2() * 2, - model.memoryAlign()); - } - - @Override - public void init(AggregationDesc desc) throws HiveException { - // No-op - } - - public VectorExpression getInputExpression() { - return inputExpression; - } - - public void setInputExpression(VectorExpression inputExpression) { - this.inputExpression = inputExpression; - } -} - diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFMinMax.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFMinMax.txt deleted file mode 100644 index 2b0364c..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFMinMax.txt +++ /dev/null @@ -1,441 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; - -import org.apache.hadoop.hive.ql.exec.Description; -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter; -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriterFactory; -import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; -import org.apache.hadoop.hive.ql.metadata.HiveException; -import org.apache.hadoop.hive.ql.plan.AggregationDesc; -import org.apache.hadoop.hive.ql.util.JavaDataModel; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; - -/** -* . Vectorized implementation for MIN/MAX aggregates. -*/ -@Description(name = "", - value = "") -public class extends VectorAggregateExpression { - - private static final long serialVersionUID = 1L; - - /** - * class for storing the current aggregate value. - */ - static private final class Aggregation implements AggregationBuffer { - - private static final long serialVersionUID = 1L; - - transient private value; - transient private boolean isNull; - - public void checkValue( value) { - if (isNull) { - isNull = false; - this.value = value; - } else if (value this.value) { - this.value = value; - } - } - - @Override - public int getVariableSize() { - throw new UnsupportedOperationException(); - } - } - - private VectorExpression inputExpression; - private transient VectorExpressionWriter resultWriter; - - public (VectorExpression inputExpression) { - this(); - this.inputExpression = inputExpression; - } - - public () { - super(); - } - - @Override - public void init(AggregationDesc desc) throws HiveException { - resultWriter = VectorExpressionWriterFactory.genVectorExpressionWritable( - desc.getParameters().get(0)); - } - - private Aggregation getCurrentAggregationBuffer( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - int row) { - VectorAggregationBufferRow mySet = aggregationBufferSets[row]; - Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregrateIndex); - return myagg; - } - - @Override - public void aggregateInputSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - VectorizedRowBatch batch) throws HiveException { - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - inputExpression.evaluate(batch); - - inputVector = ()batch. - cols[this.inputExpression.getOutputColumn()]; - [] vector = inputVector.vector; - - if (inputVector.noNulls) { - if (inputVector.isRepeating) { - iterateNoNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector[0], batchSize); - } else { - if (batch.selectedInUse) { - iterateNoNullsSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector, batch.selected, batchSize); - } else { - iterateNoNullsWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector, batchSize); - } - } - } else { - if (inputVector.isRepeating) { - if (batch.selectedInUse) { - iterateHasNullsRepeatingSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector[0], batchSize, batch.selected, inputVector.isNull); - } else { - iterateHasNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector[0], batchSize, inputVector.isNull); - } - } else { - if (batch.selectedInUse) { - iterateHasNullsSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector, batchSize, batch.selected, inputVector.isNull); - } else { - iterateHasNullsWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector, batchSize, inputVector.isNull); - } - } - } - } - - private void iterateNoNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - value, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(value); - } - } - - private void iterateNoNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - [] values, - int[] selection, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(values[selection[i]]); - } - } - - private void iterateNoNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - [] values, - int batchSize) { - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(values[i]); - } - } - - private void iterateHasNullsRepeatingSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - value, - int batchSize, - int[] selection, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(value); - } - } - - } - - private void iterateHasNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - value, - int batchSize, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(value); - } - } - } - - private void iterateHasNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - [] values, - int batchSize, - int[] selection, - boolean[] isNull) { - - for (int j=0; j < batchSize; ++j) { - int i = selection[j]; - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - j); - myagg.checkValue(values[i]); - } - } - } - - private void iterateHasNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - [] values, - int batchSize, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(values[i]); - } - } - } - - @Override - public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) - throws HiveException { - - inputExpression.evaluate(batch); - - inputVector = ()batch. - cols[this.inputExpression.getOutputColumn()]; - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - Aggregation myagg = (Aggregation)agg; - - [] vector = inputVector.vector; - - if (inputVector.isRepeating) { - if (inputVector.noNulls && - (myagg.isNull || (vector[0] myagg.value))) { - myagg.isNull = false; - myagg.value = vector[0]; - } - return; - } - - if (!batch.selectedInUse && inputVector.noNulls) { - iterateNoSelectionNoNulls(myagg, vector, batchSize); - } - else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); - } - else if (inputVector.noNulls){ - iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); - } - else { - iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); - } - } - - private void iterateSelectionHasNulls( - Aggregation myagg, - [] vector, - int batchSize, - boolean[] isNull, - int[] selected) { - - for (int j=0; j< batchSize; ++j) { - int i = selected[j]; - if (!isNull[i]) { - value = vector[i]; - if (myagg.isNull) { - myagg.isNull = false; - myagg.value = value; - } - else if (value myagg.value) { - myagg.value = value; - } - } - } - } - - private void iterateSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize, - int[] selected) { - - if (myagg.isNull) { - myagg.value = vector[selected[0]]; - myagg.isNull = false; - } - - for (int i=0; i< batchSize; ++i) { - value = vector[selected[i]]; - if (value myagg.value) { - myagg.value = value; - } - } - } - - private void iterateNoSelectionHasNulls( - Aggregation myagg, - [] vector, - int batchSize, - boolean[] isNull) { - - for(int i=0;i value = vector[i]; - if (myagg.isNull) { - myagg.value = value; - myagg.isNull = false; - } - else if (value myagg.value) { - myagg.value = value; - } - } - } - } - - private void iterateNoSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize) { - if (myagg.isNull) { - myagg.value = vector[0]; - myagg.isNull = false; - } - - for (int i=0;i value = vector[i]; - if (value myagg.value) { - myagg.value = value; - } - } - } - - @Override - public AggregationBuffer getNewAggregationBuffer() throws HiveException { - return new Aggregation(); - } - - @Override - public void reset(AggregationBuffer agg) throws HiveException { - Aggregation myAgg = (Aggregation) agg; - myAgg.isNull = true; - } - - @Override - public Object evaluateOutput( - AggregationBuffer agg) throws HiveException { - Aggregation myagg = (Aggregation) agg; - if (myagg.isNull) { - return null; - } - else { - return resultWriter.writeValue(myagg.value); - } - } - - @Override - public ObjectInspector getOutputObjectInspector() { - return resultWriter.getObjectInspector(); - } - - @Override - public int getAggregationBufferFixedSize() { - JavaDataModel model = JavaDataModel.get(); - return JavaDataModel.alignUp( - model.object() + - model.primitive2(), - model.memoryAlign()); - } - - public VectorExpression getInputExpression() { - return inputExpression; - } - - public void setInputExpression(VectorExpression inputExpression) { - this.inputExpression = inputExpression; - } -} - diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFMinMaxString.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFMinMaxString.txt deleted file mode 100644 index 36f483e..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFMinMaxString.txt +++ /dev/null @@ -1,400 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; - -import java.util.ArrayList; -import java.util.Arrays; -import org.apache.hadoop.hive.ql.exec.Description; -import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr; -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; -import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector; -import org.apache.hadoop.hive.ql.plan.AggregationDesc; -import org.apache.hadoop.hive.ql.util.JavaDataModel; -import org.apache.hadoop.hive.ql.metadata.HiveException; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; -import org.apache.hadoop.io.Text; - -/** -* . Vectorized implementation for MIN/MAX aggregates. -*/ -@Description(name = "", - value = "") -public class extends VectorAggregateExpression { - - private static final long serialVersionUID = 1L; - - /** - * class for storing the current aggregate value. - */ - static private final class Aggregation implements AggregationBuffer { - - private static final long serialVersionUID = 1L; - - transient private final static int MIN_BUFFER_SIZE = 16; - transient private byte[] bytes = new byte[MIN_BUFFER_SIZE]; - transient private int length; - transient private boolean isNull; - - public void checkValue(byte[] bytes, int start, int length) { - if (isNull) { - isNull = false; - assign(bytes, start, length); - } else if (StringExpr.compare( - bytes, start, length, - this.bytes, 0, this.length) 0) { - assign(bytes, start, length); - } - } - - public void assign(byte[] bytes, int start, int length) { - // Avoid new allocation if possible - if (this.bytes.length < length) { - this.bytes = new byte[length]; - } - System.arraycopy(bytes, start, this.bytes, 0, length); - this.length = length; - } - @Override - public int getVariableSize() { - JavaDataModel model = JavaDataModel.get(); - return model.lengthForByteArrayOfSize(bytes.length); - } - } - - private VectorExpression inputExpression; - transient private Text result; - - public (VectorExpression inputExpression) { - this(); - this.inputExpression = inputExpression; - } - - public () { - super(); - result = new Text(); - } - - private Aggregation getCurrentAggregationBuffer( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - int row) { - VectorAggregationBufferRow mySet = aggregationBufferSets[row]; - Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregrateIndex); - return myagg; - } - -@Override - public void aggregateInputSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - VectorizedRowBatch batch) throws HiveException { - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - inputExpression.evaluate(batch); - - BytesColumnVector inputColumn = (BytesColumnVector)batch. - cols[this.inputExpression.getOutputColumn()]; - - if (inputColumn.noNulls) { - if (inputColumn.isRepeating) { - iterateNoNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize); - } else { - if (batch.selectedInUse) { - iterateNoNullsSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColumn, batch.selected, batchSize); - } else { - iterateNoNullsWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize); - } - } - } else { - if (inputColumn.isRepeating) { - // All nulls, no-op for min/max - } else { - if (batch.selectedInUse) { - iterateHasNullsSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize, batch.selected); - } else { - iterateHasNullsWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize); - } - } - } - } - - private void iterateNoNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - BytesColumnVector inputColumn, - int batchSize) { - - byte[] bytes = inputColumn.vector[0]; - int start = inputColumn.start[0]; - int length = inputColumn.length[0]; - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(bytes, start, length); - } - } - - private void iterateNoNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - BytesColumnVector inputColumn, - int[] selection, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - int row = selection[i]; - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(inputColumn.vector[row], - inputColumn.start[row], - inputColumn.length[row]); - } - } - - private void iterateNoNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - BytesColumnVector inputColumn, - int batchSize) { - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); - } - } - - private void iterateHasNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - BytesColumnVector inputColumn, - int batchSize, - int[] selection) { - - for (int i=0; i < batchSize; ++i) { - int row = selection[i]; - if (!inputColumn.isNull[row]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(inputColumn.vector[row], - inputColumn.start[row], - inputColumn.length[row]); - } - } - } - - private void iterateHasNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - BytesColumnVector inputColumn, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - if (!inputColumn.isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); - } - } - } - - @Override - public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) - throws HiveException { - - inputExpression.evaluate(batch); - - BytesColumnVector inputColumn = (BytesColumnVector)batch. - cols[this.inputExpression.getOutputColumn()]; - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - Aggregation myagg = (Aggregation)agg; - - if (inputColumn.isRepeating) { - if (inputColumn.noNulls) { - myagg.checkValue(inputColumn.vector[0], - inputColumn.start[0], - inputColumn.length[0]); - } - return; - } - - if (!batch.selectedInUse && inputColumn.noNulls) { - iterateNoSelectionNoNulls(myagg, inputColumn, batchSize); - } - else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, inputColumn, batchSize); - } - else if (inputColumn.noNulls){ - iterateSelectionNoNulls(myagg, inputColumn, batchSize, batch.selected); - } - else { - iterateSelectionHasNulls(myagg, inputColumn, batchSize, batch.selected); - } - } - - private void iterateSelectionHasNulls( - Aggregation myagg, - BytesColumnVector inputColumn, - int batchSize, - int[] selected) { - - for (int j=0; j< batchSize; ++j) { - int i = selected[j]; - if (!inputColumn.isNull[i]) { - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); - } - } - } - - private void iterateSelectionNoNulls( - Aggregation myagg, - BytesColumnVector inputColumn, - int batchSize, - int[] selected) { - - for (int i=0; i< batchSize; ++i) { - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); - } - } - - private void iterateNoSelectionHasNulls( - Aggregation myagg, - BytesColumnVector inputColumn, - int batchSize) { - - for (int i=0; i< batchSize; ++i) { - if (!inputColumn.isNull[i]) { - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); - } - } - } - - private void iterateNoSelectionNoNulls( - Aggregation myagg, - BytesColumnVector inputColumn, - int batchSize) { - for (int i=0; i< batchSize; ++i) { - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); - } - } - - @Override - public AggregationBuffer getNewAggregationBuffer() throws HiveException { - return new Aggregation(); - } - - @Override - public void reset(AggregationBuffer agg) throws HiveException { - Aggregation myAgg = (Aggregation) agg; - myAgg.isNull = true; - } - - @Override - public Object evaluateOutput( - AggregationBuffer agg) throws HiveException { - Aggregation myagg = (Aggregation) agg; - if (myagg.isNull) { - return null; - } - else { - result.set(myagg.bytes, 0, myagg.length); - return result; - } - } - - @Override - public ObjectInspector getOutputObjectInspector() { - return PrimitiveObjectInspectorFactory.writableStringObjectInspector; - } - - @Override - public int getAggregationBufferFixedSize() { - JavaDataModel model = JavaDataModel.get(); - return JavaDataModel.alignUp( - model.object() + - model.ref()+ - model.primitive1()*2, - model.memoryAlign()); - } - - @Override - public boolean hasVariableSize() { - return true; - } - - @Override - public void init(AggregationDesc desc) throws HiveException { - // No-op - } - - public VectorExpression getInputExpression() { - return inputExpression; - } - - public void setInputExpression(VectorExpression inputExpression) { - this.inputExpression = inputExpression; - } -} - diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFSum.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFSum.txt deleted file mode 100644 index 3573997..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFSum.txt +++ /dev/null @@ -1,436 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; - -import org.apache.hadoop.hive.ql.exec.Description; -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; -import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; -import org.apache.hadoop.hive.ql.metadata.HiveException; -import org.apache.hadoop.hive.ql.plan.AggregationDesc; -import org.apache.hadoop.hive.ql.util.JavaDataModel; -import org.apache.hadoop.io.LongWritable; -import org.apache.hadoop.hive.serde2.io.DoubleWritable; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; - -/** -* . Vectorized implementation for SUM aggregates. -*/ -@Description(name = "sum", - value = "_FUNC_(expr) - Returns the sum value of expr (vectorized, type: )") -public class extends VectorAggregateExpression { - - private static final long serialVersionUID = 1L; - - /** - * class for storing the current aggregate value. - */ - private static final class Aggregation implements AggregationBuffer { - - private static final long serialVersionUID = 1L; - - transient private sum; - transient private boolean isNull; - - public void sumValue( value) { - if (isNull) { - sum = value; - isNull = false; - } else { - sum += value; - } - } - - @Override - public int getVariableSize() { - throw new UnsupportedOperationException(); - } - } - - private VectorExpression inputExpression; - transient private final result; - - public (VectorExpression inputExpression) { - this(); - this.inputExpression = inputExpression; - } - - public () { - super(); - result = new (); - } - - private Aggregation getCurrentAggregationBuffer( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - int row) { - VectorAggregationBufferRow mySet = aggregationBufferSets[row]; - Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregateIndex); - return myagg; - } - - @Override - public void aggregateInputSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - VectorizedRowBatch batch) throws HiveException { - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - inputExpression.evaluate(batch); - - inputVector = ()batch. - cols[this.inputExpression.getOutputColumn()]; - [] vector = inputVector.vector; - - if (inputVector.noNulls) { - if (inputVector.isRepeating) { - iterateNoNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregateIndex, - vector[0], batchSize); - } else { - if (batch.selectedInUse) { - iterateNoNullsSelectionWithAggregationSelection( - aggregationBufferSets, aggregateIndex, - vector, batch.selected, batchSize); - } else { - iterateNoNullsWithAggregationSelection( - aggregationBufferSets, aggregateIndex, - vector, batchSize); - } - } - } else { - if (inputVector.isRepeating) { - if (batch.selectedInUse) { - iterateHasNullsRepeatingSelectionWithAggregationSelection( - aggregationBufferSets, aggregateIndex, - vector[0], batchSize, batch.selected, inputVector.isNull); - } else { - iterateHasNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregateIndex, - vector[0], batchSize, inputVector.isNull); - } - } else { - if (batch.selectedInUse) { - iterateHasNullsSelectionWithAggregationSelection( - aggregationBufferSets, aggregateIndex, - vector, batchSize, batch.selected, inputVector.isNull); - } else { - iterateHasNullsWithAggregationSelection( - aggregationBufferSets, aggregateIndex, - vector, batchSize, inputVector.isNull); - } - } - } - } - - private void iterateNoNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - value, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(value); - } - } - - private void iterateNoNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] values, - int[] selection, - int batchSize) { - - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(values[selection[i]]); - } - } - - private void iterateNoNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] values, - int batchSize) { - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(values[i]); - } - } - - private void iterateHasNullsRepeatingSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - value, - int batchSize, - int[] selection, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(value); - } - } - - } - - private void iterateHasNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - value, - int batchSize, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(value); - } - } - } - - private void iterateHasNullsSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] values, - int batchSize, - int[] selection, - boolean[] isNull) { - - for (int j=0; j < batchSize; ++j) { - int i = selection[j]; - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - j); - myagg.sumValue(values[i]); - } - } - } - - private void iterateHasNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] values, - int batchSize, - boolean[] isNull) { - - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(values[i]); - } - } - } - - - @Override - public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) - throws HiveException { - - inputExpression.evaluate(batch); - - inputVector = ()batch. - cols[this.inputExpression.getOutputColumn()]; - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - Aggregation myagg = (Aggregation)agg; - - [] vector = inputVector.vector; - - if (inputVector.isRepeating) { - if (inputVector.noNulls) { - if (myagg.isNull) { - myagg.isNull = false; - myagg.sum = 0; - } - myagg.sum += vector[0]*batchSize; - } - return; - } - - if (!batch.selectedInUse && inputVector.noNulls) { - iterateNoSelectionNoNulls(myagg, vector, batchSize); - } - else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); - } - else if (inputVector.noNulls){ - iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); - } - else { - iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); - } - } - - private void iterateSelectionHasNulls( - Aggregation myagg, - [] vector, - int batchSize, - boolean[] isNull, - int[] selected) { - - for (int j=0; j< batchSize; ++j) { - int i = selected[j]; - if (!isNull[i]) { - value = vector[i]; - if (myagg.isNull) { - myagg.isNull = false; - myagg.sum = 0; - } - myagg.sum += value; - } - } - } - - private void iterateSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize, - int[] selected) { - - if (myagg.isNull) { - myagg.sum = 0; - myagg.isNull = false; - } - - for (int i=0; i< batchSize; ++i) { - value = vector[selected[i]]; - myagg.sum += value; - } - } - - private void iterateNoSelectionHasNulls( - Aggregation myagg, - [] vector, - int batchSize, - boolean[] isNull) { - - for(int i=0;i value = vector[i]; - if (myagg.isNull) { - myagg.sum = 0; - myagg.isNull = false; - } - myagg.sum += value; - } - } - } - - private void iterateNoSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize) { - if (myagg.isNull) { - myagg.sum = 0; - myagg.isNull = false; - } - - for (int i=0;i value = vector[i]; - myagg.sum += value; - } - } - - @Override - public AggregationBuffer getNewAggregationBuffer() throws HiveException { - return new Aggregation(); - } - - @Override - public void reset(AggregationBuffer agg) throws HiveException { - Aggregation myAgg = (Aggregation) agg; - myAgg.isNull = true; - } - - @Override - public Object evaluateOutput(AggregationBuffer agg) throws HiveException { - Aggregation myagg = (Aggregation) agg; - if (myagg.isNull) { - return null; - } - else { - result.set(myagg.sum); - return result; - } - } - - @Override - public ObjectInspector getOutputObjectInspector() { - return ; - } - - @Override - public int getAggregationBufferFixedSize() { - JavaDataModel model = JavaDataModel.get(); - return JavaDataModel.alignUp( - model.object(), - model.memoryAlign()); - } - - @Override - public void init(AggregationDesc desc) throws HiveException { - // No-op - } - - public VectorExpression getInputExpression() { - return inputExpression; - } - - public void setInputExpression(VectorExpression inputExpression) { - this.inputExpression = inputExpression; - } -} - diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFVar.txt ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFVar.txt deleted file mode 100644 index 7c0e58f..0000000 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFVar.txt +++ /dev/null @@ -1,520 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.hadoop.hive.ql.exec.Description; -import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression; -import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression; -import org.apache.hadoop.hive.ql.exec.vector.VectorAggregationBufferRow; -import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; -import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; -import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; -import org.apache.hadoop.hive.ql.metadata.HiveException; -import org.apache.hadoop.hive.ql.plan.AggregationDesc; -import org.apache.hadoop.hive.ql.util.JavaDataModel; -import org.apache.hadoop.io.LongWritable; -import org.apache.hadoop.hive.serde2.io.DoubleWritable; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; -import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; - -/** -* . Vectorized implementation for VARIANCE aggregates. -*/ -@Description(name = "", - value = "") -public class extends VectorAggregateExpression { - - private static final long serialVersionUID = 1L; - - /** - /* class for storing the current aggregate value. - */ - private static final class Aggregation implements AggregationBuffer { - - private static final long serialVersionUID = 1L; - - transient private double sum; - transient private long count; - transient private double variance; - transient private boolean isNull; - - public void init() { - isNull = false; - sum = 0; - count = 0; - variance = 0; - } - - @Override - public int getVariableSize() { - throw new UnsupportedOperationException(); - } - } - - private VectorExpression inputExpression; - transient private LongWritable resultCount; - transient private DoubleWritable resultSum; - transient private DoubleWritable resultVariance; - transient private Object[] partialResult; - - transient private ObjectInspector soi; - - - public (VectorExpression inputExpression) { - this(); - this.inputExpression = inputExpression; - } - - public () { - super(); - partialResult = new Object[3]; - resultCount = new LongWritable(); - resultSum = new DoubleWritable(); - resultVariance = new DoubleWritable(); - partialResult[0] = resultCount; - partialResult[1] = resultSum; - partialResult[2] = resultVariance; - initPartialResultInspector(); - } - - private void initPartialResultInspector() { - List foi = new ArrayList(); - foi.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector); - foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); - foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); - - List fname = new ArrayList(); - fname.add("count"); - fname.add("sum"); - fname.add("variance"); - - soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi); - } - - private Aggregation getCurrentAggregationBuffer( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - int row) { - VectorAggregationBufferRow mySet = aggregationBufferSets[row]; - Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregateIndex); - return myagg; - } - - - @Override - public void aggregateInputSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - VectorizedRowBatch batch) throws HiveException { - - inputExpression.evaluate(batch); - - inputVector = ()batch. - cols[this.inputExpression.getOutputColumn()]; - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - [] vector = inputVector.vector; - - if (inputVector.isRepeating) { - if (inputVector.noNulls || !inputVector.isNull[0]) { - iterateRepeatingNoNullsWithAggregationSelection( - aggregationBufferSets, aggregateIndex, vector[0], batchSize); - } - } - else if (!batch.selectedInUse && inputVector.noNulls) { - iterateNoSelectionNoNullsWithAggregationSelection( - aggregationBufferSets, aggregateIndex, vector, batchSize); - } - else if (!batch.selectedInUse) { - iterateNoSelectionHasNullsWithAggregationSelection( - aggregationBufferSets, aggregateIndex, vector, batchSize, inputVector.isNull); - } - else if (inputVector.noNulls){ - iterateSelectionNoNullsWithAggregationSelection( - aggregationBufferSets, aggregateIndex, vector, batchSize, batch.selected); - } - else { - iterateSelectionHasNullsWithAggregationSelection( - aggregationBufferSets, aggregateIndex, vector, batchSize, - inputVector.isNull, batch.selected); - } - - } - - private void iterateRepeatingNoNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - double value, - int batchSize) { - - for (int i=0; i 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - } - - private void iterateSelectionHasNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] vector, - int batchSize, - boolean[] isNull, - int[] selected) { - - for (int j=0; j< batchSize; ++j) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - j); - int i = selected[j]; - if (!isNull[i]) { - double value = vector[i]; - if (myagg.isNull) { - myagg.init (); - } - myagg.sum += value; - myagg.count += 1; - if(myagg.count > 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - } - } - - private void iterateSelectionNoNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] vector, - int batchSize, - int[] selected) { - - for (int i=0; i< batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - double value = vector[selected[i]]; - if (myagg.isNull) { - myagg.init (); - } - myagg.sum += value; - myagg.count += 1; - if(myagg.count > 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - } - - private void iterateNoSelectionHasNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] vector, - int batchSize, - boolean[] isNull) { - - for(int i=0;i 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - } - } - - private void iterateNoSelectionNoNullsWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregateIndex, - [] vector, - int batchSize) { - - for (int i=0; i 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - } - - @Override - public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) - throws HiveException { - - inputExpression.evaluate(batch); - - inputVector = ()batch. - cols[this.inputExpression.getOutputColumn()]; - - int batchSize = batch.size; - - if (batchSize == 0) { - return; - } - - Aggregation myagg = (Aggregation)agg; - - [] vector = inputVector.vector; - - if (inputVector.isRepeating) { - if (inputVector.noNulls) { - iterateRepeatingNoNulls(myagg, vector[0], batchSize); - } - } - else if (!batch.selectedInUse && inputVector.noNulls) { - iterateNoSelectionNoNulls(myagg, vector, batchSize); - } - else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); - } - else if (inputVector.noNulls){ - iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); - } - else { - iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); - } - } - - private void iterateRepeatingNoNulls( - Aggregation myagg, - double value, - int batchSize) { - - if (myagg.isNull) { - myagg.init (); - } - - // TODO: conjure a formula w/o iterating - // - - myagg.sum += value; - myagg.count += 1; - if(myagg.count > 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - - // We pulled out i=0 so we can remove the count > 1 check in the loop - for (int i=1; i[] vector, - int batchSize, - boolean[] isNull, - int[] selected) { - - for (int j=0; j< batchSize; ++j) { - int i = selected[j]; - if (!isNull[i]) { - double value = vector[i]; - if (myagg.isNull) { - myagg.init (); - } - myagg.sum += value; - myagg.count += 1; - if(myagg.count > 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - } - } - - private void iterateSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize, - int[] selected) { - - if (myagg.isNull) { - myagg.init (); - } - - double value = vector[selected[0]]; - myagg.sum += value; - myagg.count += 1; - if(myagg.count > 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - - // i=0 was pulled out to remove the count > 1 check in the loop - // - for (int i=1; i< batchSize; ++i) { - value = vector[selected[i]]; - myagg.sum += value; - myagg.count += 1; - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - - private void iterateNoSelectionHasNulls( - Aggregation myagg, - [] vector, - int batchSize, - boolean[] isNull) { - - for(int i=0;i 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - } - } - } - - private void iterateNoSelectionNoNulls( - Aggregation myagg, - [] vector, - int batchSize) { - - if (myagg.isNull) { - myagg.init (); - } - - double value = vector[0]; - myagg.sum += value; - myagg.count += 1; - - if(myagg.count > 1) { - double t = myagg.count*value - myagg.sum; - myagg.variance += (t*t) / ((double)myagg.count*(myagg.count-1)); - } - - // i=0 was pulled out to remove count > 1 check - for (int i=1; i scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2073,15 +2139,17 @@ public void testFilterLongColGreaterDoubleScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2134,15 +2202,17 @@ public void testFilterLongColGreaterDoubleScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2195,15 +2265,17 @@ public void testFilterLongColGreaterDoubleScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2256,15 +2328,17 @@ public void testFilterDoubleColGreaterDoubleScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2317,15 +2391,17 @@ public void testFilterDoubleColGreaterDoubleScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2378,15 +2454,17 @@ public void testFilterDoubleColGreaterDoubleScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2439,15 +2517,17 @@ public void testFilterDoubleColGreaterDoubleScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -2500,15 +2580,17 @@ public void testFilterLongColGreaterEqualDoubleScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2561,15 +2643,17 @@ public void testFilterLongColGreaterEqualDoubleScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2622,15 +2706,17 @@ public void testFilterLongColGreaterEqualDoubleScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2683,15 +2769,17 @@ public void testFilterLongColGreaterEqualDoubleScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2744,15 +2832,17 @@ public void testFilterDoubleColGreaterEqualDoubleScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2805,15 +2895,17 @@ public void testFilterDoubleColGreaterEqualDoubleScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2866,15 +2958,17 @@ public void testFilterDoubleColGreaterEqualDoubleScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2927,15 +3021,17 @@ public void testFilterDoubleColGreaterEqualDoubleScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -2988,15 +3084,17 @@ public void testFilterLongColEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3049,15 +3147,17 @@ public void testFilterLongColEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3110,15 +3210,17 @@ public void testFilterLongColEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3171,15 +3273,17 @@ public void testFilterLongColEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3232,15 +3336,17 @@ public void testFilterDoubleColEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3293,15 +3399,17 @@ public void testFilterDoubleColEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3354,15 +3462,17 @@ public void testFilterDoubleColEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3415,15 +3525,17 @@ public void testFilterDoubleColEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] == scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] == scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] == scalarValue) { assertEquals( @@ -3476,15 +3588,17 @@ public void testFilterLongColNotEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3537,15 +3651,17 @@ public void testFilterLongColNotEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3598,15 +3714,17 @@ public void testFilterLongColNotEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3659,15 +3777,17 @@ public void testFilterLongColNotEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3720,15 +3840,17 @@ public void testFilterDoubleColNotEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3781,15 +3903,17 @@ public void testFilterDoubleColNotEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3842,15 +3966,17 @@ public void testFilterDoubleColNotEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3903,15 +4029,17 @@ public void testFilterDoubleColNotEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] != scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] != scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] != scalarValue) { assertEquals( @@ -3964,15 +4092,17 @@ public void testFilterLongColLessLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4025,15 +4155,17 @@ public void testFilterLongColLessLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4086,15 +4218,17 @@ public void testFilterLongColLessLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4147,15 +4281,17 @@ public void testFilterLongColLessLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4208,15 +4344,17 @@ public void testFilterDoubleColLessLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4269,15 +4407,17 @@ public void testFilterDoubleColLessLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4330,15 +4470,17 @@ public void testFilterDoubleColLessLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4391,15 +4533,17 @@ public void testFilterDoubleColLessLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] < scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] < scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] < scalarValue) { assertEquals( @@ -4452,15 +4596,17 @@ public void testFilterLongColLessEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4513,15 +4659,17 @@ public void testFilterLongColLessEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4574,15 +4722,17 @@ public void testFilterLongColLessEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4635,15 +4785,17 @@ public void testFilterLongColLessEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4696,15 +4848,17 @@ public void testFilterDoubleColLessEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4757,15 +4911,17 @@ public void testFilterDoubleColLessEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4818,15 +4974,17 @@ public void testFilterDoubleColLessEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4879,15 +5037,17 @@ public void testFilterDoubleColLessEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] <= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] <= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] <= scalarValue) { assertEquals( @@ -4940,15 +5100,17 @@ public void testFilterLongColGreaterLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5001,15 +5163,17 @@ public void testFilterLongColGreaterLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5062,15 +5226,17 @@ public void testFilterLongColGreaterLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5123,15 +5289,17 @@ public void testFilterLongColGreaterLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5184,15 +5352,17 @@ public void testFilterDoubleColGreaterLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5245,15 +5415,17 @@ public void testFilterDoubleColGreaterLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5306,15 +5478,17 @@ public void testFilterDoubleColGreaterLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5367,15 +5541,17 @@ public void testFilterDoubleColGreaterLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] > scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] > scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] > scalarValue) { assertEquals( @@ -5428,15 +5604,17 @@ public void testFilterLongColGreaterEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5489,15 +5667,17 @@ public void testFilterLongColGreaterEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5550,15 +5730,17 @@ public void testFilterLongColGreaterEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5611,15 +5793,17 @@ public void testFilterLongColGreaterEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5672,15 +5856,17 @@ public void testFilterDoubleColGreaterEqualLongScalarColNullsRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5733,15 +5919,17 @@ public void testFilterDoubleColGreaterEqualLongScalarColNulls() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5794,15 +5982,17 @@ public void testFilterDoubleColGreaterEqualLongScalar() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5855,15 +6045,17 @@ public void testFilterDoubleColGreaterEqualLongScalarColRepeats() { vectorExpression.evaluate(rowBatch); + int selectedIndex = 0; + int i=0; //check for isRepeating optimization if(inputColumnVector.isRepeating) { //null vector is safe to check, as it is always initialized to match the data vector selectedIndex = - !inputColumnVector.isNull[0] && inputColumnVector.vector[0] >= scalarValue + !inputColumnVector.isNull[i] && inputColumnVector.vector[i] >= scalarValue ? BATCH_SIZE : 0; } else { - for(int i = 0; i < BATCH_SIZE; i++) { + for(i = 0; i < BATCH_SIZE; i++) { if(!inputColumnVector.isNull[i]) { if(inputColumnVector.vector[i] >= scalarValue) { assertEquals( @@ -5894,6 +6086,6054 @@ public void testFilterDoubleColGreaterEqualLongScalarColRepeats() { } } + @Test + public void testFilterLongScalarEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualDoubleColumn vectorExpression = + new FilterLongScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualDoubleColumn vectorExpression = + new FilterLongScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualDoubleColumn vectorExpression = + new FilterLongScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualDoubleColumn vectorExpression = + new FilterLongScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualDoubleColumn vectorExpression = + new FilterDoubleScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualDoubleColumn vectorExpression = + new FilterDoubleScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualDoubleColumn vectorExpression = + new FilterDoubleScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualDoubleColumn vectorExpression = + new FilterDoubleScalarEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualDoubleColumn vectorExpression = + new FilterLongScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualDoubleColumn vectorExpression = + new FilterLongScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualDoubleColumn vectorExpression = + new FilterLongScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualDoubleColumn vectorExpression = + new FilterLongScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualDoubleColumn vectorExpression = + new FilterDoubleScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualDoubleColumn vectorExpression = + new FilterDoubleScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualDoubleColumn vectorExpression = + new FilterDoubleScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualDoubleColumn vectorExpression = + new FilterDoubleScalarNotEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessDoubleColumn vectorExpression = + new FilterLongScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessDoubleColumn vectorExpression = + new FilterLongScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessDoubleColumn vectorExpression = + new FilterLongScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessDoubleColumn vectorExpression = + new FilterLongScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessDoubleColumn vectorExpression = + new FilterDoubleScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessDoubleColumn vectorExpression = + new FilterDoubleScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessDoubleColumn vectorExpression = + new FilterDoubleScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessDoubleColumn vectorExpression = + new FilterDoubleScalarLessDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualDoubleColumn vectorExpression = + new FilterLongScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualDoubleColumn vectorExpression = + new FilterLongScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualDoubleColumn vectorExpression = + new FilterLongScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualDoubleColumn vectorExpression = + new FilterLongScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualDoubleColumn vectorExpression = + new FilterDoubleScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualDoubleColumn vectorExpression = + new FilterDoubleScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualDoubleColumn vectorExpression = + new FilterDoubleScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualDoubleColumn vectorExpression = + new FilterDoubleScalarLessEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterDoubleColumn vectorExpression = + new FilterLongScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterDoubleColumn vectorExpression = + new FilterLongScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterDoubleColumn vectorExpression = + new FilterLongScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterDoubleColumn vectorExpression = + new FilterLongScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualDoubleColumn vectorExpression = + new FilterLongScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualDoubleColumn vectorExpression = + new FilterLongScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualDoubleColumn vectorExpression = + new FilterLongScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualDoubleColumn vectorExpression = + new FilterLongScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualDoubleColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualDoubleColumnColNulls() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualDoubleColumn() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualDoubleColumnColRepeats() { + + Random rand = new Random(SEED); + + DoubleColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateDoubleColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualDoubleColumn vectorExpression = + new FilterDoubleScalarGreaterEqualDoubleColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualLongColumn vectorExpression = + new FilterLongScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualLongColumn vectorExpression = + new FilterLongScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualLongColumn vectorExpression = + new FilterLongScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarEqualLongColumn vectorExpression = + new FilterLongScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualLongColumn vectorExpression = + new FilterDoubleScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualLongColumn vectorExpression = + new FilterDoubleScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualLongColumn vectorExpression = + new FilterDoubleScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarEqualLongColumn vectorExpression = + new FilterDoubleScalarEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue == inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue == inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "==" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualLongColumn vectorExpression = + new FilterLongScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualLongColumn vectorExpression = + new FilterLongScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualLongColumn vectorExpression = + new FilterLongScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarNotEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarNotEqualLongColumn vectorExpression = + new FilterLongScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualLongColumn vectorExpression = + new FilterDoubleScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualLongColumn vectorExpression = + new FilterDoubleScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualLongColumn vectorExpression = + new FilterDoubleScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarNotEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarNotEqualLongColumn vectorExpression = + new FilterDoubleScalarNotEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue != inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue != inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "!=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessLongColumn vectorExpression = + new FilterLongScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessLongColumn vectorExpression = + new FilterLongScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessLongColumn vectorExpression = + new FilterLongScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessLongColumn vectorExpression = + new FilterLongScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessLongColumn vectorExpression = + new FilterDoubleScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessLongColumn vectorExpression = + new FilterDoubleScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessLongColumn vectorExpression = + new FilterDoubleScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessLongColumn vectorExpression = + new FilterDoubleScalarLessLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue < inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue < inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualLongColumn vectorExpression = + new FilterLongScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualLongColumn vectorExpression = + new FilterLongScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualLongColumn vectorExpression = + new FilterLongScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarLessEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarLessEqualLongColumn vectorExpression = + new FilterLongScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualLongColumn vectorExpression = + new FilterDoubleScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualLongColumn vectorExpression = + new FilterDoubleScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualLongColumn vectorExpression = + new FilterDoubleScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarLessEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarLessEqualLongColumn vectorExpression = + new FilterDoubleScalarLessEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue <= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue <= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + "<=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterLongColumn vectorExpression = + new FilterLongScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterLongColumn vectorExpression = + new FilterLongScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterLongColumn vectorExpression = + new FilterLongScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterLongColumn vectorExpression = + new FilterLongScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterLongColumn vectorExpression = + new FilterDoubleScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterLongColumn vectorExpression = + new FilterDoubleScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterLongColumn vectorExpression = + new FilterDoubleScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterLongColumn vectorExpression = + new FilterDoubleScalarGreaterLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue > inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue > inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualLongColumn vectorExpression = + new FilterLongScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualLongColumn vectorExpression = + new FilterLongScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualLongColumn vectorExpression = + new FilterLongScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterLongScalarGreaterEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + long scalarValue = 0; + do { + scalarValue = rand.nextLong(); + } while(scalarValue == 0); + + FilterLongScalarGreaterEqualLongColumn vectorExpression = + new FilterLongScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualLongColumnColNullsRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualLongColumn vectorExpression = + new FilterDoubleScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualLongColumnColNulls() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(true, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualLongColumn vectorExpression = + new FilterDoubleScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualLongColumn() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + false, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualLongColumn vectorExpression = + new FilterDoubleScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + + @Test + public void testFilterDoubleScalarGreaterEqualLongColumnColRepeats() { + + Random rand = new Random(SEED); + + LongColumnVector inputColumnVector = + VectorizedRowGroupGenUtil.generateLongColumnVector(false, + true, BATCH_SIZE, rand); + + VectorizedRowBatch rowBatch = new VectorizedRowBatch(1, BATCH_SIZE); + rowBatch.cols[0] = inputColumnVector; + + double scalarValue = 0; + do { + scalarValue = rand.nextDouble(); + } while(scalarValue == 0); + + FilterDoubleScalarGreaterEqualLongColumn vectorExpression = + new FilterDoubleScalarGreaterEqualLongColumn(0, scalarValue); + + vectorExpression.evaluate(rowBatch); + + + int selectedIndex = 0; + int i=0; + //check for isRepeating optimization + if(inputColumnVector.isRepeating) { + //null vector is safe to check, as it is always initialized to match the data vector + selectedIndex = + !inputColumnVector.isNull[i] && scalarValue >= inputColumnVector.vector[i] + ? BATCH_SIZE : 0; + } else { + for(i = 0; i < BATCH_SIZE; i++) { + if(!inputColumnVector.isNull[i]) { + if(scalarValue >= inputColumnVector.vector[i]) { + assertEquals( + "Vector index that passes filter " + + scalarValue + ">=" + + inputColumnVector.vector[i] + " is not in rowBatch selected index", + i, + rowBatch.selected[selectedIndex]); + selectedIndex++; + } + } + } + } + + assertEquals("Row batch size not set to number of selected rows: " + selectedIndex, + selectedIndex, rowBatch.size); + + if(selectedIndex > 0 && selectedIndex < BATCH_SIZE) { + assertEquals( + "selectedInUse should be set when > 0 and < entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + true, rowBatch.selectedInUse); + } else if(selectedIndex == BATCH_SIZE) { + assertEquals( + "selectedInUse should not be set when entire batch(" + BATCH_SIZE + ") is selected: " + + selectedIndex, + false, rowBatch.selectedInUse); + } + } + }