You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ej...@apache.org on 2020/12/10 03:30:17 UTC
[iotdb] 01/01: add print tsfile specfic path
This is an automated email from the ASF dual-hosted git repository.
ejttianyu pushed a commit to branch dev_tool_show_tsfile_path
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 082930d02adc8dbee4de8f0853ddc9275b48ab85
Author: EJTTianyu <16...@qq.com>
AuthorDate: Thu Dec 10 11:23:14 2020 +0800
add print tsfile specfic path
---
.../print-tsfile-specfic-measurement.bat | 62 ++++++++++++++++++++++
.../print-tsfile-specific-measurement.sh | 48 +++++++++++++++++
.../iotdb/db/tools/TsFileSinglePathRead.java | 42 +++++++++++++++
.../iotdb/tsfile/read/TsFileSequenceReader.java | 21 ++++++++
4 files changed, 173 insertions(+)
diff --git a/server/src/assembly/resources/tools/tsfileToolSet/print-tsfile-specfic-measurement.bat b/server/src/assembly/resources/tools/tsfileToolSet/print-tsfile-specfic-measurement.bat
new file mode 100644
index 0000000..705b6dc
--- /dev/null
+++ b/server/src/assembly/resources/tools/tsfileToolSet/print-tsfile-specfic-measurement.bat
@@ -0,0 +1,62 @@
+@REM
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM
+
+
+@echo off
+echo ````````````````````````
+echo Starting Printing the TsFile Specific Measurement
+echo ````````````````````````
+
+if "%OS%" == "Windows_NT" setlocal
+
+pushd %~dp0..\..
+if NOT DEFINED IOTDB_HOME set IOTDB_HOME=%CD%
+popd
+
+if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.db.tools.TsFileSinglePathRead
+if NOT DEFINED JAVA_HOME goto :err
+
+@REM -----------------------------------------------------------------------------
+@REM ***** CLASSPATH library setting *****
+@REM Ensure that any user defined CLASSPATH variables are not used on startup
+set CLASSPATH="%IOTDB_HOME%\lib\*"
+
+goto okClasspath
+
+:append
+set CLASSPATH=%CLASSPATH%;%1
+goto :eof
+
+@REM -----------------------------------------------------------------------------
+:okClasspath
+
+"%JAVA_HOME%\bin\java" -cp "%CLASSPATH%" %MAIN_CLASS% %*
+
+goto finally
+
+
+:err
+echo JAVA_HOME environment variable must be set!
+pause
+
+
+@REM -----------------------------------------------------------------------------
+:finally
+
+ENDLOCAL
\ No newline at end of file
diff --git a/server/src/assembly/resources/tools/tsfileToolSet/print-tsfile-specific-measurement.sh b/server/src/assembly/resources/tools/tsfileToolSet/print-tsfile-specific-measurement.sh
new file mode 100755
index 0000000..cdcb99a
--- /dev/null
+++ b/server/src/assembly/resources/tools/tsfileToolSet/print-tsfile-specific-measurement.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# 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.
+#
+
+echo ---------------------
+echo Starting Printing the TsFile Specific Measurement
+echo ---------------------
+
+if [ -z "${IOTDB_HOME}" ]; then
+ export IOTDB_HOME="$(cd "`dirname "$0"`"/../..; pwd)"
+fi
+
+if [ -n "$JAVA_HOME" ]; then
+ for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
+ if [ -x "$java" ]; then
+ JAVA="$java"
+ break
+ fi
+ done
+else
+ JAVA=java
+fi
+
+CLASSPATH=""
+for f in ${IOTDB_HOME}/lib/*.jar; do
+ CLASSPATH=${CLASSPATH}":"$f
+done
+
+MAIN_CLASS=org.apache.iotdb.db.tools.TsFileSinglePathRead
+
+"$JAVA" -cp "$CLASSPATH" "$MAIN_CLASS" "$@"
+exit $?
\ No newline at end of file
diff --git a/server/src/main/java/org/apache/iotdb/db/tools/TsFileSinglePathRead.java b/server/src/main/java/org/apache/iotdb/db/tools/TsFileSinglePathRead.java
new file mode 100644
index 0000000..5fc4d9f
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/tools/TsFileSinglePathRead.java
@@ -0,0 +1,42 @@
+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];
+ }
+ 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) {
+ System.out.println("|--[Chunk]");
+ ChunkReader chunkReader = new ChunkReader(reader.readMemChunk(metadata), null);
+ ChunkDataIterator chunkDataIterator = new ChunkDataIterator(chunkReader);
+ while (chunkDataIterator.hasNextTimeValuePair()) {
+ TimeValuePair pair = chunkDataIterator.nextTimeValuePair();
+ System.out.println(
+ "\t\t\ttime, value: " + pair.getTimestamp() + ", " + pair.getValue());
+ }
+ }
+ }
+ }
+}
+
+
+
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
index f6d8f7c..960013b 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/TsFileSequenceReader.java
@@ -1024,6 +1024,27 @@ public class TsFileSequenceReader implements AutoCloseable {
}
/**
+ * 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)
+ throws IOException {
+ if (!sortByOffset) {
+ return getChunkMetadataList(path);
+ }
+ TimeseriesMetadata timeseriesMetaData = readTimeseriesMetadata(path);
+ if (timeseriesMetaData == null) {
+ return Collections.emptyList();
+ }
+ List<ChunkMetadata> chunkMetadataList = readChunkMetaDataList(timeseriesMetaData);
+ chunkMetadataList.sort(Comparator.comparingLong(ChunkMetadata::getOffsetOfChunkHeader));
+ return chunkMetadataList;
+ }
+
+ /**
* get ChunkMetaDatas in given TimeseriesMetaData
*
* @return List of ChunkMetaData