From fc5d5924354f8c885e7439bd54dc8d49797b928c Mon Sep 17 00:00:00 2001 From: Gopal V Date: Thu, 14 Jan 2016 19:03:00 -0800 Subject: [PATCH] fix isNull checks in UDAFs for repeating ops --- .../vectorization/UDAFTemplates/VectorUDAFAvg.txt | 32 +++++++++++--------- .../UDAFTemplates/VectorUDAFMinMax.txt | 32 +++++++++++--------- .../UDAFTemplates/VectorUDAFMinMaxDecimal.txt | 16 +++++----- .../vectorization/UDAFTemplates/VectorUDAFSum.txt | 34 ++++++++++++---------- .../aggregates/VectorUDAFAvgDecimal.java | 32 +++++++++++--------- .../aggregates/VectorUDAFCountMerge.java | 32 +++++++++++--------- .../aggregates/VectorUDAFSumDecimal.java | 32 +++++++++++--------- 7 files changed, 118 insertions(+), 92 deletions(-) diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFAvg.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFAvg.txt index 6f7ee6a..d153fd6 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFAvg.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFAvg.txt @@ -235,15 +235,17 @@ public class extends VectorAggregateExpression { int batchSize, int[] selection, boolean[] isNull) { + + if (isNull[0]) { + return; + } for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(value); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(value); } } @@ -255,14 +257,16 @@ public class extends VectorAggregateExpression { int batchSize, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValue(value); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValue(value); } } diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt index 0595f71..46d66bd 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMax.txt @@ -214,15 +214,17 @@ public class extends VectorAggregateExpression { int batchSize, int[] selection, boolean[] isNull) { + + if (isNull[0]) { + return; + } for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(value); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(value); } } @@ -234,14 +236,16 @@ public class extends VectorAggregateExpression { int batchSize, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(value); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(value); } } diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt index 6912ced..9a48171 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFMinMaxDecimal.txt @@ -245,14 +245,16 @@ public class extends VectorAggregateExpression { int batchSize, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregrateIndex, - i); - myagg.checkValue(value, scale); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregrateIndex, + i); + myagg.checkValue(value, scale); } } diff --git ql/src/gen/vectorization/UDAFTemplates/VectorUDAFSum.txt ql/src/gen/vectorization/UDAFTemplates/VectorUDAFSum.txt index 4f70733..cc7e54d 100644 --- ql/src/gen/vectorization/UDAFTemplates/VectorUDAFSum.txt +++ ql/src/gen/vectorization/UDAFTemplates/VectorUDAFSum.txt @@ -210,15 +210,17 @@ public class extends VectorAggregateExpression { int batchSize, int[] selection, boolean[] isNull) { - + + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(value); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(value); } } @@ -230,14 +232,16 @@ public class extends VectorAggregateExpression { int batchSize, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(value); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(value); } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFAvgDecimal.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFAvgDecimal.java index 9cc0621..d0ff5fa 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFAvgDecimal.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFAvgDecimal.java @@ -293,14 +293,16 @@ private void iterateHasNullsRepeatingSelectionWithAggregationSelection( int[] selection, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValueWithNullCheck(value, this.sumScale); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValueWithNullCheck(value, this.sumScale); } } @@ -312,14 +314,16 @@ private void iterateHasNullsRepeatingWithAggregationSelection( int batchSize, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - bufferIndex, - i); - myagg.sumValueWithNullCheck(value, this.sumScale); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + bufferIndex, + i); + myagg.sumValueWithNullCheck(value, this.sumScale); } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFCountMerge.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFCountMerge.java index 7dabbd8..577977f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFCountMerge.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFCountMerge.java @@ -193,15 +193,17 @@ private void iterateHasNullsRepeatingSelectionWithAggregationSelection( int batchSize, int[] selection, boolean[] isNull) { + + if (isNull[0]) { + return; + } for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.value += value; - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.value += value; } } @@ -213,14 +215,16 @@ private void iterateHasNullsRepeatingWithAggregationSelection( int batchSize, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.value += value; - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.value += value; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java index 80b7131..3a5fef6 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java @@ -232,14 +232,16 @@ private void iterateHasNullsRepeatingSelectionWithAggregationSelection( int[] selection, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[selection[i]]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(value, scale); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(value, scale); } } @@ -252,14 +254,16 @@ private void iterateHasNullsRepeatingWithAggregationSelection( int batchSize, boolean[] isNull) { + if (isNull[0]) { + return; + } + for (int i=0; i < batchSize; ++i) { - if (!isNull[i]) { - Aggregation myagg = getCurrentAggregationBuffer( - aggregationBufferSets, - aggregateIndex, - i); - myagg.sumValue(value, scale); - } + Aggregation myagg = getCurrentAggregationBuffer( + aggregationBufferSets, + aggregateIndex, + i); + myagg.sumValue(value, scale); } } -- 2.4.0