// Path: hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/OrcLazyRow.java
// public class OrcLazyRow extends OrcLazyStruct {
// 
//   private OrcLazyObject[] fields;
//   private final List<String> fieldNames;
// 
//   public OrcLazyRow(OrcLazyObject[] fields, List<String> fieldNames) {
//     super(null);
//     this.fields = fields;
//     this.fieldNames = fieldNames;
//   }
// 
//   @Override
//   public void next() {
//     super.next();
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.next();
//       }
//     }
//   }
// 
//   @Override
//   public void startStripe(Map<StreamName, InStream> streams, List<OrcProto.ColumnEncoding> encodings,
//       RowIndex[] indexes, long rowBaseInStripe) throws IOException {
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.startStripe(streams, encodings, indexes, rowBaseInStripe);
//       }
//     }
//   }
// 
//   @Override
//   public Object materialize(long row, Object previous) throws IOException {
//     OrcStruct previousRow;
//     if (previous != null) {
//       previousRow = (OrcStruct) previous;
//       previousRow.setFieldNames(fieldNames);
//     } else {
//       previousRow = new OrcStruct(fieldNames);
//     }
//     for (int i = 0; i < fields.length; i++) {
//       previousRow.setFieldValue(i, fields[i]);
//     }
//     return previousRow;
//   }
// 
//   @Override
//   public void seekToRow(long rowNumber) throws IOException {
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.seekToRow(rowNumber);
//       }
//     }
//   }
// 
//   public int getNumFields() {
//     return fields.length;
//   }
// 
//   public OrcLazyObject getFieldValue(int index) {
//     if (index >= fields.length) {
//       return null;
//     }
// 
//     return fields[index];
//   }
// 
//   public void reset(OrcLazyRow other) throws IOException {
//     this.fields = other.getRawFields();
//     seekToRow(0);
//   }
// 
//   public OrcLazyObject[] getRawFields() {
//     return fields;
//   }
// 
//   @Override
//   public void close() throws IOException {
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.close();
//       }
//     }
//   }
// }


import com.facebook.hive.orc.lazy.OrcLazyRow;
import com.facebook.presto.hadoop.shaded.com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.serde2.ReaderWriterProfiler;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.RecordWriter;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Random;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
    jobConf.setLong(OrcConf.ConfVars.HIVE_ORC_STRIPE_SIZE.varname, 1024L);
    final Path filePath = new Path(this.stagingDir.toString(), fileName);
    final RecordWriter hiveRecordWriter = (RecordWriter) (new OrcOutputFormat().getHiveRecordWriter(
        jobConf, filePath, null, true, new Properties(), null));

    final OrcSerde orcSerde = new OrcSerde();
    ObjectInspector objectInspector = getObjectInspectorFor(
        ImmutableList.of("col1"),
        ImmutableList.of("bigint"));

    final Random rand = new Random();
    for (int i = 0; i < 1000; i++) {
      final List<Object> allColumns = new ArrayList<>();
      allColumns.add(rand.nextLong());
      Object obj = orcSerde.serialize(allColumns, objectInspector);
      hiveRecordWriter.write(NullWritable.get(), obj);
    }
    hiveRecordWriter.close(null);

    // Get all the stripes in the file written.
    final Configuration configuration = new Configuration();
    final FileSystem fileSystem = filePath.getFileSystem(configuration);
    final ReaderImpl readerImpl = new ReaderImpl(fileSystem, filePath, configuration);
    final ArrayList<StripeInformation> stripes = Lists.newArrayList(readerImpl.getStripes());
    assertTrue("Number of stripes produced should be >= 2", stripes.size() >= 2);

    // Read the file back and read with ReaderImpl over only the 2nd stripe.
    final boolean[] toRead = {true, true};
    final RecordReader recordReader = new ReaderImpl(fileSystem, filePath, configuration).rows(
        stripes.get(1).getOffset(), stripes.get(1).getDataLength(), toRead);
