Stateless methods shared between RecordReaderImpl and EncodedReaderImpl.
| 48 | * Stateless methods shared between RecordReaderImpl and EncodedReaderImpl. |
| 49 | */ |
| 50 | public class RecordReaderUtils { |
| 51 | /** |
| 52 | * The maximum size of array to allocate, value being the same as {@link java.util.Hashtable} |
| 53 | */ |
| 54 | public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; |
| 55 | |
| 56 | private static final HadoopShims SHIMS = HadoopShimsFactory.get(); |
| 57 | private static final boolean supportVectoredIO = |
| 58 | SHIMS.supportVectoredIO(VersionInfo.getVersion()); |
| 59 | private static final Logger LOG = LoggerFactory.getLogger(RecordReaderUtils.class); |
| 60 | |
| 61 | private static class DefaultDataReader implements DataReader { |
| 62 | private FSDataInputStream file; |
| 63 | private ByteBufferAllocatorPool pool; |
| 64 | private HadoopShims.ZeroCopyReaderShim zcr = null; |
| 65 | private final Supplier<FileSystem> fileSystemSupplier; |
| 66 | private final Path path; |
| 67 | private final boolean useZeroCopy; |
| 68 | private final int minSeekSize; |
| 69 | private final double minSeekSizeTolerance; |
| 70 | private InStream.StreamOptions options; |
| 71 | private boolean isOpen = false; |
| 72 | |
| 73 | private DefaultDataReader(DataReaderProperties properties) { |
| 74 | this.fileSystemSupplier = properties.getFileSystemSupplier(); |
| 75 | this.path = properties.getPath(); |
| 76 | this.file = properties.getFile(); |
| 77 | this.useZeroCopy = properties.getZeroCopy(); |
| 78 | this.options = properties.getCompression(); |
| 79 | this.minSeekSize = properties.getMinSeekSize(); |
| 80 | this.minSeekSizeTolerance = properties.getMinSeekSizeTolerance(); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void open() throws IOException { |
| 85 | if (file == null) { |
| 86 | this.file = fileSystemSupplier.get().open(path); |
| 87 | } |
| 88 | if (useZeroCopy) { |
| 89 | // ZCR only uses codec for boolean checks. |
| 90 | pool = new ByteBufferAllocatorPool(); |
| 91 | zcr = RecordReaderUtils.createZeroCopyShim(file, options.getCodec(), pool); |
| 92 | } else { |
| 93 | zcr = null; |
| 94 | } |
| 95 | isOpen = true; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public OrcProto.StripeFooter readStripeFooter(StripeInformation stripe) throws IOException { |
| 100 | if (!isOpen) { |
| 101 | open(); |
| 102 | } |
| 103 | long offset = stripe.getOffset() + stripe.getIndexLength() + stripe.getDataLength(); |
| 104 | int tailLength = (int) stripe.getFooterLength(); |
| 105 | |
| 106 | // read the footer |
| 107 | ByteBuffer tailBuf = ByteBuffer.allocate(tailLength); |
nothing calls this directly
no test coverage detected