[ 
https://issues.apache.org/jira/browse/HIVE-23975?focusedWorklogId=465556&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-465556
 ]

ASF GitHub Bot logged work on HIVE-23975:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Aug/20 05:48
            Start Date: 03/Aug/20 05:48
    Worklog Time Spent: 10m 
      Work Description: rbalamohan commented on a change in pull request #1352:
URL: https://github.com/apache/hive/pull/1352#discussion_r464204771



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java
##########
@@ -514,7 +526,8 @@ private void 
prepareBatchAggregationBufferSets(VectorizedRowBatch batch) throws
           // is very important to clone the keywrapper, the one we have from 
our
           // keyWrappersBatch is going to be reset/reused on next batch.
           aggregationBuffer = allocateAggregationBuffer();

Review comment:
       allocateAggregationBuffer can be reused with the flushed out entries.

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/wrapper/VectorHashKeyWrapperGeneral.java
##########
@@ -262,6 +255,138 @@ private void duplicateTo(VectorHashKeyWrapperGeneral 
clone) {
 
     clone.hashcode = hashcode;
     assert clone.equals(this);
+
+    return clone;
+  }
+
+  private long[] copyInPlaceOrAllocate(long[] from, long[] to) {
+    if (from.length > 0) {
+      if (to != null && to.length == from.length) {
+        System.arraycopy(from, 0, to, 0, from.length);
+        return to;
+      } else {
+        return from.clone();
+      }
+    } else {
+      return EMPTY_LONG_ARRAY;
+    }
+  }
+
+  private double[] copyInPlaceOrAllocate(double[] from, double[] to) {
+    if (from.length > 0) {
+      if (to != null && to.length == from.length) {
+        System.arraycopy(from, 0, to, 0, from.length);
+        return to;
+      } else {
+        return from.clone();
+      }
+    } else {
+      return EMPTY_DOUBLE_ARRAY;
+    }
+  }
+
+  private boolean[] copyInPlaceOrAllocate(boolean[] from, boolean[] to) {
+    if (to != null && to.length == from.length) {
+      System.arraycopy(from, 0, to, 0, from.length);
+      return to;
+    } else {
+      return from.clone();
+    }
+  }
+
+  private HiveDecimalWritable[] copyInPlaceOrAllocate(HiveDecimalWritable[] 
from, HiveDecimalWritable[] to) {
+    if (from.length > 0) {
+      if (to == null || to.length != from.length) {
+        to = new HiveDecimalWritable[from.length];
+      }
+      for (int i = 0; i < from.length; i++) {
+        to[i] = new HiveDecimalWritable(from[i]);
+      }
+      return to;
+    } else {
+      return EMPTY_DECIMAL_ARRAY;
+    }
+  }
+
+  private Timestamp[] copyInPlaceOrAllocate(Timestamp[] from, Timestamp[] to) {
+    if (from.length > 0) {
+      if (to == null || to.length != from.length) {
+        to = new Timestamp[from.length];
+      }
+      for (int i = 0; i < from.length; i++) {
+        to[i] = (Timestamp) from[i].clone();
+      }
+      return to;
+    } else {
+      return EMPTY_TIMESTAMP_ARRAY;
+    }
+  }
+
+  @Override
+  public void copyKey(KeyWrapper oldWrapper) {
+    VectorHashKeyWrapperGeneral clone = (VectorHashKeyWrapperGeneral) 
oldWrapper;
+    clone.hashCtx = hashCtx;
+    clone.keyCount = keyCount;
+    clone.longValues = copyInPlaceOrAllocate(longValues, clone.longValues);
+    clone.doubleValues = copyInPlaceOrAllocate(doubleValues, 
clone.doubleValues);
+    clone.isNull = copyInPlaceOrAllocate(isNull, clone.isNull);
+    clone.decimalValues = copyInPlaceOrAllocate(decimalValues, 
clone.decimalValues);
+
+    if (byteLengths.length > 0) {
+      if (clone.byteLengths == null || clone.byteValues.length != 
byteValues.length) {
+        // byteValues and byteStarts are always the same length
+        clone.byteValues = new byte[byteValues.length][];
+        clone.byteStarts = new int[byteValues.length];
+        clone.byteLengths = byteLengths.clone();
+        for (int i = 0; i < byteValues.length; ++i) {
+          // avoid allocation/copy of nulls, because it potentially expensive.
+          // branch instead.
+          if (byteLengths[i] != -1) {
+            clone.byteValues[i] = Arrays.copyOfRange(byteValues[i],
+                byteStarts[i], byteStarts[i] + byteLengths[i]);
+          }
+        }
+      } else {
+        System.arraycopy(byteLengths, 0, clone.byteLengths, 0, 
byteValues.length);
+        Arrays.fill(byteStarts, 0);
+        System.arraycopy(byteStarts, 0, clone.byteStarts, 0, 
byteValues.length);
+        for (int i = 0; i < byteValues.length; ++i) {
+          // avoid allocation/copy of nulls, because it potentially expensive.
+          // branch instead.
+          if (byteLengths[i] != -1) {
+            if (clone.byteValues[i] != null && clone.byteValues[i].length >= 
byteValues[i].length) {
+              System.arraycopy(byteValues[i], byteStarts[i], 
clone.byteValues[i], 0, byteLengths[i]);
+            } else {
+              clone.byteValues[i] = Arrays.copyOfRange(byteValues[i],
+                  byteStarts[i], byteStarts[i] + byteLengths[i]);

Review comment:
       Why is this needed? Wouldn't be it always from 0 - bytelength?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 465556)
    Time Spent: 20m  (was: 10m)

> Reuse evicted keys from aggregation buffers
> -------------------------------------------
>
>                 Key: HIVE-23975
>                 URL: https://issues.apache.org/jira/browse/HIVE-23975
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Mustafa Iman
>            Assignee: Mustafa Iman
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to