You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by zy...@apache.org on 2023/06/29 14:07:34 UTC
[iotdb] branch master updated: Add UT and fix code smell for tools/schema and utils/schema (#10386)
This is an automated email from the ASF dual-hosted git repository.
zyk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 8f0bd73f9cb Add UT and fix code smell for tools/schema and utils/schema (#10386)
8f0bd73f9cb is described below
commit 8f0bd73f9cb5ba4d4d25090bbc7fea3255573f8c
Author: Chen YZ <43...@users.noreply.github.com>
AuthorDate: Thu Jun 29 22:07:28 2023 +0800
Add UT and fix code smell for tools/schema and utils/schema (#10386)
---
.../InternalBatchActivateTemplateStatement.java | 2 +-
.../InternalCreateMultiTimeSeriesStatement.java | 2 +-
.../InternalCreateTimeSeriesStatement.java | 15 +++++++-------
.../db/tools/schema/PBTreeFileSketchTool.java | 5 ++---
.../org/apache/iotdb/db/utils/SchemaUtils.java | 17 ++++------------
.../org/apache/iotdb/db/tools/MLogParserTest.java | 6 ++++--
.../iotdb/db/tools/PBTreeFileSketchTest.java | 3 ++-
.../org/apache/iotdb/db/utils/SchemaUtilsTest.java | 23 ++++++++++++++++++++++
8 files changed, 44 insertions(+), 29 deletions(-)
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalBatchActivateTemplateStatement.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalBatchActivateTemplateStatement.java
index 39cf053aa5b..ca2c5c79e65 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalBatchActivateTemplateStatement.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalBatchActivateTemplateStatement.java
@@ -34,7 +34,7 @@ import java.util.Map;
public class InternalBatchActivateTemplateStatement extends Statement {
// devicePath -> <Template, TemplateSetPath>
- private Map<PartialPath, Pair<Template, PartialPath>> deviceMap;
+ private final Map<PartialPath, Pair<Template, PartialPath>> deviceMap;
public InternalBatchActivateTemplateStatement(
Map<PartialPath, Pair<Template, PartialPath>> deviceMap) {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateMultiTimeSeriesStatement.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateMultiTimeSeriesStatement.java
index cf1b20364b6..58debfd13c1 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateMultiTimeSeriesStatement.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateMultiTimeSeriesStatement.java
@@ -32,7 +32,7 @@ import java.util.Map;
public class InternalCreateMultiTimeSeriesStatement extends Statement {
- private Map<PartialPath, Pair<Boolean, MeasurementGroup>> deviceMap;
+ private final Map<PartialPath, Pair<Boolean, MeasurementGroup>> deviceMap;
public InternalCreateMultiTimeSeriesStatement(
Map<PartialPath, Pair<Boolean, MeasurementGroup>> deviceMap) {
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateTimeSeriesStatement.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateTimeSeriesStatement.java
index da3d048c36c..e48eabe63d3 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateTimeSeriesStatement.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/internal/InternalCreateTimeSeriesStatement.java
@@ -27,21 +27,20 @@ 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 java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
// This is only used for auto creation while inserting data
public class InternalCreateTimeSeriesStatement extends Statement {
- private PartialPath devicePath;
- private List<String> measurements;
+ private final PartialPath devicePath;
+ private final List<String> measurements;
- private List<TSDataType> tsDataTypes;
- private List<TSEncoding> encodings = new ArrayList<>();
- private List<CompressionType> compressors = new ArrayList<>();
+ private final List<TSDataType> tsDataTypes;
+ private final List<TSEncoding> encodings;
+ private final List<CompressionType> compressors;
- private boolean isAligned;
+ private final boolean isAligned;
public InternalCreateTimeSeriesStatement(
PartialPath devicePath,
@@ -86,7 +85,7 @@ public class InternalCreateTimeSeriesStatement extends Statement {
@Override
public List<PartialPath> getPaths() {
- return measurements.stream().map(o -> devicePath.concatNode(o)).collect(Collectors.toList());
+ return measurements.stream().map(devicePath::concatNode).collect(Collectors.toList());
}
@Override
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java
index 6c5b1a6666d..4bbf9f85d0e 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java
@@ -54,8 +54,6 @@ public class PBTreeFileSketchTool {
private static String inputFile;
private static String outputFile;
- private static PrintWriter pw;
-
/**
* create the commandline options.
*
@@ -146,9 +144,10 @@ public class PBTreeFileSketchTool {
return str;
}
+ @SuppressWarnings("squid:S106")
public static void sketchFile(String inputFile, String outputFile)
throws IOException, MetadataException {
- pw = new PrintWriter(new FileWriter(outputFile, false));
+ PrintWriter pw = new PrintWriter(new FileWriter(outputFile, false));
ISchemaFile sf = SchemaFile.loadSchemaFile(SystemFileFactory.INSTANCE.getFile(inputFile));
try {
String res = ((SchemaFile) sf).inspect(pw);
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java
index fe06a9870d7..b00ec481b37 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java
@@ -26,9 +26,7 @@ import org.apache.iotdb.db.utils.constant.SqlConstant;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashSet;
@@ -81,22 +79,15 @@ public class SchemaUtils {
schemaChecker.put(TSDataType.TEXT, textSet);
}
- public static List<TSDataType> getSeriesTypesByPaths(Collection<? extends PartialPath> paths) {
- List<TSDataType> dataTypes = new ArrayList<>();
- for (PartialPath path : paths) {
- dataTypes.add(path == null ? null : path.getSeriesType());
- }
- return dataTypes;
- }
-
/**
* If the datatype of 'aggregation' depends on 'measurementDataType' (min_value, max_value),
* return 'measurementDataType' directly, or return a list whose elements are all the datatype of
* 'aggregation' and its length is the same as 'measurementDataType'.
*
- * @param measurementDataType
- * @param aggregation
- * @return
+ * @param measurementDataType raw measurement type
+ * @param aggregation aggregation type
+ * @return measurementDataType directly, or return a list whose elements are all the datatype of
+ * aggregation and its length is the same as 'measurementDataType'
*/
public static List<TSDataType> getAggregatedDataTypes(
List<TSDataType> measurementDataType, String aggregation) {
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/MLogParserTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/MLogParserTest.java
index 38f63764be0..a0773eff00d 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/MLogParserTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/MLogParserTest.java
@@ -165,8 +165,10 @@ public class MLogParserTest {
File file = new File("target" + File.separator + "tmp" + File.separator + "text.mlog");
file.delete();
- MLogParser.parseFromFile(
- path, "target" + File.separator + "tmp" + File.separator + "text.mlog");
+ MLogParser.main(
+ new String[] {
+ "-f", path, "-o", "target" + File.separator + "tmp" + File.separator + "text.mlog"
+ });
try (BufferedReader reader =
new BufferedReader(
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/PBTreeFileSketchTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/PBTreeFileSketchTest.java
index 590284c9c25..0c05b672803 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/PBTreeFileSketchTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/tools/PBTreeFileSketchTest.java
@@ -106,7 +106,8 @@ public class PBTreeFileSketchTest {
+ SchemaConstant.PBTREE_FILE_NAME);
File sketchFile = new File("sketch_schemafile.txt");
- PBTreeFileSketchTool.sketchFile(file.getAbsolutePath(), sketchFile.getAbsolutePath());
+ PBTreeFileSketchTool.main(
+ new String[] {"-f", file.getAbsolutePath(), "-o", sketchFile.getAbsolutePath()});
ISchemaFile sf = SchemaFile.loadSchemaFile(file);
try {
StringWriter sw = new StringWriter();
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaUtilsTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaUtilsTest.java
index dd04a4a2802..7c76d5bafcf 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaUtilsTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaUtilsTest.java
@@ -18,8 +18,12 @@
*/
package org.apache.iotdb.db.utils;
+import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.db.utils.constant.SqlConstant;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.junit.Assert;
import org.junit.Test;
@@ -52,4 +56,23 @@ public class SchemaUtilsTest {
measurementTypes,
SchemaUtils.getAggregatedDataTypes(measurementTypes, SqlConstant.MAX_VALUE));
}
+
+ @Test
+ public void getSeriesTypeByPath() throws IllegalPathException {
+ MeasurementPath measurementPath = new MeasurementPath("s1", TSDataType.INT64);
+ Assert.assertEquals(
+ TSDataType.DOUBLE, SchemaUtils.getSeriesTypeByPath(measurementPath, SqlConstant.SUM));
+ Assert.assertEquals(
+ TSDataType.INT64, SchemaUtils.getSeriesTypeByPath(measurementPath, SqlConstant.LAST_VALUE));
+ }
+
+ @Test
+ public void checkDataTypeWithEncoding() {
+ try {
+ SchemaUtils.checkDataTypeWithEncoding(TSDataType.TEXT, TSEncoding.RLE);
+ Assert.fail("expect exception");
+ } catch (MetadataException e) {
+ // do nothing
+ }
+ }
}