@Override
public Iterator<T> read(FileSystem fs, final Path path) {
try {
if (!fs.isFile(path)) {
throw new CrunchRuntimeException("Not a file: " + path);
}
inputFn.initialize();
FileStatus status = fs.getFileStatus(path);
FileSplit split = new FileSplit(path, 0, status.getLen(), new String[0]);
JobConf conf = new JobConf();
if (readColumns != null) {
conf.setBoolean(OrcFileSource.HIVE_READ_ALL_COLUMNS, false);
conf.set(ColumnProjectionUtils.READ_COLUMN_IDS_CONF_STR, OrcFileSource.getColumnIdsStr(readColumns));
}
final RecordReader<NullWritable, OrcStruct> reader = inputFormat.getRecordReader(split, conf, Reporter.NULL);
return new UnmodifiableIterator<T>() {
private boolean checked = false;
private boolean hasNext;
private OrcStruct value;
private OrcWritable writable = new OrcWritable();
@Override
public boolean hasNext() {
try {
if (value == null) {
value = reader.createValue();
}
if (!checked) {
hasNext = reader.next(NullWritable.get(), value);
checked = true;
}
return hasNext;
} catch (Exception e) {
throw new CrunchRuntimeException("Error while reading local file: " + path, e);
}
}
@Override
public T next() {
try {
if (value == null) {
value = reader.createValue();
}
if (!checked) {
reader.next(NullWritable.get(), value);
}
checked = false;
writable.set(value);
return inputFn.map(writable);
} catch (Exception e) {
throw new CrunchRuntimeException("Error while reading local file: " + path, e);
}
}
};
} catch (Exception e) {
throw new CrunchRuntimeException("Error while reading local file: " + path, e);
}
}