Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,17 @@ public static MetadataIndexNode deserializeFrom(
return new MetadataIndexNode(children, offset, nodeType);
}

/**
* Searches the floor child entry of the given key.
*
* <p>In floor mode a key that sorts before the first child returns child 0, so a caller that must
* not read a group which cannot hold the key should compare the key with the first child first.
*/
public Pair<IMetadataIndexEntry, Long> getChildIndexEntry(Comparable key, boolean exactSearch) {
int index = binarySearchInChildren(key, exactSearch);
return getChildIndexEntry(binarySearchInChildren(key, exactSearch));
}

private Pair<IMetadataIndexEntry, Long> getChildIndexEntry(int index) {
if (index == -1) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

import static org.apache.tsfile.utils.Preconditions.checkArgument;
import static org.apache.tsfile.utils.RamUsageEstimator.sizeOfCharArray;
Expand Down Expand Up @@ -167,6 +168,23 @@ public static TimeseriesMetadata deserializeFrom(
boolean needChunkMetadataForDataTypeWithValuesInStatistics,
boolean needChunkMetadataForDataTypeWithoutValuesInStatistics)
throws IOException {
return deserializeFrom(
tsFileInput,
id -> true,
needChunkMetadataForDataTypeWithValuesInStatistics,
needChunkMetadataForDataTypeWithoutValuesInStatistics);
}

/**
* Deserializes one TimeseriesMetadata from a file input and decodes its chunk metadata only when
* {@code decodeChunkMetadata} accepts the measurement.
*/
public static TimeseriesMetadata deserializeFrom(
Comment thread
ColinLeeo marked this conversation as resolved.
Resolved
TsFileInput tsFileInput,
Predicate<String> decodeChunkMetadata,
boolean needChunkMetadataForDataTypeWithValuesInStatistics,
boolean needChunkMetadataForDataTypeWithoutValuesInStatistics)
throws IOException {
InputStream inputStream = tsFileInput.wrapAsInputStream();
TimeseriesMetadata timeseriesMetaData = new TimeseriesMetadata();
timeseriesMetaData.setTimeSeriesMetadataType(ReadWriteIOUtils.readByte(inputStream));
Expand All @@ -177,10 +195,11 @@ public static TimeseriesMetadata deserializeFrom(
timeseriesMetaData.setStatistics(
Statistics.deserialize(inputStream, timeseriesMetaData.dataType));
long startOffset = tsFileInput.position();
if ((!timeseriesMetaData.getTsDataType().hasNoValueInStatistics()
&& needChunkMetadataForDataTypeWithValuesInStatistics)
|| (timeseriesMetaData.getTsDataType().hasNoValueInStatistics()
&& needChunkMetadataForDataTypeWithoutValuesInStatistics)) {
if (decodeChunkMetadata.test(timeseriesMetaData.getMeasurementId())
Comment thread
ColinLeeo marked this conversation as resolved.
Resolved
&& ((!timeseriesMetaData.getTsDataType().hasNoValueInStatistics()
&& needChunkMetadataForDataTypeWithValuesInStatistics)
|| (timeseriesMetaData.getTsDataType().hasNoValueInStatistics()
&& needChunkMetadataForDataTypeWithoutValuesInStatistics))) {
timeseriesMetaData.chunkMetadataList = new ArrayList<>();
while (tsFileInput.position() < startOffset + chunkMetaDataListDataSize) {
timeseriesMetaData.chunkMetadataList.add(
Expand Down Expand Up @@ -208,6 +227,23 @@ public static TimeseriesMetadata deserializeFrom(
Set<String> excludedMeasurements,
boolean needChunkMetadataForDataTypeWithValuesInStatistics,
boolean needChunkMetadataForDataTypeWithoutValuesInStatistics) {
return deserializeFrom(
buffer,
measurementId -> !excludedMeasurements.contains(measurementId),
needChunkMetadataForDataTypeWithValuesInStatistics,
needChunkMetadataForDataTypeWithoutValuesInStatistics);
}

/**
* Deserializes one TimeseriesMetadata and decodes its chunk metadata only when {@code
* decodeChunkMetadata} accepts the measurement. Statistics are always read; the chunk metadata
* region is skipped when it is not decoded.
*/
public static TimeseriesMetadata deserializeFrom(
ByteBuffer buffer,
Predicate<String> decodeChunkMetadata,
boolean needChunkMetadataForDataTypeWithValuesInStatistics,
boolean needChunkMetadataForDataTypeWithoutValuesInStatistics) {
byte timeseriesType = ReadWriteIOUtils.readByte(buffer);
String measurementID = ReadWriteIOUtils.readVarIntString(buffer);
TSDataType tsDataType = ReadWriteIOUtils.readDataType(buffer);
Expand All @@ -221,12 +257,11 @@ public static TimeseriesMetadata deserializeFrom(
timeseriesMetaData.setDataSizeOfChunkMetaDataList(chunkMetaDataListDataSize);
timeseriesMetaData.setStatistics(statistics);

if (!excludedMeasurements.contains(measurementID)
if (decodeChunkMetadata.test(measurementID)
&& ((!tsDataType.hasNoValueInStatistics()
&& needChunkMetadataForDataTypeWithValuesInStatistics)
|| (tsDataType.hasNoValueInStatistics()
&& needChunkMetadataForDataTypeWithoutValuesInStatistics))) {
// measurement is not in the excluded set and need chunk metadata
ByteBuffer byteBuffer = buffer.slice();
byteBuffer.limit(chunkMetaDataListDataSize);
timeseriesMetaData.chunkMetadataList = new ArrayList<>();
Expand Down
Loading
Loading