Github user prasanthj commented on a diff in the pull request: https://github.com/apache/orc/pull/60#discussion_r79095023 --- Diff: java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java --- @@ -106,49 +198,58 @@ public OrcIndex readRowIndex(StripeInformation stripe, if (indexes == null) { indexes = new OrcProto.RowIndex[typeCount]; } + if (bloomFilterKinds == null) { + bloomFilterKinds = new OrcProto.Stream.Kind[typeCount]; + } if (bloomFilterIndices == null) { bloomFilterIndices = new OrcProto.BloomFilterIndex[typeCount]; } - long offset = stripe.getOffset(); - List<OrcProto.Stream> streams = footer.getStreamsList(); - for (int i = 0; i < streams.size(); i++) { - OrcProto.Stream stream = streams.get(i); - OrcProto.Stream nextStream = null; - if (i < streams.size() - 1) { - nextStream = streams.get(i+1); + DiskRangeList ranges = planIndexReading(fileSchema, footer, + ignoreNonUtf8BloomFilter, included, sargColumns, bloomFilterKinds); + ranges = readDiskRanges(file, zcr, stripe.getOffset(), ranges, false); + long offset = 0; + DiskRangeList range = ranges; + for(OrcProto.Stream stream: footer.getStreamsList()) { + // advance to find the next range + while (range != null && range.getEnd() <= offset) { + range = range.next; } - int col = stream.getColumn(); - int len = (int) stream.getLength(); - // row index stream and bloom filter are interlaced, check if the sarg column contains bloom - // filter and combine the io to read row index and bloom filters for that column together - if (stream.hasKind() && (stream.getKind() == OrcProto.Stream.Kind.ROW_INDEX)) { - boolean readBloomFilter = false; - if (sargColumns != null && sargColumns[col] && - nextStream.getKind() == OrcProto.Stream.Kind.BLOOM_FILTER) { - len += nextStream.getLength(); - i += 1; - readBloomFilter = true; - } - if ((included == null || included[col]) && indexes[col] == null) { - byte[] buffer = new byte[len]; - file.readFully(offset, buffer, 0, buffer.length); - ByteBuffer bb = ByteBuffer.wrap(buffer); - indexes[col] = OrcProto.RowIndex.parseFrom(InStream.create("index", - ReaderImpl.singleton(new BufferChunk(bb, 0)), stream.getLength(), - codec, bufferSize)); - if (readBloomFilter) { - bb.position((int) stream.getLength()); - bloomFilterIndices[col] = OrcProto.BloomFilterIndex.parseFrom(InStream.create( - "bloom_filter", ReaderImpl.singleton(new BufferChunk(bb, 0)), - nextStream.getLength(), codec, bufferSize)); - } + // no more ranges, so we are done + if (range == null) { + break; + } + int column = stream.getColumn(); + if (stream.hasKind() && range.getOffset() <= offset) { + switch (stream.getKind()) { + case ROW_INDEX: + if (included == null || included[column]) { + ByteBuffer bb = range.getData().duplicate(); + bb.position((int) (offset - range.getOffset())); + bb.limit((int) (bb.position() + stream.getLength())); + indexes[column] = OrcProto.RowIndex.parseFrom(InStream.create("index", --- End diff -- use InStream.createCodedInputStream() instead? to void metadata explosion.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---