diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java index 2bd1850..5de59b1 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapper.java @@ -47,6 +47,8 @@ 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 @@ 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 VectorHashKeyWrapper(int longValuesCount, int doubleValuesCount, 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 boolean getIsIntervalDayTimeNull(int i) { 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); + } + } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java index b4708b5..f68228c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorHashKeyWrapperBatch.java @@ -744,7 +744,7 @@ public static VectorHashKeyWrapperBatch compileKeyWrapperBatch(VectorExpression[ } 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); }