public class TsFileSequenceReader extends Object implements AutoCloseable
| Modifier and Type | Class and Description |
|---|---|
static class |
TsFileSequenceReader.LocateStatus
The location of a chunkGroupMetaData with respect to a space partition constraint.
|
| Modifier and Type | Field and Description |
|---|---|
protected static TSFileConfig |
config |
protected String |
file |
protected long |
fileMetadataPos |
protected int |
fileMetadataSize |
protected TsFileInput |
tsFileInput |
protected TsFileMetadata |
tsFileMetaData |
| Constructor and Description |
|---|
TsFileSequenceReader(String file)
Create a file reader of the given file.
|
TsFileSequenceReader(String file,
boolean loadMetadataSize)
construct function for TsFileSequenceReader.
|
TsFileSequenceReader(String file,
boolean loadMetadata,
boolean cacheDeviceMetadata) |
TsFileSequenceReader(TsFileInput input)
Create a file reader of the given file.
|
TsFileSequenceReader(TsFileInput input,
boolean loadMetadataSize)
construct function for TsFileSequenceReader.
|
TsFileSequenceReader(TsFileInput input,
long fileMetadataPos,
int fileMetadataSize)
construct function for TsFileSequenceReader.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
binarySearchInTimeseriesMetadataList(List<TimeseriesMetadata> timeseriesMetadataList,
String key) |
long |
checkChunkAndPagesStatistics(IChunkMetadata chunkMetadata) |
void |
close() |
long |
fileSize() |
List<AlignedChunkMetadata> |
getAlignedChunkMetadata(String device)
Get AlignedChunkMetadata of sensors under one device
|
List<String> |
getAllDevices() |
TsFileDeviceIterator |
getAllDevicesIteratorWithIsAligned() |
Map<String,TSDataType> |
getAllMeasurements()
get all measurements in this file
|
List<Path> |
getAllPaths()
this function return all timeseries names
|
Map<String,List<TimeseriesMetadata>> |
getAllTimeseriesMetadata(boolean needChunkMetadata) |
List<ChunkMetadata> |
getChunkMetadataList(Path path) |
List<ChunkMetadata> |
getChunkMetadataList(Path path,
boolean ignoreNotExists)
get ChunkMetaDatas of given path, and throw exception if path not exists
|
Map<String,List<String>> |
getDeviceMeasurementsMap() |
List<String> |
getDeviceNameInRange(long start,
long end)
get device names which has valid chunks in [start, end)
|
long |
getFileMetadataPos() |
long |
getFileMetadataSize()
Return the whole meta data size of this tsfile, including ChunkMetadata, TimeseriesMetadata and
etc.
|
String |
getFileName() |
List<IChunkMetadata> |
getIChunkMetadataList(Path path) |
long |
getMaxPlanIndex() |
Iterator<Map<String,List<ChunkMetadata>>> |
getMeasurementChunkMetadataListMapIterator(String device) |
protected Pair<MetadataIndexEntry,Long> |
getMetadataAndEndOffset(MetadataIndexNode metadataIndex,
String name,
boolean isDeviceLevel,
boolean exactSearch)
Get target MetadataIndexEntry and its end offset
|
MetadataIndexNode |
getMetadataIndexNode(long startOffset,
long endOffset)
get metadata index node
|
long |
getMinPlanIndex() |
Iterator<List<Path>> |
getPathsIterator() |
int |
getTsFileMetadataSize() |
int |
hashCode() |
boolean |
isComplete()
whether the file is a complete TsFile: only if the head magic and tail magic string exists.
|
void |
loadMetadataSize() |
long |
position() |
void |
position(long offset) |
BloomFilter |
readBloomFilter()
this function does not modify the position of the file reader.
|
ChunkGroupHeader |
readChunkGroupHeader()
read data from current position of the input, and deserialize it to a CHUNK_GROUP_FOOTER.
|
ChunkGroupHeader |
readChunkGroupHeader(long position,
boolean markerRead)
read data from current position of the input, and deserialize it to a CHUNK_GROUP_FOOTER.
|
ChunkHeader |
readChunkHeader(byte chunkType)
read data from current position of the input, and deserialize it to a CHUNK_HEADER.
|
Map<String,List<ChunkMetadata>> |
readChunkMetadataInDevice(String device)
read all ChunkMetaDatas of given device
|
List<ChunkMetadata> |
readChunkMetaDataList(TimeseriesMetadata timeseriesMetaData)
get ChunkMetaDatas in given TimeseriesMetaData
|
ByteBuffer |
readCompressedPage(PageHeader header) |
protected ByteBuffer |
readData(long position,
int totalSize)
read data from tsFileInput, from the current position (if position = -1), or the given
position.
|
protected ByteBuffer |
readData(long start,
long end)
read data from tsFileInput, from the current position (if position = -1), or the given
position.
|
Map<String,TimeseriesMetadata> |
readDeviceMetadata(String device)
this function reads measurements and TimeseriesMetaDatas in given device Thread Safe
|
TsFileMetadata |
readFileMetadata()
this function does not modify the position of the file reader.
|
String |
readHeadMagic()
this function does not modify the position of the file reader.
|
List<IChunkMetadata> |
readIChunkMetaDataList(ITimeSeriesMetadata timeseriesMetaData) |
ITimeSeriesMetadata |
readITimeseriesMetadata(Path path,
boolean ignoreNotExists) |
List<ITimeSeriesMetadata> |
readITimeseriesMetadata(String device,
Set<String> measurements) |
byte |
readMarker()
read one byte from the input.
|
Chunk |
readMemChunk(CachedChunkLoaderImpl.ChunkCacheKey chunkCacheKey)
read memory chunk.
|
Chunk |
readMemChunk(ChunkMetadata metaData)
read memory chunk.
|
ByteBuffer |
readPage(PageHeader header,
CompressionType type) |
PageHeader |
readPageHeader(TSDataType type,
boolean hasStatistic)
not thread safe.
|
void |
readPlanIndex() |
int |
readRaw(long position,
int length,
ByteBuffer target)
notice, the target bytebuffer are not flipped.
|
String |
readTailMagic()
this function does not modify the position of the file reader.
|
TimeseriesMetadata |
readTimeseriesMetadata(Path path,
boolean ignoreNotExists) |
List<TimeseriesMetadata> |
readTimeseriesMetadata(Path path,
Set<String> allSensors) |
byte |
readVersionNumber()
this function reads version number and checks compatibility of TsFile.
|
long |
selfCheck(Map<Path,IMeasurementSchema> newSchema,
List<ChunkGroupMetadata> chunkGroupMetadataList,
boolean fastFinish)
Self Check the file and return the position before where the data is safe.
|
long |
selfCheckWithInfo(String filename,
boolean fastFinish,
Map<Long,Pair<Path,TimeseriesMetadata>> timeseriesMetadataMap)
Self Check the file and return whether the file is safe.
|
void |
skipPageData(PageHeader header) |
protected static final TSFileConfig config
protected String file
protected TsFileInput tsFileInput
protected long fileMetadataPos
protected int fileMetadataSize
protected TsFileMetadata tsFileMetaData
public TsFileSequenceReader(String file) throws IOException
file - the data fileIOException - If some I/O error occurspublic TsFileSequenceReader(String file, boolean loadMetadataSize) throws IOException
file - -given file nameloadMetadataSize - -whether load meta data sizeIOExceptionpublic TsFileSequenceReader(String file, boolean loadMetadata, boolean cacheDeviceMetadata) throws IOException
IOExceptionpublic TsFileSequenceReader(TsFileInput input) throws IOException
input - given inputIOExceptionpublic TsFileSequenceReader(TsFileInput input, boolean loadMetadataSize) throws IOException
input - -given inputloadMetadataSize - -load meta data sizeIOExceptionpublic TsFileSequenceReader(TsFileInput input, long fileMetadataPos, int fileMetadataSize)
input - the input of a tsfile. The current position should be a marker and then a chunk
Header, rather than the magic numberfileMetadataPos - the position of the file metadata in the TsFileInput from the beginning
of the input to the current positionfileMetadataSize - the byte size of the file metadata in the inputpublic void loadMetadataSize()
throws IOException
IOExceptionpublic long getFileMetadataPos()
public int getTsFileMetadataSize()
public long getFileMetadataSize()
throws IOException
IOExceptionpublic String readTailMagic() throws IOException
IOExceptionpublic boolean isComplete()
throws IOException
IOExceptionpublic String readHeadMagic() throws IOException
IOExceptionpublic byte readVersionNumber()
throws IOException
IOExceptionpublic TsFileMetadata readFileMetadata() throws IOException
IOException - io errorpublic BloomFilter readBloomFilter() throws IOException
IOException - io errorpublic Map<String,TimeseriesMetadata> readDeviceMetadata(String device) throws IOException
device - nameIOException - io errorpublic TimeseriesMetadata readTimeseriesMetadata(Path path, boolean ignoreNotExists) throws IOException
IOExceptionpublic ITimeSeriesMetadata readITimeseriesMetadata(Path path, boolean ignoreNotExists) throws IOException
IOExceptionpublic List<TimeseriesMetadata> readTimeseriesMetadata(Path path, Set<String> allSensors) throws IOException
IOExceptionpublic List<ITimeSeriesMetadata> readITimeseriesMetadata(String device, Set<String> measurements) throws IOException
IOExceptionprotected int binarySearchInTimeseriesMetadataList(List<TimeseriesMetadata> timeseriesMetadataList, String key)
public List<String> getAllDevices() throws IOException
IOExceptionpublic TsFileDeviceIterator getAllDevicesIteratorWithIsAligned() throws IOException
IOExceptionpublic Map<String,List<ChunkMetadata>> readChunkMetadataInDevice(String device) throws IOException
device - nameIOException - io errorpublic List<Path> getAllPaths() throws IOException
IOException - io errorpublic Iterator<List<Path>> getPathsIterator() throws IOException
IOException - io errorpublic Map<String,List<TimeseriesMetadata>> getAllTimeseriesMetadata(boolean needChunkMetadata) throws IOException
IOExceptionprotected Pair<MetadataIndexEntry,Long> getMetadataAndEndOffset(MetadataIndexNode metadataIndex, String name, boolean isDeviceLevel, boolean exactSearch) throws IOException
metadataIndex - given MetadataIndexNodename - target device / measurement nameisDeviceLevel - whether target MetadataIndexNode is device levelexactSearch - whether is in exact search mode, return null when there is no entry with
name; or else return the nearest MetadataIndexEntry before it (for deeper search)IOExceptionpublic ChunkGroupHeader readChunkGroupHeader() throws IOException
IOException - io errorpublic ChunkGroupHeader readChunkGroupHeader(long position, boolean markerRead) throws IOException
position - the offset of the chunk group footer in the filemarkerRead - true if the offset does not contains the marker , otherwise falseIOException - io errorpublic void readPlanIndex()
throws IOException
IOExceptionpublic ChunkHeader readChunkHeader(byte chunkType) throws IOException
IOException - io errorpublic Chunk readMemChunk(ChunkMetadata metaData) throws IOException
metaData - -given chunk meta dataIOExceptionpublic Chunk readMemChunk(CachedChunkLoaderImpl.ChunkCacheKey chunkCacheKey) throws IOException
chunkCacheKey - given key of chunk LRUCacheIOExceptionpublic PageHeader readPageHeader(TSDataType type, boolean hasStatistic) throws IOException
type - given tsfile data typeIOExceptionpublic long position()
throws IOException
IOExceptionpublic void position(long offset)
throws IOException
IOExceptionpublic void skipPageData(PageHeader header) throws IOException
IOExceptionpublic ByteBuffer readCompressedPage(PageHeader header) throws IOException
IOExceptionpublic ByteBuffer readPage(PageHeader header, CompressionType type) throws IOException
IOExceptionpublic byte readMarker()
throws IOException
IOExceptionpublic void close()
throws IOException
close in interface AutoCloseableIOExceptionpublic String getFileName()
public long fileSize()
throws IOException
IOExceptionprotected ByteBuffer readData(long position, int totalSize) throws IOException
position - the start position of data in the tsFileInput, or the current position if
position = -1totalSize - the size of data that want to readIOExceptionprotected ByteBuffer readData(long start, long end) throws IOException
start - the start position of data in the tsFileInput, or the current position if position
= -1end - the end position of data that want to readIOExceptionpublic int readRaw(long position,
int length,
ByteBuffer target)
throws IOException
IOExceptionpublic long selfCheck(Map<Path,IMeasurementSchema> newSchema, List<ChunkGroupMetadata> chunkGroupMetadataList, boolean fastFinish) throws IOException
newSchema - the schema on each time series in the filechunkGroupMetadataList - ChunkGroupMetadata ListfastFinish - if true and the file is complete, then newSchema and chunkGroupMetadataList
parameter will be not modified.IOExceptionpublic long selfCheckWithInfo(String filename, boolean fastFinish, Map<Long,Pair<Path,TimeseriesMetadata>> timeseriesMetadataMap) throws IOException, TsFileStatisticsMistakesException
filename - the path of filefastFinish - if true, the method will only check the format of head (Magic String TsFile,
Version Number) and tail (Magic String TsFile) of TsFile.IOExceptionTsFileStatisticsMistakesExceptionpublic long checkChunkAndPagesStatistics(IChunkMetadata chunkMetadata) throws IOException
IOExceptionpublic List<ChunkMetadata> getChunkMetadataList(Path path, boolean ignoreNotExists) throws IOException
path - timeseries pathIOExceptionpublic List<IChunkMetadata> getIChunkMetadataList(Path path) throws IOException
IOExceptionpublic List<ChunkMetadata> getChunkMetadataList(Path path) throws IOException
IOExceptionpublic List<AlignedChunkMetadata> getAlignedChunkMetadata(String device) throws IOException
device - device nameIOExceptionpublic List<ChunkMetadata> readChunkMetaDataList(TimeseriesMetadata timeseriesMetaData) throws IOException
IOExceptionpublic List<IChunkMetadata> readIChunkMetaDataList(ITimeSeriesMetadata timeseriesMetaData)
public Map<String,TSDataType> getAllMeasurements() throws IOException
IOExceptionpublic Map<String,List<String>> getDeviceMeasurementsMap() throws IOException
IOExceptionpublic List<String> getDeviceNameInRange(long start, long end) throws IOException
start - start of the partitionend - end of the partitionIOExceptionpublic MetadataIndexNode getMetadataIndexNode(long startOffset, long endOffset) throws IOException
startOffset - start read offsetendOffset - end read offsetIOExceptionpublic long getMinPlanIndex()
public long getMaxPlanIndex()
public Iterator<Map<String,List<ChunkMetadata>>> getMeasurementChunkMetadataListMapIterator(String device) throws IOException
IOExceptionCopyright © 2022 The Apache Software Foundation. All rights reserved.