This is an automated email from the ASF dual-hosted git repository.

qiaojialin 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 f72064d  [IOTDB-928] Make ENCODING optional in create time series 
sentence (#1785)
f72064d is described below

commit f72064d2e381c5ae9d36276cdc317c862a46ffbf
Author: Qi Yu <[email protected]>
AuthorDate: Mon Oct 19 22:41:44 2020 +0800

    [IOTDB-928] Make ENCODING optional in create time series sentence (#1785)
---
 .../org/apache/iotdb/db/qp/strategy/SqlBase.g4     |  2 +-
 .../org/apache/iotdb/db/conf/IoTDBDescriptor.java  | 23 +++++++++++++++++
 .../iotdb/db/qp/strategy/LogicalGenerator.java     | 17 ++++++++++---
 .../iotdb/db/integration/IoTDBMultiSeriesIT.java   | 29 ++++++++++++++++++++++
 4 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4 
b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4
index 8d92a99..c7bba59 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/strategy/SqlBase.g4
@@ -166,7 +166,7 @@ aliasClause
     ;
 
 attributeClauses
-    : DATATYPE OPERATOR_EQ dataType COMMA ENCODING OPERATOR_EQ encoding
+    : DATATYPE OPERATOR_EQ dataType (COMMA ENCODING OPERATOR_EQ encoding)?
     (COMMA (COMPRESSOR | COMPRESSION) OPERATOR_EQ compressor)?
     (COMMA property)*
     tagClause
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java 
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index fbeccfd..af11e70 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -39,6 +39,7 @@ import 
org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.utils.FilePathUtils;
 import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.fileSystem.FSType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -756,6 +757,28 @@ public class IoTDBDescriptor {
 
   }
 
+  /**
+   * Get default encode algorithm by data type
+   * @param dataType
+   * @return
+   */
+  public TSEncoding getDefualtEncodingByType(TSDataType dataType) {
+    switch (dataType) {
+      case BOOLEAN:
+        return conf.getDefaultBooleanEncoding();
+      case INT32:
+        return conf.getDefaultInt32Encoding();
+      case INT64:
+        return conf.getDefaultInt64Encoding();
+      case FLOAT:
+        return conf.getDefaultFloatEncoding();
+      case DOUBLE:
+        return conf.getDefaultDoubleEncoding();
+      default:
+        return conf.getDefaultTextEncoding();
+    }
+  }
+
   private static class IoTDBDescriptorHolder {
 
     private static final IoTDBDescriptor INSTANCE = new IoTDBDescriptor();
diff --git 
a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java 
b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
index 5225e73..6feb46a 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import org.antlr.v4.runtime.tree.TerminalNode;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -1172,10 +1173,18 @@ public class LogicalGenerator extends 
SqlBaseBaseListener {
   @Override
   public void enterAttributeClauses(AttributeClausesContext ctx) {
     super.enterAttributeClauses(ctx);
-    String dataType = ctx.dataType().getChild(0).getText().toUpperCase();
-    String encoding = ctx.encoding().getChild(0).getText().toUpperCase();
-    createTimeSeriesOperator.setDataType(TSDataType.valueOf(dataType));
-    createTimeSeriesOperator.setEncoding(TSEncoding.valueOf(encoding));
+    final String dataType = ctx.dataType().getChild(0).getText().toUpperCase();
+    final TSDataType tsDataType = TSDataType.valueOf(dataType);
+    createTimeSeriesOperator.setDataType(tsDataType);
+
+    final IoTDBDescriptor ioTDBDescriptor = IoTDBDescriptor.getInstance();
+    TSEncoding encoding = ioTDBDescriptor.getDefualtEncodingByType(tsDataType);
+    if (Objects.nonNull(ctx.encoding())) {
+      String encodingString = 
ctx.encoding().getChild(0).getText().toUpperCase();
+      encoding = TSEncoding.valueOf(encodingString);
+    }
+    createTimeSeriesOperator.setEncoding(encoding);
+
     CompressionType compressor;
     List<PropertyContext> properties = ctx.property();
     if (ctx.compressor() != null) {
diff --git 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java
index 22f851c..89940e1 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java
@@ -34,6 +34,7 @@ import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
 import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
 import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -437,4 +438,32 @@ public class IoTDBMultiSeriesIT {
           e.getMessage());
     }
   }
+
+  @Test
+  public void testCreateTimeSeriesWithoutEncoding() throws SQLException {
+    try (Connection connection = DriverManager
+            .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", 
"root", "root");
+         Statement statement = connection.createStatement()) {
+      statement.execute("CREATE TIMESERIES root.ln.wf01.wt01.name WITH 
DATATYPE=TEXT");
+      statement.execute("CREATE TIMESERIES root.ln.wf01.wt01.age WITH 
DATATYPE=INT32, ENCODING=RLE");
+      statement.execute("CREATE TIMESERIES root.ln.wf01.wt01.salary WITH 
DATATYPE=INT64");
+      statement.execute("CREATE TIMESERIES root.ln.wf01.wt01.score WITH 
DATATYPE=FLOAT");
+
+      ResultSet nameRs = statement.executeQuery("SHOW TIMESERIES 
root.ln.wf01.wt01.name");
+      nameRs.next();
+      
Assert.assertTrue(TSEncoding.PLAIN.name().equalsIgnoreCase(nameRs.getString(5)));
+
+      ResultSet ageRs = statement.executeQuery("SHOW TIMESERIES 
root.ln.wf01.wt01.age");
+      ageRs.next();
+      
Assert.assertTrue(TSEncoding.RLE.name().equalsIgnoreCase(ageRs.getString(5)));
+
+      ResultSet salaryRs = statement.executeQuery("SHOW TIMESERIES 
root.ln.wf01.wt01.salary");
+      salaryRs.next();
+      
Assert.assertTrue(TSEncoding.RLE.name().equalsIgnoreCase(salaryRs.getString(5)));
+
+      ResultSet scoreRs = statement.executeQuery("SHOW TIMESERIES 
root.ln.wf01.wt01.score");
+      scoreRs.next();
+      
Assert.assertTrue(TSEncoding.GORILLA.name().equalsIgnoreCase(scoreRs.getString(5)));
+    }
+  }
 }

Reply via email to