You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2022/03/13 13:34:53 UTC

[iotdb] branch master updated: [IOTDB-2461] Add cpp and sql support for ZIGZAG encoding (#5207)

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 32cd145  [IOTDB-2461] Add cpp and sql support for ZIGZAG encoding (#5207)
32cd145 is described below

commit 32cd14528a74c9350fcf2487dc62d6e9fc368e07
Author: Haonan <hh...@outlook.com>
AuthorDate: Sun Mar 13 21:34:18 2022 +0800

    [IOTDB-2461] Add cpp and sql support for ZIGZAG encoding (#5207)
---
 .../antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4  |  5 +-
 client-cpp/src/main/Session.h                      |  3 +-
 .../iotdb/db/integration/IoTDBEncodingIT.java      | 69 +++++++++++++++++++++-
 3 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4
index 89a4603..c08d2c9 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4
@@ -633,7 +633,7 @@ TEXT
 // Encoding Type Keywords
 
 ENCODING_VALUE
-    : DICTIONARY | DIFF | GORILLA | PLAIN | REGULAR | RLE | TS_2DIFF
+    : DICTIONARY | DIFF | GORILLA | PLAIN | REGULAR | RLE | TS_2DIFF | ZIGZAG
     ;
 
 DICTIONARY
@@ -664,6 +664,9 @@ TS_2DIFF
     : T S '_' '2' D I F F
     ;
 
+ZIGZAG
+    : Z I G Z A G
+    ;
 
 // Compressor Type Keywords
 
diff --git a/client-cpp/src/main/Session.h b/client-cpp/src/main/Session.h
index 3a93a8e..c8b8326 100644
--- a/client-cpp/src/main/Session.h
+++ b/client-cpp/src/main/Session.h
@@ -143,7 +143,8 @@ namespace TSEncoding {
         BITMAP = (char) 5,
         GORILLA_V1 = (char) 6,
         REGULAR = (char) 7,
-        GORILLA = (char) 8
+        GORILLA = (char) 8,
+        ZIGZAG = (char) 9
     };
 }
 
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBEncodingIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBEncodingIT.java
index 65d30b1..c4a7bdc 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBEncodingIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBEncodingIT.java
@@ -40,6 +40,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 @Category({LocalStandaloneTest.class})
 public class IoTDBEncodingIT {
@@ -70,7 +71,7 @@ public class IoTDBEncodingIT {
                 Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
       statement.execute("CREATE TIMESERIES root.test1.s0 WITH DATATYPE=INT64,ENCODING=REGULAR");
-
+      fail();
     } catch (SQLException e) {
       assertEquals(303, e.getErrorCode());
     }
@@ -102,6 +103,7 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
     }
   }
 
@@ -130,6 +132,7 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
     }
   }
 
@@ -157,6 +160,7 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
     }
   }
 
@@ -184,6 +188,7 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
     }
   }
 
@@ -212,6 +217,7 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
     }
   }
 
@@ -240,6 +246,65 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
+    }
+  }
+
+  @Test
+  public void testSetTimeEncoderRegularAndValueEncoderZIGZAG() {
+    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.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=ZIGZAG");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(1,1100)");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(2,1200)");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(3,1300)");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(4,1400)");
+      statement.execute("flush");
+
+      int[] result = new int[] {1100, 1200, 1300, 1400};
+      try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) {
+        int index = 0;
+        while (resultSet.next()) {
+          int salary = resultSet.getInt("root.db_0.tab0.salary");
+          assertEquals(result[index], salary);
+          index++;
+        }
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail();
+    }
+  }
+
+  @Test
+  public void testSetTimeEncoderRegularAndValueEncoderZIGZAGOutofOrder() {
+    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.db_0.tab0.salary WITH DATATYPE=INT64,ENCODING=ZIGZAG");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(1,1200)");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(2,1100)");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(7,1000)");
+      statement.execute("insert into root.db_0.tab0(time,salary) values(4,2200)");
+      statement.execute("flush");
+
+      int[] result = new int[] {1200, 1100, 2200, 1000};
+      try (ResultSet resultSet = statement.executeQuery("select * from root.db_0.tab0")) {
+        int index = 0;
+        while (resultSet.next()) {
+          int salary = resultSet.getInt("root.db_0.tab0.salary");
+          assertEquals(result[index], salary);
+          index++;
+        }
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail();
     }
   }
 
@@ -268,6 +333,7 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
     }
   }
 
@@ -296,6 +362,7 @@ public class IoTDBEncodingIT {
       }
     } catch (Exception e) {
       e.printStackTrace();
+      fail();
     }
   }