0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 package org.apache.hadoop.hive.ql.io.orc;
0019
0020 import org.apache.hadoop.conf.Configuration;
0021 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
0022 import org.apache.hadoop.io.NullWritable;
0023 import org.apache.hadoop.mapreduce.InputSplit;
0024 import org.apache.hadoop.mapreduce.TaskAttemptContext;
0025
0026 import java.io.IOException;
0027
0028
0029
0030
0031
0032
0033
0034 public class SparkOrcNewRecordReader extends
0035 org.apache.hadoop.mapreduce.RecordReader<NullWritable, OrcStruct> {
0036 private final org.apache.hadoop.hive.ql.io.orc.RecordReader reader;
0037 private final int numColumns;
0038 OrcStruct value;
0039 private float progress = 0.0f;
0040 private ObjectInspector objectInspector;
0041
0042 public SparkOrcNewRecordReader(Reader file, Configuration conf,
0043 long offset, long length) throws IOException {
0044 if (file.getTypes().isEmpty()) {
0045 numColumns = 0;
0046 } else {
0047 numColumns = file.getTypes().get(0).getSubtypesCount();
0048 }
0049 value = new OrcStruct(numColumns);
0050 this.reader = OrcInputFormat.createReaderFromFile(file, conf, offset,
0051 length);
0052 this.objectInspector = file.getObjectInspector();
0053 }
0054
0055 @Override
0056 public void close() throws IOException {
0057 reader.close();
0058 }
0059
0060 @Override
0061 public NullWritable getCurrentKey() throws IOException,
0062 InterruptedException {
0063 return NullWritable.get();
0064 }
0065
0066 @Override
0067 public OrcStruct getCurrentValue() throws IOException,
0068 InterruptedException {
0069 return value;
0070 }
0071
0072 @Override
0073 public float getProgress() throws IOException, InterruptedException {
0074 return progress;
0075 }
0076
0077 @Override
0078 public void initialize(InputSplit split, TaskAttemptContext context)
0079 throws IOException, InterruptedException {
0080 }
0081
0082 @Override
0083 public boolean nextKeyValue() throws IOException, InterruptedException {
0084 if (reader.hasNext()) {
0085 reader.next(value);
0086 progress = reader.getProgress();
0087 return true;
0088 } else {
0089 return false;
0090 }
0091 }
0092
0093 public ObjectInspector getObjectInspector() {
0094 return objectInspector;
0095 }
0096 }