HIVE-16182: Semijoin: Avoid VectorHashKeyWrapper allocations for the bloom hash aggregate (Gopal V, reviewed by Sergey Shelukhin)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/bfa03502 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/bfa03502 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/bfa03502 Branch: refs/heads/hive-14535 Commit: bfa035024082a08c0fde12a3c58f2b59ec57ef99 Parents: ba4f6e7 Author: Gopal V <[email protected]> Authored: Mon Mar 13 23:11:37 2017 +0530 Committer: Gopal V <[email protected]> Committed: Mon Mar 13 23:11:37 2017 +0530 ---------------------------------------------------------------------- .../ql/exec/vector/VectorHashKeyWrapper.java | 37 +++++++++++++++++++- .../exec/vector/VectorHashKeyWrapperBatch.java | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/bfa03502/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java index 2bd1850..5de59b1 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java @@ -47,6 +47,8 @@ public class VectorHashKeyWrapper extends KeyWrapper { private static final Timestamp[] EMPTY_TIMESTAMP_ARRAY = new Timestamp[0]; private static final HiveIntervalDayTime[] EMPTY_INTERVAL_DAY_TIME_ARRAY = new HiveIntervalDayTime[0]; + public static final VectorHashKeyWrapper EMPTY_KEY_WRAPPER = new EmptyVectorHashKeyWrapper(); + private long[] longValues; private double[] doubleValues; @@ -63,7 +65,7 @@ public class VectorHashKeyWrapper extends KeyWrapper { private boolean[] isNull; private int hashcode; - public VectorHashKeyWrapper(int longValuesCount, int doubleValuesCount, + private VectorHashKeyWrapper(int longValuesCount, int doubleValuesCount, int byteValuesCount, int decimalValuesCount, int timestampValuesCount, int intervalDayTimeValuesCount) { longValues = longValuesCount > 0 ? new long[longValuesCount] : EMPTY_LONG_ARRAY; @@ -97,6 +99,17 @@ public class VectorHashKeyWrapper extends KeyWrapper { private VectorHashKeyWrapper() { } + public static VectorHashKeyWrapper allocate(int longValuesCount, int doubleValuesCount, + int byteValuesCount, int decimalValuesCount, int timestampValuesCount, + int intervalDayTimeValuesCount) { + if ((longValuesCount + doubleValuesCount + byteValuesCount + decimalValuesCount + + timestampValuesCount + intervalDayTimeValuesCount) == 0) { + return EMPTY_KEY_WRAPPER; + } + return new VectorHashKeyWrapper(longValuesCount, doubleValuesCount, byteValuesCount, + decimalValuesCount, timestampValuesCount, intervalDayTimeValuesCount); + } + @Override public void getNewKey(Object row, ObjectInspector rowInspector) throws HiveException { throw new HiveException("Should not be called"); @@ -415,5 +428,27 @@ public class VectorHashKeyWrapper extends KeyWrapper { public HiveIntervalDayTime getIntervalDayTime(int i) { return intervalDayTimeValues[i]; } + + public static final class EmptyVectorHashKeyWrapper extends VectorHashKeyWrapper { + private EmptyVectorHashKeyWrapper() { + super(0, 0, 0, 0, 0, 0); + // no need to override assigns - all assign ops will fail due to 0 size + } + + @Override + protected Object clone() { + // immutable + return this; + } + + @Override + public boolean equals(Object that) { + if (that == this) { + // should only be one object + return true; + } + return super.equals(that); + } + } } http://git-wip-us.apache.org/repos/asf/hive/blob/bfa03502/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java index b4708b5..f68228c 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java @@ -744,7 +744,7 @@ public class VectorHashKeyWrapperBatch extends VectorColumnSetInfo { } public VectorHashKeyWrapper allocateKeyWrapper() { - return new VectorHashKeyWrapper(longIndices.length, doubleIndices.length, + return VectorHashKeyWrapper.allocate(longIndices.length, doubleIndices.length, stringIndices.length, decimalIndices.length, timestampIndices.length, intervalDayTimeIndices.length); }
