diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java b/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java index 9491afaa2..376fc9b9f 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java @@ -559,6 +559,55 @@ public ITimeSeriesMetadata readITimeseriesMetadata(Path path, boolean ignoreNotE } } + /** + * Read the TimeseriesMetadata of the given measurement and its successors from the index node + * into the list. + * + * @param timeseriesMetadataList result holder + * @param node index node to be read from + * @param measurement the desired measurement + * @return true if the measurement exists + * @throws IOException when read fails + */ + public boolean readITimeseriesMetadata( + List timeseriesMetadataList, MetadataIndexNode node, String measurement) + throws IOException { + Pair measurementMetadataIndexPair = + getMetadataAndEndOffsetOfMeasurementNode(node, measurement, true, null); + + if (measurementMetadataIndexPair == null) { + return false; + } + long startOffset = measurementMetadataIndexPair.getLeft().getOffset(); + long endOffset = measurementMetadataIndexPair.getRight(); + TimeseriesMetadata timeseriesMetadata; + if (endOffset - startOffset >= Integer.MAX_VALUE) { + synchronized (this) { + this.position(startOffset); + try { + timeseriesMetadata = TimeseriesMetadata.deserializeFrom(tsFileInput, true); + } catch (Exception e) { + logger.error( + "Something error happened while deserializing TimeseriesMetadata of file {}", file); + throw e; + } + } + } else { + try { + ByteBuffer buffer = + readData( + measurementMetadataIndexPair.left.getOffset(), measurementMetadataIndexPair.right); + timeseriesMetadata = TimeseriesMetadata.deserializeFrom(buffer, true); + } catch (Exception e) { + logger.error( + "Something error happened while deserializing TimeseriesMetadata of file {}", file); + throw e; + } + } + timeseriesMetadataList.add(timeseriesMetadata); + return true; + } + /** * Find the leaf node that contains path, return all the sensors in that leaf node which are also * in allSensors set