This is an automated email from the ASF dual-hosted git repository.
haonan 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 f82f180 delete some useless type transfer while deserializing and
serializing MeasurementMNode (#1803)
f82f180 is described below
commit f82f18027b6c5376fdb0cecee53e14779aaa63f3
Author: Jackie Tien <[email protected]>
AuthorDate: Tue Oct 6 20:44:44 2020 +0800
delete some useless type transfer while deserializing and serializing
MeasurementMNode (#1803)
---
.../java/org/apache/iotdb/db/metadata/MTree.java | 43 +++++-----
.../iotdb/db/metadata/mnode/MeasurementMNode.java | 13 ++-
.../file/metadata/enums/CompressionType.java | 99 ++++------------------
.../tsfile/file/metadata/enums/TSDataType.java | 53 ++++--------
.../tsfile/file/metadata/enums/TSEncoding.java | 62 +++-----------
.../tsfile/write/schema/MeasurementSchema.java | 34 +++++---
6 files changed, 92 insertions(+), 212 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index 1abd0e7..925ffe2 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -112,13 +112,8 @@ public class MTree implements Serializable {
* @param props props
* @param alias alias of measurement
*/
- MeasurementMNode createTimeseries(
- PartialPath path,
- TSDataType dataType,
- TSEncoding encoding,
- CompressionType compressor,
- Map<String, String> props,
- String alias)
+ MeasurementMNode createTimeseries(PartialPath path, TSDataType dataType,
TSEncoding encoding,
+ CompressionType compressor, Map<String, String> props, String alias)
throws MetadataException {
String[] nodeNames = path.getNodes();
if (nodeNames.length <= 2 || !nodeNames[0].equals(root.getName())) {
@@ -240,9 +235,11 @@ public class MTree implements Serializable {
}
}
- private void checkStorageGroup(String storageGroup) throws
IllegalPathException{
- if(!IoTDBConfig.STORAGE_GROUP_PATTERN.matcher(storageGroup).matches()) {
- throw new IllegalPathException(String.format("The storage group name can
only be characters, numbers and underscores. %s", storageGroup));
+ private void checkStorageGroup(String storageGroup) throws
IllegalPathException {
+ if (!IoTDBConfig.STORAGE_GROUP_PATTERN.matcher(storageGroup).matches()) {
+ throw new IllegalPathException(String
+ .format("The storage group name can only be characters, numbers and
underscores. %s",
+ storageGroup));
}
}
@@ -385,12 +382,12 @@ public class MTree implements Serializable {
}
/**
- * E.g., root.sg is storage group
- * given [root, sg], return the MNode of root.sg
- * given [root, sg, device], throw exception
- * Get storage group node, if the give path is not a storage group, throw
exception
+ * E.g., root.sg is storage group given [root, sg], return the MNode of
root.sg given [root, sg,
+ * device], throw exception Get storage group node, if the give path is not
a storage group, throw
+ * exception
*/
- StorageGroupMNode getStorageGroupNodeByStorageGroupPath(PartialPath path)
throws MetadataException {
+ StorageGroupMNode getStorageGroupNodeByStorageGroupPath(PartialPath path)
+ throws MetadataException {
MNode node = getNodeByPath(path);
if (node instanceof StorageGroupMNode) {
return (StorageGroupMNode) node;
@@ -400,10 +397,9 @@ public class MTree implements Serializable {
}
/**
- * E.g., root.sg is storage group
- * given [root, sg], return the MNode of root.sg
- * given [root, sg, device], return the MNode of root.sg
- * Get storage group node, the give path don't need to be storage group path.
+ * E.g., root.sg is storage group given [root, sg], return the MNode of
root.sg given [root, sg,
+ * device], return the MNode of root.sg Get storage group node, the give
path don't need to be
+ * storage group path.
*/
StorageGroupMNode getStorageGroupNodeByPath(PartialPath path) throws
MetadataException {
String[] nodes = path.getNodes();
@@ -808,7 +804,8 @@ public class MTree implements Serializable {
findPath(root, nodes, 1, allMatchedNodes, false, true, queryContext);
Stream<Pair<PartialPath, String[]>> sortedStream =
allMatchedNodes.stream().sorted(
- Comparator.comparingLong((Pair<PartialPath, String[]> p) ->
Long.parseLong(p.right[6])).reversed()
+ Comparator.comparingLong((Pair<PartialPath, String[]> p) ->
Long.parseLong(p.right[6]))
+ .reversed()
.thenComparing((Pair<PartialPath, String[]> p) -> p.left));
// no limit
@@ -825,7 +822,8 @@ public class MTree implements Serializable {
*
* <p>result: [name, alias, storage group, dataType, encoding, compression,
offset]
*/
- List<Pair<PartialPath, String[]>> getAllMeasurementSchema(ShowTimeSeriesPlan
plan) throws MetadataException {
+ List<Pair<PartialPath, String[]>> getAllMeasurementSchema(ShowTimeSeriesPlan
plan)
+ throws MetadataException {
List<Pair<PartialPath, String[]>> res;
String[] nodes = plan.getPath().getNodes();
if (nodes.length == 0 || !nodes[0].equals(root.getName())) {
@@ -858,7 +856,8 @@ public class MTree implements Serializable {
* dataType, encoding, compression, offset,
lastTimeStamp]
*/
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity
warning
- private void findPath(MNode node, String[] nodes, int idx,
List<Pair<PartialPath, String[]>> timeseriesSchemaList,
+ private void findPath(MNode node, String[] nodes, int idx,
+ List<Pair<PartialPath, String[]>> timeseriesSchemaList,
boolean hasLimit, boolean needLast, QueryContext queryContext) throws
MetadataException {
if (node instanceof MeasurementMNode && nodes.length <= idx) {
if (hasLimit) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MeasurementMNode.java
b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MeasurementMNode.java
index 645b34a..5da9d1c 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MeasurementMNode.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MeasurementMNode.java
@@ -147,8 +147,9 @@ public class MeasurementMNode extends MNode {
* deserialize MeasuremetMNode from string array
*
* @param nodeInfo node information array. For example:
"2,s0,speed,2,2,1,year:2020;month:jan;,-1,0"
- * representing: [0] nodeType [1] name [2] alias [3] TSDataType.ordinal()
[4] TSEncoding.ordinal()
- * [5] CompressionType.ordinal() [6] props [7] offset [8] children size
+ * representing: [0] nodeType [1] name [2] alias [3]
TSDataType.ordinal() [4]
+ * TSEncoding.ordinal() [5] CompressionType.ordinal() [6]
props [7] offset [8]
+ * children size
*/
public static MeasurementMNode deserializeFrom(String[] nodeInfo) {
String name = nodeInfo[1];
@@ -159,12 +160,10 @@ public class MeasurementMNode extends MNode {
props.put(propInfo.split(":")[0], propInfo.split(":")[1]);
}
}
- MeasurementSchema schema = new MeasurementSchema(name,
- TSDataType.deserialize(Short.valueOf(nodeInfo[3])),
- TSEncoding.deserialize(Short.valueOf(nodeInfo[4])),
- CompressionType.deserialize(Short.valueOf(nodeInfo[5])), props);
+ MeasurementSchema schema = new MeasurementSchema(name,
Byte.parseByte(nodeInfo[3]),
+ Byte.parseByte(nodeInfo[4]), Byte.parseByte(nodeInfo[5]), props);
MeasurementMNode node = new MeasurementMNode(null, name, schema, alias);
- node.setOffset(Long.valueOf(nodeInfo[7]));
+ node.setOffset(Long.parseLong(nodeInfo[7]));
return node;
}
diff --git
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/CompressionType.java
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/CompressionType.java
index 47143fc..e8380e6 100644
---
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/CompressionType.java
+++
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/CompressionType.java
@@ -18,8 +18,6 @@
*/
package org.apache.iotdb.tsfile.file.metadata.enums;
-import
org.apache.iotdb.tsfile.exception.compress.CompressionTypeNotSupportedException;
-
public enum CompressionType {
UNCOMPRESSED, SNAPPY, GZIP, LZO, SDT, PAA, PLA, LZ4;
@@ -30,12 +28,22 @@ public enum CompressionType {
* @return CompressionType
*/
public static CompressionType deserialize(short compressor) {
- if (compressor >= 8) {
+ return getCompressionType(compressor);
+ }
+
+ public static byte deserializeToByte(short compressor) {
+ if (compressor >= 8 || compressor < 0) {
+ throw new IllegalArgumentException("Invalid input: " + compressor);
+ }
+ return (byte) compressor;
+ }
+
+
+ private static CompressionType getCompressionType(short compressor) {
+ if (compressor >= 8 || compressor < 0) {
throw new IllegalArgumentException("Invalid input: " + compressor);
}
switch (compressor) {
- case 0:
- return UNCOMPRESSED;
case 1:
return SNAPPY;
case 2:
@@ -62,29 +70,7 @@ public enum CompressionType {
* @return CompressionType
*/
public static CompressionType byteToEnum(byte compressor) {
- if (compressor >= 8) {
- throw new IllegalArgumentException("Invalid input: " + compressor);
- }
- switch (compressor) {
- case 0:
- return UNCOMPRESSED;
- case 1:
- return SNAPPY;
- case 2:
- return GZIP;
- case 3:
- return LZO;
- case 4:
- return SDT;
- case 5:
- return PAA;
- case 6:
- return PLA;
- case 7:
- return LZ4;
- default:
- return UNCOMPRESSED;
- }
+ return getCompressionType(compressor);
}
public static int getSerializedSize() {
@@ -92,63 +78,12 @@ public enum CompressionType {
}
/**
- * find by short name.
- *
- * @param name name
- * @return CompressionType
- */
- public static CompressionType findByShortName(String name) {
- if (name == null) {
- return UNCOMPRESSED;
- }
- switch (name.trim().toUpperCase()) {
- case "UNCOMPRESSED":
- return UNCOMPRESSED;
- case "SNAPPY":
- return SNAPPY;
- case "GZIP":
- return GZIP;
- case "LZO":
- return LZO;
- case "SDT":
- return SDT;
- case "PAA":
- return PAA;
- case "PLA":
- return PLA;
- case "LZ4":
- return LZ4;
- default:
- throw new CompressionTypeNotSupportedException(name);
- }
- }
-
- /**
* serialize.
*
* @return short number
*/
public short serialize() {
- switch (this) {
- case UNCOMPRESSED:
- return 0;
- case SNAPPY:
- return 1;
- case GZIP:
- return 2;
- case LZO:
- return 3;
- case SDT:
- return 4;
- case PAA:
- return 5;
- case PLA:
- return 6;
- case LZ4:
- return 7;
- default:
- return 0;
- }
+ return enumToByte();
}
/**
@@ -156,8 +91,6 @@ public enum CompressionType {
*/
public byte enumToByte() {
switch (this) {
- case UNCOMPRESSED:
- return 0;
case SNAPPY:
return 1;
case GZIP:
@@ -184,8 +117,6 @@ public enum CompressionType {
*/
public String getExtension() {
switch (this) {
- case UNCOMPRESSED:
- return "";
case SNAPPY:
return ".snappy";
case GZIP:
diff --git
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSDataType.java
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSDataType.java
index 588de0b..882d8dd 100644
---
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSDataType.java
+++
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSDataType.java
@@ -32,7 +32,12 @@ public enum TSDataType {
* @return -enum type
*/
public static TSDataType deserialize(short type) {
- if (type >= 6) {
+ return getTsDataType(type);
+ }
+
+
+ private static TSDataType getTsDataType(short type) {
+ if (type >= 6 || type < 0) {
throw new IllegalArgumentException("Invalid input: " + type);
}
switch (type) {
@@ -46,13 +51,18 @@ public enum TSDataType {
return FLOAT;
case 4:
return DOUBLE;
- case 5:
- return TEXT;
default:
return TEXT;
}
}
+ public static byte deserializeToByte(short type) {
+ if (type >= 6 || type < 0) {
+ throw new IllegalArgumentException("Invalid input: " + type);
+ }
+ return (byte) type;
+ }
+
/**
* give an byte to return a data type.
*
@@ -60,25 +70,7 @@ public enum TSDataType {
* @return data type
*/
public static TSDataType byteToEnum(byte type) {
- if (type >= 6) {
- throw new IllegalArgumentException("Invalid input: " + type);
- }
- switch (type) {
- case 0:
- return BOOLEAN;
- case 1:
- return INT32;
- case 2:
- return INT64;
- case 3:
- return FLOAT;
- case 4:
- return DOUBLE;
- case 5:
- return TEXT;
- default:
- return TEXT;
- }
+ return getTsDataType(type);
}
public static TSDataType deserializeFrom(ByteBuffer buffer) {
@@ -103,22 +95,7 @@ public enum TSDataType {
* @return -enum type
*/
public short serialize() {
- switch (this) {
- case BOOLEAN:
- return 0;
- case INT32:
- return 1;
- case INT64:
- return 2;
- case FLOAT:
- return 3;
- case DOUBLE:
- return 4;
- case TEXT:
- return 5;
- default:
- return -1;
- }
+ return enumToByte();
}
/**
diff --git
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSEncoding.java
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSEncoding.java
index 2c8e525..af54841 100644
---
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSEncoding.java
+++
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/enums/TSEncoding.java
@@ -29,12 +29,21 @@ public enum TSEncoding {
* @return -encoding type
*/
public static TSEncoding deserialize(short encoding) {
- if (encoding >= 8) {
+ return getTsEncoding(encoding);
+ }
+
+ public static byte deserializeToByte(short encoding) {
+ if (encoding >= 8 || encoding < 0) {
+ throw new IllegalArgumentException("Invalid input: " + encoding);
+ }
+ return (byte) encoding;
+ }
+
+ private static TSEncoding getTsEncoding(short encoding) {
+ if (encoding >= 8 || encoding < 0) {
throw new IllegalArgumentException("Invalid input: " + encoding);
}
switch (encoding) {
- case 0:
- return PLAIN;
case 1:
return PLAIN_DICTIONARY;
case 2:
@@ -61,29 +70,7 @@ public enum TSEncoding {
* @return encoding type
*/
public static TSEncoding byteToEnum(byte encoding) {
- if (encoding >= 8) {
- throw new IllegalArgumentException("Invalid input: " + encoding);
- }
- switch (encoding) {
- case 0:
- return PLAIN;
- case 1:
- return PLAIN_DICTIONARY;
- case 2:
- return RLE;
- case 3:
- return DIFF;
- case 4:
- return TS_2DIFF;
- case 5:
- return BITMAP;
- case 6:
- return GORILLA;
- case 7:
- return REGULAR;
- default:
- return PLAIN;
- }
+ return getTsEncoding(encoding);
}
public static int getSerializedSize() {
@@ -96,26 +83,7 @@ public enum TSEncoding {
* @return -encoding type
*/
public short serialize() {
- switch (this) {
- case PLAIN:
- return 0;
- case PLAIN_DICTIONARY:
- return 1;
- case RLE:
- return 2;
- case DIFF:
- return 3;
- case TS_2DIFF:
- return 4;
- case BITMAP:
- return 5;
- case GORILLA:
- return 6;
- case REGULAR:
- return 7;
- default:
- return 0;
- }
+ return enumToByte();
}
/**
@@ -123,8 +91,6 @@ public enum TSEncoding {
*/
public byte enumToByte() {
switch (this) {
- case PLAIN:
- return 0;
case PLAIN_DICTIONARY:
return 1;
case RLE:
diff --git
a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/schema/MeasurementSchema.java
b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/schema/MeasurementSchema.java
index d9ea02b..3e19119 100644
---
a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/schema/MeasurementSchema.java
+++
b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/schema/MeasurementSchema.java
@@ -23,7 +23,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -90,6 +89,15 @@ public class MeasurementSchema implements
Comparable<MeasurementSchema>, Seriali
this.compressor = compressionType.enumToByte();
}
+ public MeasurementSchema(String measurementId, byte type, byte encoding,
+ byte compressionType, Map<String, String> props) {
+ this.type = type;
+ this.measurementId = measurementId;
+ this.encoding = encoding;
+ this.props = props;
+ this.compressor = compressionType;
+ }
+
/**
* function for deserializing data from input stream.
*/
@@ -98,11 +106,11 @@ public class MeasurementSchema implements
Comparable<MeasurementSchema>, Seriali
measurementSchema.measurementId = ReadWriteIOUtils.readString(inputStream);
- measurementSchema.type =
ReadWriteIOUtils.readDataType(inputStream).enumToByte();
+ measurementSchema.type =
TSDataType.deserializeToByte(ReadWriteIOUtils.readShort(inputStream));
- measurementSchema.encoding =
ReadWriteIOUtils.readEncoding(inputStream).enumToByte();
+ measurementSchema.encoding =
TSEncoding.deserializeToByte(ReadWriteIOUtils.readShort(inputStream));
- measurementSchema.compressor =
ReadWriteIOUtils.readCompressionType(inputStream).enumToByte();
+ measurementSchema.compressor =
CompressionType.deserializeToByte(ReadWriteIOUtils.readShort(inputStream));
int size = ReadWriteIOUtils.readInt(inputStream);
if (size > 0) {
@@ -127,11 +135,11 @@ public class MeasurementSchema implements
Comparable<MeasurementSchema>, Seriali
measurementSchema.measurementId = ReadWriteIOUtils.readString(buffer);
- measurementSchema.type =
ReadWriteIOUtils.readDataType(buffer).enumToByte();
+ measurementSchema.type =
TSDataType.deserializeToByte(ReadWriteIOUtils.readShort(buffer));
- measurementSchema.encoding =
ReadWriteIOUtils.readEncoding(buffer).enumToByte();
+ measurementSchema.encoding =
TSEncoding.deserializeToByte(ReadWriteIOUtils.readShort(buffer));
- measurementSchema.compressor =
ReadWriteIOUtils.readCompressionType(buffer).enumToByte();
+ measurementSchema.compressor =
CompressionType.deserializeToByte(ReadWriteIOUtils.readShort(buffer));
int size = ReadWriteIOUtils.readInt(buffer);
if (size > 0) {
@@ -210,11 +218,11 @@ public class MeasurementSchema implements
Comparable<MeasurementSchema>, Seriali
byteLen += ReadWriteIOUtils.write(measurementId, outputStream);
- byteLen += ReadWriteIOUtils.write(TSDataType.byteToEnum(type),
outputStream);
+ byteLen += ReadWriteIOUtils.write((short) type, outputStream);
- byteLen += ReadWriteIOUtils.write(TSEncoding.byteToEnum(encoding),
outputStream);
+ byteLen += ReadWriteIOUtils.write((short) encoding, outputStream);
- byteLen += ReadWriteIOUtils.write(CompressionType.byteToEnum(compressor),
outputStream);
+ byteLen += ReadWriteIOUtils.write((short) compressor, outputStream);
if (props == null) {
byteLen += ReadWriteIOUtils.write(0, outputStream);
@@ -237,11 +245,11 @@ public class MeasurementSchema implements
Comparable<MeasurementSchema>, Seriali
byteLen += ReadWriteIOUtils.write(measurementId, buffer);
- byteLen += ReadWriteIOUtils.write(TSDataType.byteToEnum(type), buffer);
+ byteLen += ReadWriteIOUtils.write((short) type, buffer);
- byteLen += ReadWriteIOUtils.write(TSEncoding.byteToEnum(encoding), buffer);
+ byteLen += ReadWriteIOUtils.write((short) encoding, buffer);
- byteLen += ReadWriteIOUtils.write(CompressionType.byteToEnum(compressor),
buffer);
+ byteLen += ReadWriteIOUtils.write((short) compressor, buffer);
if (props == null) {
byteLen += ReadWriteIOUtils.write(0, buffer);