diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/avro/AvroGenericRecordReader.java b/ql/src/java/org/apache/hadoop/hive/ql/io/avro/AvroGenericRecordReader.java index 1381514..1048e44 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/avro/AvroGenericRecordReader.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/avro/AvroGenericRecordReader.java @@ -57,6 +57,7 @@ final private long start; final private long stop; protected JobConf jobConf; + final private boolean isEmptyInput; /** * A unique ID for each record reader. */ @@ -78,9 +79,18 @@ public AvroGenericRecordReader(JobConf job, FileSplit split, Reporter reporter) gdr.setExpected(latest); } - this.reader = new DataFileReader(new FsInput(split.getPath(), job), gdr); - this.reader.sync(split.getStart()); - this.start = reader.tell(); + if (split.getLength() == 0) { + this.isEmptyInput = true; + this.start = 0; + this.reader = null; + } + else { + this.isEmptyInput = false; + this.reader = new DataFileReader(new FsInput(split.getPath(), job), gdr); + this.reader.sync(split.getStart()); + this.start = reader.tell(); + } this.stop = split.getStart() + split.getLength(); this.recordReaderID = new UID(); } @@ -146,7 +156,7 @@ private boolean pathIsInPartition(Path split, String partitionPath) { @Override public boolean next(NullWritable nullWritable, AvroGenericRecordWritable record) throws IOException { - if(!reader.hasNext() || reader.pastSync(stop)) { + if(isEmptyInput || !reader.hasNext() || reader.pastSync(stop)) { return false; } @@ -170,12 +180,13 @@ public AvroGenericRecordWritable createValue() { @Override public long getPos() throws IOException { - return reader.tell(); + return isEmptyInput ? 0 : reader.tell(); } @Override public void close() throws IOException { - reader.close(); + if (isEmptyInput == false) + reader.close(); } @Override