// Path: hive-dwrf/src/main/java/com/facebook/hive/orc/lazy/OrcLazyRow.java
// public class OrcLazyRow extends OrcLazyStruct {
// 
//   private OrcLazyObject[] fields;
//   private final List<String> fieldNames;
// 
//   public OrcLazyRow(OrcLazyObject[] fields, List<String> fieldNames) {
//     super(null);
//     this.fields = fields;
//     this.fieldNames = fieldNames;
//   }
// 
//   @Override
//   public void next() {
//     super.next();
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.next();
//       }
//     }
//   }
// 
//   @Override
//   public void startStripe(Map<StreamName, InStream> streams, List<OrcProto.ColumnEncoding> encodings,
//       RowIndex[] indexes, long rowBaseInStripe) throws IOException {
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.startStripe(streams, encodings, indexes, rowBaseInStripe);
//       }
//     }
//   }
// 
//   @Override
//   public Object materialize(long row, Object previous) throws IOException {
//     OrcStruct previousRow;
//     if (previous != null) {
//       previousRow = (OrcStruct) previous;
//       previousRow.setFieldNames(fieldNames);
//     } else {
//       previousRow = new OrcStruct(fieldNames);
//     }
//     for (int i = 0; i < fields.length; i++) {
//       previousRow.setFieldValue(i, fields[i]);
//     }
//     return previousRow;
//   }
// 
//   @Override
//   public void seekToRow(long rowNumber) throws IOException {
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.seekToRow(rowNumber);
//       }
//     }
//   }
// 
//   public int getNumFields() {
//     return fields.length;
//   }
// 
//   public OrcLazyObject getFieldValue(int index) {
//     if (index >= fields.length) {
//       return null;
//     }
// 
//     return fields[index];
//   }
// 
//   public void reset(OrcLazyRow other) throws IOException {
//     this.fields = other.getRawFields();
//     seekToRow(0);
//   }
// 
//   public OrcLazyObject[] getRawFields() {
//     return fields;
//   }
// 
//   @Override
//   public void close() throws IOException {
//     for (OrcLazyObject field : fields) {
//       if (field != null) {
//         field.close();
//       }
//     }
//   }
// }


// Path: hive-dwrf/src/test/java/com/facebook/hive/orc/TestRecordReaderImpl.java
import com.facebook.hive.orc.lazy.OrcLazyRow;
import com.facebook.presto.hadoop.shaded.com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.serde2.ReaderWriterProfiler;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.RecordWriter;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Random;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

    jobConf.setLong(OrcConf.ConfVars.HIVE_ORC_STRIPE_SIZE.varname, 1024L);
    final Path filePath = new Path(this.stagingDir.toString(), fileName);
    final RecordWriter hiveRecordWriter = (RecordWriter) (new OrcOutputFormat().getHiveRecordWriter(
        jobConf, filePath, null, true, new Properties(), null));

    final OrcSerde orcSerde = new OrcSerde();
    ObjectInspector objectInspector = getObjectInspectorFor(
        ImmutableList.of("col1"),
        ImmutableList.of("bigint"));

    final Random rand = new Random();
    for (int i = 0; i < 1000; i++) {
      final List<Object> allColumns = new ArrayList<>();
      allColumns.add(rand.nextLong());
      Object obj = orcSerde.serialize(allColumns, objectInspector);
      hiveRecordWriter.write(NullWritable.get(), obj);
    }
    hiveRecordWriter.close(null);

    // Get all the stripes in the file written.
    final Configuration configuration = new Configuration();
    final FileSystem fileSystem = filePath.getFileSystem(configuration);
    final ReaderImpl readerImpl = new ReaderImpl(fileSystem, filePath, configuration);
    final ArrayList<StripeInformation> stripes = Lists.newArrayList(readerImpl.getStripes());
    assertTrue("Number of stripes produced should be >= 2", stripes.size() >= 2);

    // Read the file back and read with ReaderImpl over only the 2nd stripe.
    final boolean[] toRead = {true, true};
    final RecordReader recordReader = new ReaderImpl(fileSystem, filePath, configuration).rows(
        stripes.get(1).getOffset(), stripes.get(1).getDataLength(), toRead);
    OrcLazyRow row = null;