Skip to content

Commit

Permalink
Modify isDeleted method in page reader to public access (#241)
Browse files Browse the repository at this point in the history
* modify isDeleted method access

* modify getAlignedChunkMetadataByMetadataIndexNode

* spotless

* fix compile
  • Loading branch information
shuwenwei authored Sep 20, 2024
1 parent fae7467 commit e90a4c0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.tsfile.file.header.ChunkGroupHeader;
import org.apache.tsfile.file.header.ChunkHeader;
import org.apache.tsfile.file.header.PageHeader;
import org.apache.tsfile.file.metadata.AbstractAlignedTimeSeriesMetadata;
import org.apache.tsfile.file.metadata.AlignedChunkMetadata;
import org.apache.tsfile.file.metadata.AlignedTimeSeriesMetadata;
import org.apache.tsfile.file.metadata.ChunkGroupMetadata;
Expand All @@ -48,6 +49,7 @@
import org.apache.tsfile.file.metadata.ITimeSeriesMetadata;
import org.apache.tsfile.file.metadata.MeasurementMetadataIndexEntry;
import org.apache.tsfile.file.metadata.MetadataIndexNode;
import org.apache.tsfile.file.metadata.TableDeviceMetadata;
import org.apache.tsfile.file.metadata.TimeseriesMetadata;
import org.apache.tsfile.file.metadata.TsFileMetadata;
import org.apache.tsfile.file.metadata.enums.CompressionType;
Expand Down Expand Up @@ -2356,7 +2358,8 @@ public List<ChunkMetadata> getChunkMetadataList(Path path) throws IOException {
*
* @param device device name
*/
public List<AlignedChunkMetadata> getAlignedChunkMetadata(IDeviceID device) throws IOException {
public List<AlignedChunkMetadata> getAlignedChunkMetadata(
IDeviceID device, boolean ignoreAllNullRows) throws IOException {
readFileMetadata();
MetadataIndexNode deviceMetadataIndexNode =
tsFileMetaData.getTableMetadataIndexNode(device.getTableName());
Expand All @@ -2376,7 +2379,7 @@ public List<AlignedChunkMetadata> getAlignedChunkMetadata(IDeviceID device) thro
logger.error(METADATA_INDEX_NODE_DESERIALIZE_ERROR, file);
throw e;
}
return getAlignedChunkMetadataByMetadataIndexNode(device, metadataIndexNode);
return getAlignedChunkMetadataByMetadataIndexNode(device, metadataIndexNode, ignoreAllNullRows);
}

/**
Expand All @@ -2385,9 +2388,11 @@ public List<AlignedChunkMetadata> getAlignedChunkMetadata(IDeviceID device) thro
*
* @param device device name
* @param metadataIndexNode the first measurement metadata index node of the device
* @param ignoreAllNullRows ignore all null rows
*/
public List<AlignedChunkMetadata> getAlignedChunkMetadataByMetadataIndexNode(
IDeviceID device, MetadataIndexNode metadataIndexNode) throws IOException {
IDeviceID device, MetadataIndexNode metadataIndexNode, boolean ignoreAllNullRows)
throws IOException {
TimeseriesMetadata firstTimeseriesMetadata = getTimeColumnMetadata(metadataIndexNode);
if (firstTimeseriesMetadata == null) {
throw new IOException("Timeseries of device {" + device + "} are not aligned");
Expand Down Expand Up @@ -2438,8 +2443,14 @@ public List<AlignedChunkMetadata> getAlignedChunkMetadataByMetadataIndexNode(
valueTimeseriesMetadataList.add(timeseriesMetadataList.get(i));
}

AlignedTimeSeriesMetadata alignedTimeSeriesMetadata =
new AlignedTimeSeriesMetadata(timeseriesMetadata, valueTimeseriesMetadataList);
AbstractAlignedTimeSeriesMetadata alignedTimeSeriesMetadata;
if (ignoreAllNullRows) {
alignedTimeSeriesMetadata =
new AlignedTimeSeriesMetadata(timeseriesMetadata, valueTimeseriesMetadataList);
} else {
alignedTimeSeriesMetadata =
new TableDeviceMetadata(timeseriesMetadata, valueTimeseriesMetadataList);
}
List<AlignedChunkMetadata> chunkMetadataList = new ArrayList<>();
for (IChunkMetadata chunkMetadata : readIChunkMetaDataList(alignedTimeSeriesMetadata)) {
chunkMetadataList.add((AlignedChunkMetadata) chunkMetadata);
Expand All @@ -2461,9 +2472,9 @@ public List<ChunkMetadata> readChunkMetaDataList(TimeseriesMetadata timeseriesMe

// This method is only used for TsFile
public List<IChunkMetadata> readIChunkMetaDataList(ITimeSeriesMetadata timeseriesMetaData) {
if (timeseriesMetaData instanceof AlignedTimeSeriesMetadata) {
if (timeseriesMetaData instanceof AbstractAlignedTimeSeriesMetadata) {
return new ArrayList<>(
((AlignedTimeSeriesMetadata) timeseriesMetaData).getChunkMetadataList());
((AbstractAlignedTimeSeriesMetadata) timeseriesMetaData).getChunkMetadataList());
} else {
return new ArrayList<>(((TimeseriesMetadata) timeseriesMetaData).getChunkMetadataList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean isModified() {
return pageHeader.isModified();
}

protected boolean isDeleted(long timestamp) {
public boolean isDeleted(long timestamp) {
while (deleteIntervalList != null && deleteCursor < deleteIntervalList.size()) {
if (deleteIntervalList.get(deleteCursor).contains(timestamp)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public boolean isModified() {
return pageHeader.isModified();
}

protected boolean isDeleted(long timestamp) {
public boolean isDeleted(long timestamp) {
while (deleteIntervalList != null && deleteCursor < deleteIntervalList.size()) {
if (deleteIntervalList.get(deleteCursor).contains(timestamp)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,23 +524,23 @@ public void testGetAlignedChunkMetadata() throws IOException {
// query for non-exist device
IDeviceID d3 = IDeviceID.Factory.DEFAULT_FACTORY.create("d3");
try {
reader.getAlignedChunkMetadata(d3);
reader.getAlignedChunkMetadata(d3, true);
} catch (IOException e) {
Assert.assertEquals("Device {" + d3 + "} is not in tsFileMetaData", e.getMessage());
}

// query for non-aligned device
IDeviceID d2 = IDeviceID.Factory.DEFAULT_FACTORY.create("d2");
try {
reader.getAlignedChunkMetadata(d2);
reader.getAlignedChunkMetadata(d2, true);
} catch (IOException e) {
Assert.assertEquals("Timeseries of device {" + d2 + "} are not aligned", e.getMessage());
}

String[] expected = new String[] {"s1", "s2", "s3", "s4"};

List<AlignedChunkMetadata> chunkMetadataList =
reader.getAlignedChunkMetadata(IDeviceID.Factory.DEFAULT_FACTORY.create("d1"));
reader.getAlignedChunkMetadata(IDeviceID.Factory.DEFAULT_FACTORY.create("d1"), true);
AlignedChunkMetadata alignedChunkMetadata = chunkMetadataList.get(0);
Assert.assertEquals("", alignedChunkMetadata.getTimeChunkMetadata().getMeasurementUid());
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public void testChunkReaderWithoutStatistics() throws IOException {
for (int i = 0; i < deviceNum; i++) {
final List<AlignedChunkMetadata> chunkMetadataList =
tsFileSequenceReader.getAlignedChunkMetadata(
Factory.DEFAULT_FACTORY.create(testStorageGroup + PATH_SEPARATOR + "d1000" + i));
Factory.DEFAULT_FACTORY.create(testStorageGroup + PATH_SEPARATOR + "d1000" + i),
true);
for (final AlignedChunkMetadata chunkMetadata : chunkMetadataList) {
Chunk timeChunk =
tsFileSequenceReader.readMemChunk(
Expand Down

0 comments on commit e90a4c0

Please sign in to comment.