JackieTien97 commented on a change in pull request #2237:
URL: https://github.com/apache/iotdb/pull/2237#discussion_r542129129
##########
File path:
tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
##########
@@ -1023,6 +1023,27 @@ public int getTotalChunkNum() {
return chunkMetadataList;
}
+ /**
+ * get ChunkMetaDatas of given path sorting by offset
+ *
+ * @param path timeseries path
+ * @param sortByOffset whether to use offset to sort the ChunkMetadatas
+ * @return List of ChunkMetaData
+ */
+ public List<ChunkMetadata> getChunkMetadataList(Path path, boolean
sortByOffset)
Review comment:
I've no idea whether the `sortByOffset` parameter is necessary, because
as far as I known, the ChunkMetadataList has been sorted already in the disk.
##########
File path:
server/src/test/java/org/apache/iotdb/db/tools/TsFileSinglePathReadTest.java
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.tools;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.List;
+import org.apache.iotdb.db.query.reader.chunk.ChunkDataIterator;
+import org.apache.iotdb.tsfile.exception.write.NoMeasurementException;
+import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
+import org.apache.iotdb.tsfile.file.metadata.ChunkMetadata;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.reader.chunk.ChunkReader;
+import org.apache.iotdb.tsfile.write.TsFileWriter;
+import org.apache.iotdb.tsfile.write.record.TSRecord;
+import org.apache.iotdb.tsfile.write.record.datapoint.FloatDataPoint;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TsFileSinglePathReadTest {
+
+ String fileName = "target/tsfileWriter-" + System.nanoTime();
+ TsFileWriter writer = null;
+ String path = "d1.s1";
+
+ @Before
+ public void setUp() {
+ try {
+ writer = new TsFileWriter(new File(fileName));
+ writeRecordAndClose();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ Files.deleteIfExists(new File(fileName).toPath());
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ private void writeRecordAndClose() throws IOException, WriteProcessException
{
+ addMeasurement();
+ writeTSRecord();
+ writer.close();
+ }
+
+ private void addMeasurement() {
+ try {
+ //String measurementId, TSDataType type, TSEncoding encoding,
+ // CompressionType compressionType
+ writer.registerTimeseries(new Path("d1", "s1"),
+ new MeasurementSchema("s1", TSDataType.FLOAT, TSEncoding.RLE,
CompressionType.SNAPPY));
+ } catch (WriteProcessException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ private void writeTSRecord() throws IOException, WriteProcessException {
+ TSRecord record = new TSRecord(10000, "d1");
+ record.addTuple(new FloatDataPoint("s1", 5.0f));
+ writer.write(record);
+
+ record = new TSRecord(10001, "d1");
+ record.addTuple(new FloatDataPoint("s1", 5.0f));
+ try {
+ writer.write(record);
+ } catch (WriteProcessException e) {
+ assertTrue(e instanceof NoMeasurementException);
+ }
+ }
+
+ @Test
+ public void SinglePathReadTest() throws IOException {
+ int numCnt = 0;
+ try (TsFileSequenceReader reader = new TsFileSequenceReader(fileName)) {
+ // get the chunkMetaList of the specific path
+ List<ChunkMetadata> chunkMetadataList = reader
+ .getChunkMetadataList(new Path(path, true), true);
+ for (ChunkMetadata metadata : chunkMetadataList) {
+ ChunkReader chunkReader = new
ChunkReader(reader.readMemChunk(metadata), null);
+ ChunkDataIterator chunkDataIterator = new
ChunkDataIterator(chunkReader);
+ while (chunkDataIterator.hasNextTimeValuePair()) {
+ chunkDataIterator.nextTimeValuePair();
+ numCnt ++;
+ }
+ }
+ }
+ assertEquals(numCnt, 2);
Review comment:
I think you should not write the same code again, you can extract the
code in TsFileSinglePathRead as a public method, and in this UT, you can just
test that method. Or if the class has been modified, this test may be forgotten
to be changed.
##########
File path:
server/src/main/java/org/apache/iotdb/db/tools/TsFileSinglePathRead.java
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.tools;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.iotdb.db.query.reader.chunk.ChunkDataIterator;
+import org.apache.iotdb.tsfile.file.metadata.ChunkMetadata;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.reader.chunk.ChunkReader;
+
+public class TsFileSinglePathRead {
+
+ public static void main(String[] args) throws IOException {
+ String filename = "test.tsfile";
+ String path = "root.vehicle.d0.s0";
+ if (args.length >= 2) {
+ filename = args[0];
+ path = args[1];
+ } else if (args.length >= 1){
+ filename = args[0];
+ }
Review comment:
Maybe if the args.length is less than 2, we should throw an exception to
tell users to give the right paremeters.
----------------------------------------------------------------
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:
[email protected]