diff --git ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java index 2745bee..06a465f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java +++ ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java @@ -835,24 +835,48 @@ Object nextVector(Object previousVector, long batchSize) throws IOException { // Read present/isNull stream super.nextVector(result, batchSize); - // Read value entries based on isNull entries - for (int i = 0; i < batchSize; i++) { - if (!result.isNull[i]) { - result.vector[i] = utils.readFloat(stream); - } else { + final boolean hasNulls = !result.noNulls; + boolean allNulls = hasNulls; - // If the value is not present then set NaN - result.vector[i] = Double.NaN; + if (hasNulls) { + // conditions to ensure bounds checks skips + for (int i = 0; i < batchSize && batchSize <= result.isNull.length; i++) { + allNulls = allNulls & result.isNull[i]; } - } - - // Set isRepeating flag - result.isRepeating = true; - for (int i = 0; (i < batchSize - 1 && result.isRepeating); i++) { - if (result.vector[i] != result.vector[i + 1]) { + if (allNulls) { + result.vector[0] = Double.NaN; + result.isRepeating = true; + } else { + // some nulls result.isRepeating = false; + // conditions to ensure bounds checks skips + for (int i = 0; i < batchSize && batchSize <= result.isNull.length && batchSize <= result.vector.length; i++) { + if (!result.isNull[i]) { + result.vector[i] = utils.readFloat(stream); + } else { + // If the value is not present then set NaN + result.vector[i] = Double.NaN; + } + } } + } else if (batchSize > 1) { + // no nulls & > 1 row (check repeating) + boolean repeating = true; + final float f1 = utils.readFloat(stream); + result.vector[0] = f1; + // conditions to ensure bounds checks skips + for (int i = 1; i < batchSize && batchSize <= result.vector.length; i++) { + final float f2 = utils.readFloat(stream); + repeating = repeating && (f1 == f2); + result.vector[i] = f2; + } + result.isRepeating = repeating; + } else if (batchSize == 1) { + // no-nulls and 1 row + result.vector[0] = utils.readFloat(stream); + result.isRepeating = false; } + return result; } @@ -918,23 +942,48 @@ Object nextVector(Object previousVector, long batchSize) throws IOException { // Read present/isNull stream super.nextVector(result, batchSize); - // Read value entries based on isNull entries - for (int i = 0; i < batchSize; i++) { - if (!result.isNull[i]) { - result.vector[i] = utils.readDouble(stream); - } else { - // If the value is not present then set NaN - result.vector[i] = Double.NaN; - } - } + final boolean hasNulls = !result.noNulls; + boolean allNulls = hasNulls; - // Set isRepeating flag - result.isRepeating = true; - for (int i = 0; (i < batchSize - 1 && result.isRepeating); i++) { - if (result.vector[i] != result.vector[i + 1]) { + if (hasNulls) { + // conditions to ensure bounds checks skips + for (int i = 0; i < batchSize && batchSize <= result.isNull.length; i++) { + allNulls = allNulls & result.isNull[i]; + } + if (allNulls) { + result.vector[0] = Double.NaN; + result.isRepeating = true; + } else { + // some nulls result.isRepeating = false; + // conditions to ensure bounds checks skips + for (int i = 0; i < batchSize && batchSize <= result.isNull.length && batchSize <= result.vector.length; i++) { + if (!result.isNull[i]) { + result.vector[i] = utils.readDouble(stream); + } else { + // If the value is not present then set NaN + result.vector[i] = Double.NaN; + } + } + } + } else if (batchSize > 1) { + // no nulls & > 1 row + boolean repeating = true; + final double d1 = utils.readDouble(stream); + result.vector[0] = d1; + // conditions to ensure bounds checks skips + for (int i = 1; i < batchSize && batchSize <= result.vector.length; i++) { + final double d2 = utils.readDouble(stream); + repeating = repeating && (d1 == d2); + result.vector[i] = d2; } + result.isRepeating = repeating; + } else if (batchSize == 1) { + // no-nulls and 1 row + result.vector[0] = utils.readDouble(stream); + result.isRepeating = false; } + return result; }