samperson1997 commented on a change in pull request #1134: URL: https://github.com/apache/incubator-iotdb/pull/1134#discussion_r418958967 ########## File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java ########## @@ -314,28 +311,76 @@ public TsFileMetadata readFileMetadata() throws IOException { public TimeseriesMetadata readTimeseriesMetadata(Path path) throws IOException { readFileMetadata(); MetadataIndexNode deviceMetadataIndexNode = tsFileMetaData.getMetadataIndex(); - Pair metadataIndexPair = getMetaDataAndEndOffset( + Pair metadataIndexPair = getMetadataAndEndOffset( deviceMetadataIndexNode, path.getDevice(), MetadataIndexNodeType.INTERNAL_DEVICE); ByteBuffer buffer = readData(metadataIndexPair.left.getOffset(), metadataIndexPair.right); while (!metadataIndexPair.left.getChildNodeType() .equals(MetadataIndexNodeType.LEAF_MEASUREMENT)) { MetadataIndexNode metadataIndexNode = MetadataIndexNode.deserializeFrom(buffer); - metadataIndexPair = getMetaDataAndEndOffset(metadataIndexNode, + metadataIndexPair = getMetadataAndEndOffset(metadataIndexNode, path.getMeasurement(), MetadataIndexNodeType.INTERNAL_MEASUREMENT); } List timeseriesMetadataList = new ArrayList<>(); buffer = readData(metadataIndexPair.left.getOffset(), metadataIndexPair.right); while (buffer.hasRemaining()) { timeseriesMetadataList.add(TimeseriesMetadata.deserializeFrom(buffer)); } - String[] measurementNameList = timeseriesMetadataList.stream() - .map(TimeseriesMetadata::getMeasurementId).collect(Collectors.toList()) - .toArray(new String[timeseriesMetadataList.size()]); - // return null if path does not exist in the TsFile - int searchResult; - return (searchResult = Arrays.binarySearch(measurementNameList, path.getMeasurement())) >= 0 - ? timeseriesMetadataList.get(searchResult) : null; + int searchResult = binarySearchInTimeseriesMetadataList(timeseriesMetadataList, + path.getMeasurement()); + return searchResult >= 0 ? timeseriesMetadataList.get(searchResult) : null; + } + + public List readTimeseriesMetadata(String device, Set measurements) + throws IOException { + readFileMetadata(); + MetadataIndexNode deviceMetadataIndexNode = tsFileMetaData.getMetadataIndex(); + Pair metadataIndexPair = getMetadataAndEndOffset( + deviceMetadataIndexNode, device, MetadataIndexNodeType.INTERNAL_DEVICE); Review comment: I could explain why I use INTERAL_DEVICE / INTERNAL_MEASUREMENT in method `getMetadataAndEndOffset`: The statement which ends the recursion is: `if (!childIndexEntry.left.getChildNodeType().equals(type))`. For example, when searching for a device node, we look for LEAF_DEVICE, so we return when it is not INTERNAL_DEVICE. Likewise, when searching for a measurement node, we look for LEAF_MEASUREMENT, so we return when it is not INTERNAL_MEASUREMENT. Why not judging by `== LEAF_DEVICE` or `== LEAF_MEASUREMENT`? Because this works for the situation when we are searching for device, but the index tree does **not** have the **device level** and only has the **measurement level**. Or we will never meet the LEAF_DEVICE. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org