diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt index 46d66bd..f0e877c 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt @@ -22,7 +22,7 @@ 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.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; @@ -33,15 +33,15 @@ import org.apache.hadoop.hive.ql.util.JavaDataModel; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; /** -* . Vectorized implementation for MIN/MAX aggregates. +* . 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 { @@ -75,10 +75,10 @@ public class extends VectorAggregateExpression { value = 0; } } - + private VectorExpression inputExpression; private transient VectorExpressionWriter resultWriter; - + public (VectorExpression inputExpression) { this(); this.inputExpression = inputExpression; @@ -87,13 +87,13 @@ public class extends VectorAggregateExpression { public () { super(); } - + @Override public void init(AggregationDesc desc) throws HiveException { resultWriter = VectorExpressionWriterFactory.genVectorExpressionWritable( desc.getParameters().get(0)); } - + private Aggregation getCurrentAggregationBuffer( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -102,66 +102,71 @@ public class extends VectorAggregateExpression { Aggregation myagg = (Aggregation) mySet.getAggregationBuffer(aggregrateIndex); return myagg; } - + @Override public void aggregateInputSelection( VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, + int aggregrateIndex, VectorizedRowBatch batch) throws HiveException { - + int batchSize = batch.size; - + if (batchSize == 0) { return; } - + inputExpression.evaluate(batch); - - inputVector = ()batch. + + inputColVector = ()batch. cols[this.inputExpression.getOutputColumn()]; - [] vector = inputVector.vector; + [] vector = inputColVector.vector; - if (inputVector.noNulls) { - if (inputVector.isRepeating) { + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + // 1. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. iterateNoNullsRepeatingWithAggregationSelection( aggregationBufferSets, aggregrateIndex, vector[0], batchSize); } else { if (batch.selectedInUse) { + // 2. iterateNoNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, vector, batch.selected, batchSize); } else { + // 3. 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); - } + if (inputColVector.isRepeating) { + // 4. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector[0], batchSize, inputColVector.isNull); } else { if (batch.selectedInUse) { + // 5. iterateHasNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - vector, batchSize, batch.selected, inputVector.isNull); + vector, batchSize, batch.selected, inputColVector.isNull); } else { + // 6. iterateHasNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - vector, batchSize, inputVector.isNull); + vector, batchSize, inputColVector.isNull); } } } } + // 1. private void iterateNoNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -170,29 +175,31 @@ public class extends VectorAggregateExpression { for (int i=0; i < batchSize; ++i) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, aggregrateIndex, i); myagg.checkValue(value); } - } + } + // 2. private void iterateNoNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, [] values, int[] selection, int batchSize) { - + for (int i=0; i < batchSize; ++i) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, aggregrateIndex, i); myagg.checkValue(values[selection[i]]); } } + // 3. private void iterateNoNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -200,35 +207,14 @@ public class extends VectorAggregateExpression { 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) { - - if (isNull[0]) { - return; - } - - for (int i=0; i < batchSize; ++i) { - Aggregation myagg = getCurrentAggregationBuffer( aggregationBufferSets, aggregrateIndex, i); - myagg.checkValue(value); + myagg.checkValue(values[i]); } - } + // 4. private void iterateHasNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -249,6 +235,7 @@ public class extends VectorAggregateExpression { } } + // 5. private void iterateHasNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -261,7 +248,7 @@ public class extends VectorAggregateExpression { int i = selection[j]; if (!isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, aggregrateIndex, j); myagg.checkValue(values[i]); @@ -269,6 +256,7 @@ public class extends VectorAggregateExpression { } } + // 6. private void iterateHasNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -279,63 +267,63 @@ public class extends VectorAggregateExpression { for (int i=0; i < batchSize; ++i) { if (!isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, + aggregationBufferSets, aggregrateIndex, i); myagg.checkValue(values[i]); } } } - + @Override - public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) + public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) throws HiveException { - + inputExpression.evaluate(batch); - - inputVector = ()batch. + + inputColVector = ()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 && + + [] vector = inputColVector.vector; + + if (inputColVector.isRepeating) { + if ((inputColVector.noNulls || !inputColVector.isNull[0]) && (myagg.isNull || (vector[0] myagg.value))) { myagg.isNull = false; myagg.value = vector[0]; } return; } - - if (!batch.selectedInUse && inputVector.noNulls) { + + if (!batch.selectedInUse && inputColVector.noNulls) { iterateNoSelectionNoNulls(myagg, vector, batchSize); } else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull); + iterateNoSelectionHasNulls(myagg, vector, batchSize, inputColVector.isNull); } - else if (inputVector.noNulls){ + else if (inputColVector.noNulls){ iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected); } else { - iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected); + iterateSelectionHasNulls(myagg, vector, batchSize, inputColVector.isNull, batch.selected); } } - + private void iterateSelectionHasNulls( - Aggregation myagg, - [] vector, + Aggregation myagg, + [] vector, int batchSize, - boolean[] isNull, + boolean[] isNull, int[] selected) { - + for (int j=0; j< batchSize; ++j) { int i = selected[j]; if (!isNull[i]) { @@ -352,16 +340,16 @@ public class extends VectorAggregateExpression { } private void iterateSelectionNoNulls( - Aggregation myagg, - [] vector, + 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) { @@ -371,11 +359,11 @@ public class extends VectorAggregateExpression { } private void iterateNoSelectionHasNulls( - Aggregation myagg, - [] vector, + Aggregation myagg, + [] vector, int batchSize, boolean[] isNull) { - + for(int i=0;i value = vector[i]; @@ -398,7 +386,7 @@ public class extends VectorAggregateExpression { myagg.value = vector[0]; myagg.isNull = false; } - + for (int i=0;i value = vector[i]; if (value myagg.value) { @@ -429,7 +417,7 @@ public class extends VectorAggregateExpression { return resultWriter.writeValue(myagg.value); } } - + @Override public ObjectInspector getOutputObjectInspector() { return resultWriter.getObjectInspector(); diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt index 9a48171..20109fa 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt @@ -123,51 +123,56 @@ public class extends VectorAggregateExpression { inputExpression.evaluate(batch); - DecimalColumnVector inputVector = (DecimalColumnVector)batch. + DecimalColumnVector inputColVector = (DecimalColumnVector)batch. cols[this.inputExpression.getOutputColumn()]; - HiveDecimalWritable[] vector = inputVector.vector; + HiveDecimalWritable[] vector = inputColVector.vector; - if (inputVector.noNulls) { - if (inputVector.isRepeating) { + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + // 1. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. iterateNoNullsRepeatingWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - vector[0], inputVector.scale, batchSize); + vector[0], inputColVector.scale, batchSize); } else { if (batch.selectedInUse) { + // 2. iterateNoNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - vector, inputVector.scale, batch.selected, batchSize); + vector, inputColVector.scale, batch.selected, batchSize); } else { + // 3. iterateNoNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - vector, inputVector.scale, batchSize); + vector, inputColVector.scale, batchSize); } } } else { - if (inputVector.isRepeating) { - if (batch.selectedInUse) { - iterateHasNullsRepeatingSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector[0], inputVector.scale, batchSize, batch.selected, inputVector.isNull); - } else { - iterateHasNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - vector[0], inputVector.scale, batchSize, inputVector.isNull); - } + if (inputColVector.isRepeating) { + // 4. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + vector[0], inputColVector.scale, batchSize, inputColVector.isNull); } else { if (batch.selectedInUse) { + // 5. iterateHasNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - vector, inputVector.scale, batchSize, batch.selected, inputVector.isNull); + vector, inputColVector.scale, batchSize, batch.selected, inputColVector.isNull); } else { + // 6. iterateHasNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - vector, inputVector.scale, batchSize, inputVector.isNull); + vector, inputColVector.scale, batchSize, inputColVector.isNull); } } } } + // 1. private void iterateNoNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -184,6 +189,7 @@ public class extends VectorAggregateExpression { } } + // 2. private void iterateNoNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -201,6 +207,7 @@ public class extends VectorAggregateExpression { } } + // 3. private void iterateNoNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -216,27 +223,7 @@ public class extends VectorAggregateExpression { } } - private void iterateHasNullsRepeatingSelectionWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - HiveDecimalWritable value, - short scale, - 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, scale); - } - } - - } - + // 4. private void iterateHasNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -258,6 +245,7 @@ public class extends VectorAggregateExpression { } } + // 5. private void iterateHasNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -279,6 +267,7 @@ public class extends VectorAggregateExpression { } } + // 6. private void iterateHasNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -304,7 +293,7 @@ public class extends VectorAggregateExpression { inputExpression.evaluate(batch); - DecimalColumnVector inputVector = (DecimalColumnVector)batch. + DecimalColumnVector inputColVector = (DecimalColumnVector)batch. cols[this.inputExpression.getOutputColumn()]; int batchSize = batch.size; @@ -315,31 +304,26 @@ public class extends VectorAggregateExpression { Aggregation myagg = (Aggregation)agg; - HiveDecimalWritable[] vector = inputVector.vector; + HiveDecimalWritable[] vector = inputColVector.vector; - if (inputVector.isRepeating) { - if (inputVector.noNulls && - (myagg.isNull || (myagg.value.compareTo(vector[0]) 0))) { - myagg.isNull = false; - HiveDecimal value = vector[0].getHiveDecimal(); - myagg.value.set(value); + if (inputColVector.isRepeating) { + if (inputColVector.noNulls || !inputColVector.isNull[0]) { + myagg.checkValue(vector[0], inputColVector.scale);; } return; } - if (!batch.selectedInUse && inputVector.noNulls) { - iterateNoSelectionNoNulls(myagg, vector, inputVector.scale, batchSize); + if (!batch.selectedInUse && inputColVector.noNulls) { + iterateNoSelectionNoNulls(myagg, vector, inputColVector.scale, batchSize); } else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, vector, inputVector.scale, - batchSize, inputVector.isNull); + iterateNoSelectionHasNulls(myagg, vector, inputColVector.scale, batchSize, inputColVector.isNull); } - else if (inputVector.noNulls){ - iterateSelectionNoNulls(myagg, vector, inputVector.scale, batchSize, batch.selected); + else if (inputColVector.noNulls){ + iterateSelectionNoNulls(myagg, vector, inputColVector.scale, batchSize, batch.selected); } else { - iterateSelectionHasNulls(myagg, vector, inputVector.scale, - batchSize, inputVector.isNull, batch.selected); + iterateSelectionHasNulls(myagg, vector, inputColVector.scale, batchSize, inputColVector.isNull, batch.selected); } } diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxIntervalDayTime.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxIntervalDayTime.txt index 3cdf7e2..3892998 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxIntervalDayTime.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxIntervalDayTime.txt @@ -126,15 +126,20 @@ public class extends VectorAggregateExpression { if (inputColVector.noNulls) { if (inputColVector.isRepeating) { + // 1. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. iterateNoNullsRepeatingWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batchSize); } else { if (batch.selectedInUse) { + // 2. iterateNoNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batch.selected, batchSize); } else { + // 3. iterateNoNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batchSize); @@ -142,21 +147,20 @@ public class extends VectorAggregateExpression { } } else { if (inputColVector.isRepeating) { - if (batch.selectedInUse) { - iterateHasNullsRepeatingSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColVector, batchSize, batch.selected, inputColVector.isNull); - } else { - iterateHasNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColVector, batchSize, inputColVector.isNull); - } + // 4. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColVector, batchSize, inputColVector.isNull); } else { if (batch.selectedInUse) { + // 5. iterateHasNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - inputColVector, batchSize, batch.selected, inputColVector.isNull); + inputColVector, batchSize, batch.selected); } else { + // 6. iterateHasNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batchSize, inputColVector.isNull); @@ -165,6 +169,7 @@ public class extends VectorAggregateExpression { } } + // 1. private void iterateNoNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -181,6 +186,7 @@ public class extends VectorAggregateExpression { } } + // 2. private void iterateNoNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -197,6 +203,7 @@ public class extends VectorAggregateExpression { } } + // 3. private void iterateNoNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -211,57 +218,39 @@ public class extends VectorAggregateExpression { } } - private void iterateHasNullsRepeatingSelectionWithAggregationSelection( + // 4. + private void iterateHasNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, IntervalDayTimeColumnVector inputColVector, int batchSize, - int[] selection, boolean[] isNull) { - for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - // Repeating use index 0. - myagg.checkValue(inputColVector, 0); - } + if (isNull[0]) { + return; } - } - - private void iterateHasNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - IntervalDayTimeColumnVector inputColVector, - int batchSize, - boolean[] isNull) { - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - // Repeating use index 0. - myagg.checkValue(inputColVector, 0); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + // Repeating use index 0. + myagg.checkValue(inputColVector, 0); } } + // 5. private void iterateHasNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, IntervalDayTimeColumnVector inputColVector, int batchSize, - int[] selection, - boolean[] isNull) { + int[] selection) { for (int j=0; j < batchSize; ++j) { int i = selection[j]; - if (!isNull[i]) { + if (!inputColVector.isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( aggregationBufferSets, aggregrateIndex, @@ -271,6 +260,7 @@ public class extends VectorAggregateExpression { } } + // 6. private void iterateHasNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -307,10 +297,8 @@ public class extends VectorAggregateExpression { Aggregation myagg = (Aggregation)agg; if (inputColVector.isRepeating) { - if (inputColVector.noNulls && - (myagg.isNull || (inputColVector.compareTo(myagg.value, 0) 0))) { - myagg.isNull = false; - inputColVector.intervalDayTimeUpdate(myagg.value, 0); + if (inputColVector.noNulls || !inputColVector.isNull[0]) { + myagg.checkValue(inputColVector, 0); } return; } diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxString.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxString.txt index cdce457..2cab454 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxString.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxString.txt @@ -114,7 +114,7 @@ public class extends VectorAggregateExpression { return myagg; } -@Override + @Override public void aggregateInputSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -128,51 +128,64 @@ public class extends VectorAggregateExpression { inputExpression.evaluate(batch); - BytesColumnVector inputColumn = (BytesColumnVector)batch. + BytesColumnVector inputColVector = (BytesColumnVector)batch. cols[this.inputExpression.getOutputColumn()]; - if (inputColumn.noNulls) { - if (inputColumn.isRepeating) { + if (inputColVector.noNulls) { + if (inputColVector.isRepeating) { + // 1. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. iterateNoNullsRepeatingWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize); + inputColVector, batchSize); } else { if (batch.selectedInUse) { + // 2. iterateNoNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - inputColumn, batch.selected, batchSize); + inputColVector, batch.selected, batchSize); } else { + // 3. iterateNoNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize); + inputColVector, batchSize); } } } else { - if (inputColumn.isRepeating) { - // All nulls, no-op for min/max + if (inputColVector.isRepeating) { + // 4. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColVector, batchSize, inputColVector.isNull); } else { if (batch.selectedInUse) { + // 5. iterateHasNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize, batch.selected); + inputColVector, batchSize, batch.selected); } else { + // 6. iterateHasNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - inputColumn, batchSize); + inputColVector, batchSize); } } } } + // 1. private void iterateNoNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, int batchSize) { - byte[] bytes = inputColumn.vector[0]; - int start = inputColumn.start[0]; - int length = inputColumn.length[0]; + byte[] bytes = inputColVector.vector[0]; + int start = inputColVector.start[0]; + int length = inputColVector.length[0]; for (int i=0; i < batchSize; ++i) { Aggregation myagg = getCurrentAggregationBuffer( aggregationBufferSets, @@ -182,10 +195,11 @@ public class extends VectorAggregateExpression { } } + // 2. private void iterateNoNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, int[] selection, int batchSize) { @@ -195,64 +209,91 @@ public class extends VectorAggregateExpression { aggregationBufferSets, aggregrateIndex, i); - myagg.checkValue(inputColumn.vector[row], - inputColumn.start[row], - inputColumn.length[row]); + myagg.checkValue(inputColVector.vector[row], + inputColVector.start[row], + inputColVector.length[row]); } } + // 3. private void iterateNoNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, 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]); + myagg.checkValue(inputColVector.vector[i], + inputColVector.start[i], + inputColVector.length[i]); + } + } + + // 4. + private void iterateHasNullsRepeatingWithAggregationSelection( + VectorAggregationBufferRow[] aggregationBufferSets, + int aggregrateIndex, + BytesColumnVector inputColVector, + int batchSize, + boolean[] isNull) { + + if (isNull[0]) { + return; + } + + byte[] bytes = inputColVector.vector[0]; + int start = inputColVector.start[0]; + int length = inputColVector.length[0]; + for (int i=0; i < batchSize; ++i) { + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(bytes, start, length); } } + // 5. private void iterateHasNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, int batchSize, int[] selection) { for (int i=0; i < batchSize; ++i) { int row = selection[i]; - if (!inputColumn.isNull[row]) { + if (!inputColVector.isNull[row]) { Aggregation myagg = getCurrentAggregationBuffer( aggregationBufferSets, aggregrateIndex, i); - myagg.checkValue(inputColumn.vector[row], - inputColumn.start[row], - inputColumn.length[row]); + myagg.checkValue(inputColVector.vector[row], + inputColVector.start[row], + inputColVector.length[row]); } } } + // 6. private void iterateHasNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, int batchSize) { for (int i=0; i < batchSize; ++i) { - if (!inputColumn.isNull[i]) { + if (!inputColVector.isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( aggregationBufferSets, aggregrateIndex, i); - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); + myagg.checkValue(inputColVector.vector[i], + inputColVector.start[i], + inputColVector.length[i]); } } } @@ -263,7 +304,7 @@ public class extends VectorAggregateExpression { inputExpression.evaluate(batch); - BytesColumnVector inputColumn = (BytesColumnVector)batch. + BytesColumnVector inputColVector = (BytesColumnVector)batch. cols[this.inputExpression.getOutputColumn()]; int batchSize = batch.size; @@ -274,81 +315,81 @@ public class extends VectorAggregateExpression { Aggregation myagg = (Aggregation)agg; - if (inputColumn.isRepeating) { - if (inputColumn.noNulls) { - myagg.checkValue(inputColumn.vector[0], - inputColumn.start[0], - inputColumn.length[0]); + if (inputColVector.isRepeating) { + if (inputColVector.noNulls || !inputColVector.isNull[0]) { + myagg.checkValue(inputColVector.vector[0], + inputColVector.start[0], + inputColVector.length[0]); } return; } - if (!batch.selectedInUse && inputColumn.noNulls) { - iterateNoSelectionNoNulls(myagg, inputColumn, batchSize); + if (!batch.selectedInUse && inputColVector.noNulls) { + iterateNoSelectionNoNulls(myagg, inputColVector, batchSize); } else if (!batch.selectedInUse) { - iterateNoSelectionHasNulls(myagg, inputColumn, batchSize); + iterateNoSelectionHasNulls(myagg, inputColVector, batchSize); } - else if (inputColumn.noNulls){ - iterateSelectionNoNulls(myagg, inputColumn, batchSize, batch.selected); + else if (inputColVector.noNulls){ + iterateSelectionNoNulls(myagg, inputColVector, batchSize, batch.selected); } else { - iterateSelectionHasNulls(myagg, inputColumn, batchSize, batch.selected); + iterateSelectionHasNulls(myagg, inputColVector, batchSize, batch.selected); } } private void iterateSelectionHasNulls( Aggregation myagg, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, 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]); + if (!inputColVector.isNull[i]) { + myagg.checkValue(inputColVector.vector[i], + inputColVector.start[i], + inputColVector.length[i]); } } } private void iterateSelectionNoNulls( Aggregation myagg, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, int batchSize, int[] selected) { for (int j=0; j< batchSize; ++j) { int i = selected[j]; - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); + myagg.checkValue(inputColVector.vector[i], + inputColVector.start[i], + inputColVector.length[i]); } } private void iterateNoSelectionHasNulls( Aggregation myagg, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, int batchSize) { for (int i=0; i< batchSize; ++i) { - if (!inputColumn.isNull[i]) { - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); + if (!inputColVector.isNull[i]) { + myagg.checkValue(inputColVector.vector[i], + inputColVector.start[i], + inputColVector.length[i]); } } } private void iterateNoSelectionNoNulls( Aggregation myagg, - BytesColumnVector inputColumn, + BytesColumnVector inputColVector, int batchSize) { for (int i=0; i< batchSize; ++i) { - myagg.checkValue(inputColumn.vector[i], - inputColumn.start[i], - inputColumn.length[i]); + myagg.checkValue(inputColVector.vector[i], + inputColVector.start[i], + inputColVector.length[i]); } } diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxTimestamp.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxTimestamp.txt index 7e34965..f15fa4f 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxTimestamp.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxTimestamp.txt @@ -128,15 +128,20 @@ public class extends VectorAggregateExpression { if (inputColVector.noNulls) { if (inputColVector.isRepeating) { + // 1. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. iterateNoNullsRepeatingWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batchSize); } else { if (batch.selectedInUse) { + // 2. iterateNoNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batch.selected, batchSize); } else { + // 3. iterateNoNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batchSize); @@ -144,21 +149,20 @@ public class extends VectorAggregateExpression { } } else { if (inputColVector.isRepeating) { - if (batch.selectedInUse) { - iterateHasNullsRepeatingSelectionWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColVector, batchSize, batch.selected, inputColVector.isNull); - } else { - iterateHasNullsRepeatingWithAggregationSelection( - aggregationBufferSets, aggregrateIndex, - inputColVector, batchSize, inputColVector.isNull); - } + // 4. + // With repeated, row 0 always has the value so we don't have to look at + // selectedInUse. + iterateHasNullsRepeatingWithAggregationSelection( + aggregationBufferSets, aggregrateIndex, + inputColVector, batchSize, inputColVector.isNull); } else { if (batch.selectedInUse) { + // 5. iterateHasNullsSelectionWithAggregationSelection( aggregationBufferSets, aggregrateIndex, - inputColVector, batchSize, batch.selected, inputColVector.isNull); + inputColVector, batchSize, batch.selected); } else { + // 6. iterateHasNullsWithAggregationSelection( aggregationBufferSets, aggregrateIndex, inputColVector, batchSize, inputColVector.isNull); @@ -167,6 +171,7 @@ public class extends VectorAggregateExpression { } } + // 1. private void iterateNoNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -183,6 +188,7 @@ public class extends VectorAggregateExpression { } } + // 2. private void iterateNoNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -199,6 +205,7 @@ public class extends VectorAggregateExpression { } } + // 3. private void iterateNoNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -213,57 +220,39 @@ public class extends VectorAggregateExpression { } } - private void iterateHasNullsRepeatingSelectionWithAggregationSelection( + // 4. + private void iterateHasNullsRepeatingWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, TimestampColumnVector inputColVector, int batchSize, - int[] selection, boolean[] isNull) { - for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - // Repeating use index 0. - myagg.checkValue(inputColVector, 0); - } + if (isNull[0]) { + return; } - } - - private void iterateHasNullsRepeatingWithAggregationSelection( - VectorAggregationBufferRow[] aggregationBufferSets, - int aggregrateIndex, - TimestampColumnVector inputColVector, - int batchSize, - boolean[] isNull) { - for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - // Repeating use index 0. - myagg.checkValue(inputColVector, 0); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + // Repeating use index 0. + myagg.checkValue(inputColVector, 0); } } + // 5. private void iterateHasNullsSelectionWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, TimestampColumnVector inputColVector, int batchSize, - int[] selection, - boolean[] isNull) { + int[] selection) { for (int j=0; j < batchSize; ++j) { int i = selection[j]; - if (!isNull[i]) { + if (!inputColVector.isNull[i]) { Aggregation myagg = getCurrentAggregationBuffer( aggregationBufferSets, aggregrateIndex, @@ -273,6 +262,7 @@ public class extends VectorAggregateExpression { } } + // 6. private void iterateHasNullsWithAggregationSelection( VectorAggregationBufferRow[] aggregationBufferSets, int aggregrateIndex, @@ -309,10 +299,8 @@ public class extends VectorAggregateExpression { Aggregation myagg = (Aggregation)agg; if (inputColVector.isRepeating) { - if (inputColVector.noNulls && - (myagg.isNull || (inputColVector.compareTo(myagg.value, 0) 0))) { - myagg.isNull = false; - inputColVector.timestampUpdate(myagg.value, 0); + if (inputColVector.noNulls || !inputColVector.isNull[0]) { + myagg.checkValue(inputColVector, 0); } return; }