[ https://issues.apache.org/jira/browse/HIVE-23975?focusedWorklogId=465807&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-465807 ]
ASF GitHub Bot logged work on HIVE-23975: ----------------------------------------- Author: ASF GitHub Bot Created on: 03/Aug/20 16:45 Start Date: 03/Aug/20 16:45 Worklog Time Spent: 10m Work Description: mustafaiman commented on a change in pull request #1352: URL: https://github.com/apache/hive/pull/1352#discussion_r464532531 ########## 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: `clone.byteStarts[i]` is always zero but `byteStarts[i]` can be different values, depending on how it was assigned initially in `VectorHashKeyWrapperBatch#assignString` methods. Example: assignStringBullsNoRepeatingSelection ---------------------------------------------------------------- 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: 465807) Time Spent: 40m (was: 0.5h) > 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: 40m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)