diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/VectorHashKeyWrapperBatch.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/VectorHashKeyWrapperBatch.java index cd57151..b4d7a5d 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/VectorHashKeyWrapperBatch.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/VectorHashKeyWrapperBatch.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.serde2.io.DoubleWritable; import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; /** @@ -43,6 +44,7 @@ * */ private static class KeyLookupHelper { + public int intIndex; public int longIndex; public int doubleIndex; public int stringIndex; @@ -87,6 +89,11 @@ private LongWritable[] longKeyValueOutput; /** + * preallocated and reause IntWritable object for emiting row mode key values + */ + private IntWritable[] intKeyValueOutput; + + /** * preallocated and reused DoubleWritable objects for emiting row mode key values */ private DoubleWritable[] doubleKeyValueOutput; @@ -446,6 +453,7 @@ public static VectorHashKeyWrapperBatch compileKeyWrapperBatch(VectorExpression[ int doubleIndicesIndex = 0; int[] stringIndices = new int[keyExpressions.length]; int stringIndicesIndex = 0; + int intIndicesIndex = 0; KeyLookupHelper[] indexLookup = new KeyLookupHelper[keyExpressions.length]; // Inspect the output type of each key expression. @@ -453,23 +461,37 @@ public static VectorHashKeyWrapperBatch compileKeyWrapperBatch(VectorExpression[ indexLookup[i] = new KeyLookupHelper(); String outputType = keyExpressions[i].getOutputType(); if (outputType.equalsIgnoreCase("long") || - outputType.equalsIgnoreCase("bigint") || - outputType.equalsIgnoreCase("int")) { + outputType.equalsIgnoreCase("bigint")) { + longIndices[longIndicesIndex] = i; + indexLookup[i].longIndex = longIndicesIndex; + indexLookup[i].doubleIndex = -1; + indexLookup[i].stringIndex = -1; + indexLookup[i].intIndex = -1; + ++longIndicesIndex; + } else if (outputType.equalsIgnoreCase("int")) { + /* 'int' is special: the key value is stored as 'long' + * but the writable output is written as int + */ + longIndices[longIndicesIndex] = i; indexLookup[i].longIndex = longIndicesIndex; indexLookup[i].doubleIndex = -1; indexLookup[i].stringIndex = -1; + indexLookup[i].intIndex = intIndicesIndex; ++longIndicesIndex; + ++intIndicesIndex; } else if (outputType.equalsIgnoreCase("double")) { doubleIndices[doubleIndicesIndex] = i; indexLookup[i].longIndex = -1; indexLookup[i].doubleIndex = doubleIndicesIndex; indexLookup[i].stringIndex = -1; + indexLookup[i].intIndex = -1; ++doubleIndicesIndex; } else if (outputType.equalsIgnoreCase("string")) { indexLookup[i].longIndex = -1; indexLookup[i].doubleIndex = -1; stringIndices[i]= stringIndicesIndex; + indexLookup[i].intIndex = -1; ++stringIndicesIndex; } else { @@ -481,6 +503,10 @@ public static VectorHashKeyWrapperBatch compileKeyWrapperBatch(VectorExpression[ for (int i=0; i < longIndicesIndex; ++i) { compiledKeyWrapperBatch.longKeyValueOutput[i] = new LongWritable(); } + compiledKeyWrapperBatch.intKeyValueOutput = new IntWritable[intIndicesIndex]; + for(int i=0; i < intIndicesIndex; ++i) { + compiledKeyWrapperBatch.intKeyValueOutput[i] = new IntWritable(); + } compiledKeyWrapperBatch.doubleKeyValueOutput = new DoubleWritable[doubleIndicesIndex]; for (int i=0; i < doubleIndicesIndex; ++i) { compiledKeyWrapperBatch.doubleKeyValueOutput[i] = new DoubleWritable(); @@ -510,7 +536,10 @@ public Object getWritableKeyValue(VectorHashKeyWrapper kw, int i) return null; } KeyLookupHelper klh = indexLookup[i]; - if (klh.longIndex >= 0) { + if (klh.intIndex >= 0) { + intKeyValueOutput[klh.intIndex].set((int) kw.getLongValue(i)); + return intKeyValueOutput[klh.intIndex]; + } else if (klh.longIndex >= 0) { longKeyValueOutput[klh.longIndex].set(kw.getLongValue(i)); return longKeyValueOutput[klh.longIndex]; } else if (klh.doubleIndex >= 0) { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java index 04d362d..c717527 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java @@ -1077,9 +1077,10 @@ public ObjectInspector createObjectInspector(VectorExpression vectorExpression) throws HiveException { String columnType = vectorExpression.getOutputType(); if (columnType.equalsIgnoreCase("long") || - columnType.equalsIgnoreCase("bigint") || - columnType.equalsIgnoreCase("int")) { + columnType.equalsIgnoreCase("bigint")) { return PrimitiveObjectInspectorFactory.writableLongObjectInspector; + } else if (columnType.equalsIgnoreCase("int")) { + return PrimitiveObjectInspectorFactory.writableIntObjectInspector; } else if (columnType.equalsIgnoreCase("double")) { return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; } else if (columnType.equalsIgnoreCase("string")) {