Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion java/core/src/java/org/apache/orc/impl/OrcTail.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,32 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

import org.apache.orc.CompressionKind;
import org.apache.orc.OrcFile;
import org.apache.orc.OrcProto;
import org.apache.orc.OrcUtils;
import org.apache.orc.Reader;
import org.apache.orc.StripeInformation;
import org.apache.orc.StripeStatistics;
import org.apache.orc.TypeDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// TODO: Make OrcTail implement FileMetadata or Reader interface
public final class OrcTail {
private static final Logger LOG = LoggerFactory.getLogger(OrcTail.class);

// postscript + footer - Serialized in OrcSplit
private final OrcProto.FileTail fileTail;
// serialized representation of metadata, footer and postscript
private final BufferChunk serializedTail;
private final TypeDescription schema;
// used to invalidate cache entries
private final long fileModificationTime;
private final Reader reader;

public OrcTail(OrcProto.FileTail fileTail,
ByteBuffer serializedTail) throws IOException {
Expand All @@ -50,13 +58,19 @@ public OrcTail(OrcProto.FileTail fileTail, ByteBuffer serializedTail,
}

public OrcTail(OrcProto.FileTail fileTail, BufferChunk serializedTail,
long fileModificationTime) throws IOException {
long fileModificationTime) throws IOException {
this(fileTail, serializedTail, fileModificationTime, null);
}

public OrcTail(OrcProto.FileTail fileTail, BufferChunk serializedTail,
long fileModificationTime, Reader reader) throws IOException {
this.fileTail = fileTail;
this.serializedTail = serializedTail;
this.fileModificationTime = fileModificationTime;
List<OrcProto.Type> types = getTypes();
OrcUtils.isValidTypeTree(types, 0);
this.schema = OrcUtils.convertTypeFromProtobuf(types, 0);
this.reader = reader;
}

public ByteBuffer getSerializedTail() {
Expand Down Expand Up @@ -185,4 +199,19 @@ public OrcProto.FileTail getMinimalFileTail() {
fileTailBuilder.setFooter(footerBuilder.build());
return fileTailBuilder.build();
}

/**
* Get the stripe statistics from the file tail.
* This code is for compatibility with ORC 1.5.
* @return the stripe statistics
* @deprecated the user should use Reader.getStripeStatistics instead.
*/
public List<StripeStatistics> getStripeStatistics() throws IOException {
if (reader == null) {
LOG.warn("Please use Reader.getStripeStatistics or give `Reader` to OrcTail constructor.");
return new ArrayList<>();
} else {
return reader.getStripeStatistics();
}
}
}
4 changes: 2 additions & 2 deletions java/core/src/java/org/apache/orc/impl/ReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ OrcTail buildEmptyTail() throws IOException {
result.setPostscript(postscript);
result.setFileLength(0);
result.setPostscriptLength(0);
return new OrcTail(result.build(), new BufferChunk(0, 0), -1);
return new OrcTail(result.build(), new BufferChunk(0, 0), -1, this);
}

private static void read(FSDataInputStream file,
Expand Down Expand Up @@ -728,7 +728,7 @@ protected OrcTail extractFileTail(FileSystem fs, Path path,
new IOException("Problem reading file footer " + path, thr);
}

return new OrcTail(fileTailBuilder.build(), buffer, modificationTime);
return new OrcTail(fileTailBuilder.build(), buffer, modificationTime, this);
}

@Override
Expand Down