You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/05/23 01:55:53 UTC

[GitHub] [iotdb] SteveYurongSu commented on a diff in pull request #5955: [IOTDB-3236] register a timeseries with a wrong compress type

SteveYurongSu commented on code in PR #5955:
URL: https://github.com/apache/iotdb/pull/5955#discussion_r878969104


##########
server/src/main/java/org/apache/iotdb/db/qp/logical/sys/CreateTimeSeriesOperator.java:
##########
@@ -124,4 +128,61 @@ public PhysicalPlan generatePhysicalPlan(PhysicalGenerator generator)
     return new CreateTimeSeriesPlan(
         path, dataType, encoding, compressor, props, tags, attributes, alias);
   }
+
+  /**
+   * check datatype,encoding,compressor
+   *
+   * @throws SemanticException e
+   */
+  public void check() throws SemanticException {
+    if (!props.containsKey(IoTDBConstant.COLUMN_TIMESERIES_DATATYPE.toLowerCase())) {
+      throw new SemanticException("datatype must be declared");
+    }
+    String datatypeString =
+        props.get(IoTDBConstant.COLUMN_TIMESERIES_DATATYPE.toLowerCase()).toUpperCase();
+    try {
+      this.dataType = TSDataType.valueOf(datatypeString);
+      props.remove(IoTDBConstant.COLUMN_TIMESERIES_DATATYPE.toLowerCase());
+    } catch (Exception e) {
+      throw new SemanticException(String.format("Unsupported datatype: %s", datatypeString));
+    }
+
+    final IoTDBDescriptor ioTDBDescriptor = IoTDBDescriptor.getInstance();
+    this.encoding = ioTDBDescriptor.getDefaultEncodingByType(this.dataType);
+    if (props.containsKey(IoTDBConstant.COLUMN_TIMESERIES_ENCODING.toLowerCase())) {
+      String encodingString =
+          props.get(IoTDBConstant.COLUMN_TIMESERIES_ENCODING.toLowerCase()).toUpperCase();
+      try {
+        this.encoding = TSEncoding.valueOf(encodingString);
+        props.remove(IoTDBConstant.COLUMN_TIMESERIES_ENCODING.toLowerCase());
+      } catch (Exception e) {
+        throw new SemanticException(String.format("Unsupported encoding: %s", encodingString));
+      }
+    }
+
+    this.compressor = TSFileDescriptor.getInstance().getConfig().getCompressor();
+    if (props.containsKey(IoTDBConstant.COLUMN_TIMESERIES_COMPRESSION)) {
+      String compressionString =
+          props.get(IoTDBConstant.COLUMN_TIMESERIES_COMPRESSION.toLowerCase()).toUpperCase();
+      try {
+        this.compressor = CompressionType.valueOf(compressionString);
+        props.remove(IoTDBConstant.COLUMN_TIMESERIES_COMPRESSION.toLowerCase());
+      } catch (Exception e) {
+        throw new SemanticException(
+            String.format("Unsupported compression: %s", compressionString));
+      }
+    } else if (props.containsKey(IoTDBConstant.COLUMN_TIMESERIES_COMPRESSOR)) {
+      String compressorString =
+          props.get(IoTDBConstant.COLUMN_TIMESERIES_COMPRESSOR.toLowerCase()).toUpperCase();
+      try {
+        this.compressor = CompressionType.valueOf(compressorString);
+        props.remove(IoTDBConstant.COLUMN_TIMESERIES_COMPRESSOR.toLowerCase());
+      } catch (Exception e) {
+        throw new SemanticException(String.format("Unsupported compression: %s", compressorString));
+      }
+    }
+    if (props.size() == 0) {
+      props = null;
+    }

Review Comment:
   ```suggestion
   ```



##########
server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java:
##########
@@ -1621,23 +1715,13 @@ private void parsePrimitiveTypeClause(
   }
 
   private TSDataType parseType(String datatype) {
-    String type = datatype.toLowerCase();
-    switch (type) {
-      case "int32":
-        return TSDataType.INT32;
-      case "int64":
-        return TSDataType.INT64;
-      case "float":
-        return TSDataType.FLOAT;
-      case "double":
-        return TSDataType.DOUBLE;
-      case "boolean":
-        return TSDataType.BOOLEAN;
-      case "text":
-        return TSDataType.TEXT;
-      default:
-        throw new SQLParserException("not a valid fill type : " + type);
+    TSDataType tsDataType;
+    try {
+      tsDataType = TSDataType.valueOf(datatype.toUpperCase());

Review Comment:
   ```suggestion
         return TSDataType.valueOf(datatype.toUpperCase());
   ```



##########
server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java:
##########
@@ -418,26 +461,77 @@ void parseAttributeClause(
     if (ctx.aliasNodeName() != null) {
       throw new SQLParserException("schema template: alias is not supported yet.");
     }
+    TSDataType dataType = null;
+    TSEncoding encoding = null;
+    CompressionType compressor = null;
 
-    String dataTypeString = ctx.dataType.getText().toUpperCase();
-    TSDataType dataType = TSDataType.valueOf(dataTypeString);
-    dataTypes.add(dataType);
+    if (ctx.dataType != null) {
+      if (ctx.attributeKey() != null) {
+        if (!parseAttributeKey(ctx.attributeKey())
+            .equalsIgnoreCase(IoTDBConstant.COLUMN_TIMESERIES_DATATYPE)) {
+          throw new SQLParserException("expecting datatype");
+        }
+      }
+      String dataTypeString = ctx.dataType.getText().toUpperCase();
+      try {
+        dataType = TSDataType.valueOf(dataTypeString);
+        dataTypes.add(dataType);

Review Comment:
   ```suggestion
           dataTypes.add(TSDataType.valueOf(dataTypeString));
   ```



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org