You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ma...@apache.org on 2022/10/14 09:27:37 UTC
[iotdb] branch IOTDB-4650 updated: refactor and add javadoc
This is an automated email from the ASF dual-hosted git repository.
marklau99 pushed a commit to branch IOTDB-4650
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/IOTDB-4650 by this push:
new 73cedd0d80 refactor and add javadoc
73cedd0d80 is described below
commit 73cedd0d809a92b464e7b1b2f9c085ac2607ca61
Author: Liu Xuxin <li...@outlook.com>
AuthorDate: Fri Oct 14 17:27:24 2022 +0800
refactor and add javadoc
---
.../java/org/apache/iotdb/RewriteTsFileTool.java | 67 +++++++++++++++-------
1 file changed, 45 insertions(+), 22 deletions(-)
diff --git a/rewrite-tsfile-tool/src/main/java/org/apache/iotdb/RewriteTsFileTool.java b/rewrite-tsfile-tool/src/main/java/org/apache/iotdb/RewriteTsFileTool.java
index f45b3457c3..fd699cd1d9 100644
--- a/rewrite-tsfile-tool/src/main/java/org/apache/iotdb/RewriteTsFileTool.java
+++ b/rewrite-tsfile-tool/src/main/java/org/apache/iotdb/RewriteTsFileTool.java
@@ -470,6 +470,17 @@ public class RewriteTsFileTool {
}
}
+ /**
+ * Read the chunk metadata first, then read the chunk according to chunk metadata
+ *
+ * @param files
+ * @param session
+ * @throws IOException
+ * @throws IllegalPathException
+ * @throws IoTDBConnectionException
+ * @throws StatementExecutionException
+ * @throws NoMeasurementException
+ */
public static void reverseWriteTsFile(List<File> files, Session session)
throws IOException, IllegalPathException, IoTDBConnectionException,
StatementExecutionException, NoMeasurementException {
@@ -498,10 +509,10 @@ public class RewriteTsFileTool {
}
}
+ /** Read data from tsfile and write it to IoTDB for a single not aligned series. */
protected static void writeSingleSeries(
String device, MultiTsFileDeviceIterator.MeasurementIterator seriesIterator, Session session)
- throws IllegalPathException, IOException, IoTDBConnectionException,
- StatementExecutionException {
+ throws IllegalPathException {
PartialPath p = new PartialPath(device, seriesIterator.nextSeries());
LinkedList<Pair<TsFileSequenceReader, List<ChunkMetadata>>> readerAndChunkMetadataList =
seriesIterator.getMetadataListForCurrentSeries();
@@ -521,6 +532,7 @@ public class RewriteTsFileTool {
}
}
+ /** Read and write a single chunk for not aligned series. */
protected static void writeSingleChunk(
String device,
PartialPath p,
@@ -556,6 +568,7 @@ public class RewriteTsFileTool {
}
}
+ /** Collect the schema list for an aligned device. */
private static List<IMeasurementSchema> collectSchemaFromAlignedChunkMetadataList(
LinkedList<Pair<TsFileSequenceReader, List<AlignedChunkMetadata>>> readerAndChunkMetadataList)
throws IOException {
@@ -592,6 +605,7 @@ public class RewriteTsFileTool {
return schemaList;
}
+ /** Read and write an aligned series. */
protected static void writeAlignedSeries(
String device, MultiTsFileDeviceIterator deviceIterator, Session session)
throws IOException, IoTDBConnectionException, StatementExecutionException {
@@ -608,28 +622,37 @@ public class RewriteTsFileTool {
List<AlignedChunkMetadata> alignedChunkMetadataList = readerListPair.right;
TsFileAlignedSeriesReaderIterator readerIterator =
new TsFileAlignedSeriesReaderIterator(reader, alignedChunkMetadataList, iSchemaList);
- while (readerIterator.hasNext()) {
- Tablet tablet = new Tablet(device, schemaList, 1024);
- Pair<AlignedChunkReader, Long> chunkReaderAndChunkSize = readerIterator.nextReader();
- AlignedChunkReader alignedChunkReader = chunkReaderAndChunkSize.left;
- while (alignedChunkReader.hasNextSatisfiedPage()) {
- IBatchDataIterator batchDataIterator =
- alignedChunkReader.nextPageData().getBatchDataIterator();
- while (batchDataIterator.hasNext()) {
- TsPrimitiveType[] pointsData = (TsPrimitiveType[]) batchDataIterator.currentValue();
- tablet.timestamps[tablet.rowSize] = batchDataIterator.currentTime();
- tablet.values[tablet.rowSize++] = batchDataIterator.currentValue();
- batchDataIterator.next();
- if (tablet.rowSize >= 1024) {
- session.insertAlignedTablet(tablet);
- tablet.reset();
- }
+ writeAlignedChunk(readerIterator, device, schemaList, session);
+ }
+ }
+
+ private static void writeAlignedChunk(
+ TsFileAlignedSeriesReaderIterator readerIterator,
+ String device,
+ List<MeasurementSchema> schemaList,
+ Session session)
+ throws IOException, IoTDBConnectionException, StatementExecutionException {
+ while (readerIterator.hasNext()) {
+ Tablet tablet = new Tablet(device, schemaList, 1024);
+ Pair<AlignedChunkReader, Long> chunkReaderAndChunkSize = readerIterator.nextReader();
+ AlignedChunkReader alignedChunkReader = chunkReaderAndChunkSize.left;
+ while (alignedChunkReader.hasNextSatisfiedPage()) {
+ IBatchDataIterator batchDataIterator =
+ alignedChunkReader.nextPageData().getBatchDataIterator();
+ while (batchDataIterator.hasNext()) {
+ TsPrimitiveType[] pointsData = (TsPrimitiveType[]) batchDataIterator.currentValue();
+ tablet.timestamps[tablet.rowSize] = batchDataIterator.currentTime();
+ tablet.values[tablet.rowSize++] = batchDataIterator.currentValue();
+ batchDataIterator.next();
+ if (tablet.rowSize >= 1024) {
+ session.insertAlignedTablet(tablet);
+ tablet.reset();
}
}
- if (tablet.rowSize > 0) {
- session.insertAlignedTablet(tablet);
- tablet.reset();
- }
+ }
+ if (tablet.rowSize > 0) {
+ session.insertAlignedTablet(tablet);
+ tablet.reset();
}
}
}