iotdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject [iotdb] 01/02: support
Date Sun, 01 Nov 2020 01:44:56 GMT
This is an automated email from the ASF dual-hosted git repository.

hxd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 3215d5e36a15faa3773841cacf1a757334f20499
Author: LebronAl <TXYPotato@gmail.com>
AuthorDate: Wed Oct 28 11:13:12 2020 +0800

    support
---
 .../DDL Data Definition Language.md                |  4 +-
 docs/UserGuide/Operation Manual/SQL Reference.md   |  3 +-
 .../DDL Data Definition Language.md                |  4 +-
 .../zh/UserGuide/Operation Manual/SQL Reference.md |  3 +-
 .../org/apache/iotdb/db/engine/StorageEngine.java  |  1 -
 .../apache/iotdb/db/qp/executor/PlanExecutor.java  | 38 ++++++---
 .../db/integration/IoTDBDeleteStorageGroupIT.java  | 90 +++++++++++++++-------
 7 files changed, 98 insertions(+), 45 deletions(-)

diff --git a/docs/UserGuide/Operation Manual/DDL Data Definition Language.md b/docs/UserGuide/Operation
Manual/DDL Data Definition Language.md
index e83842e..f9c90d4 100644
--- a/docs/UserGuide/Operation Manual/DDL Data Definition Language.md	
+++ b/docs/UserGuide/Operation Manual/DDL Data Definition Language.md	
@@ -53,11 +53,13 @@ The result is as follows:
 
 ## Delete Storage Group
 
-User can delete a specified storage group by using [DELETE STORAGE GROUP](../Operation%20Manual/SQL%20Reference.md).
Please note the data in the storage group will also be deleted. 
+User can use the `DELETE STORAGE GROUP <PrefixPath>` statement to delete all storage
groups under the prefixPath. Please note the data in the storage group will also be deleted.

 
 ```
 IoTDB > DELETE STORAGE GROUP root.ln
 IoTDB > DELETE STORAGE GROUP root.sgcc
+// delete all data, all timeseries and all storage groups
+IoTDB > DELETE STORAGE GROUP root.*
 ```
 
 ## Create Timeseries
diff --git a/docs/UserGuide/Operation Manual/SQL Reference.md b/docs/UserGuide/Operation Manual/SQL
Reference.md
index b69b9b0..943910a 100644
--- a/docs/UserGuide/Operation Manual/SQL Reference.md	
+++ b/docs/UserGuide/Operation Manual/SQL Reference.md	
@@ -62,7 +62,8 @@ Note: FullPath can not include `*`
 DELETE STORAGE GROUP <FullPath> [COMMA <FullPath>]*
 Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.wt01
 Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.wt01, root.ln.wf01.wt02
-Note: FullPath can not include `*`
+Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.*
+Eg: IoTDB > DELETE STORAGE GROUP root.*
 ```
 
 * Create Timeseries Statement
diff --git a/docs/zh/UserGuide/Operation Manual/DDL Data Definition Language.md b/docs/zh/UserGuide/Operation
Manual/DDL Data Definition Language.md
index 607c73c..349e2f7 100644
--- a/docs/zh/UserGuide/Operation Manual/DDL Data Definition Language.md	
+++ b/docs/zh/UserGuide/Operation Manual/DDL Data Definition Language.md	
@@ -53,11 +53,13 @@ IoTDB> show storage group root.ln
 
 ## 删除存储组
 
-用户使用[DELETE STORAGE GROUP](../Operation%20Manual/SQL%20Reference.md)语句可以删除指定的存储组。在删除的过程中,需要注意的是存储组的数据也会被删除。
+用户可以使用`DELETE STORAGE GROUP <PrefixPath>`语句删除该前缀路径下所有的存储组。在删除的过程中,需要注意的是存储组的数据也会被删除。
 
 ```
 IoTDB > DELETE STORAGE GROUP root.ln
 IoTDB > DELETE STORAGE GROUP root.sgcc
+// 删除所有数据,时间序列以及存储组
+IoTDB > DELETE STORAGE GROUP root.*
 ```
 
 ## 创建时间序列
diff --git a/docs/zh/UserGuide/Operation Manual/SQL Reference.md b/docs/zh/UserGuide/Operation
Manual/SQL Reference.md
index 08afaaa..657b1a6 100644
--- a/docs/zh/UserGuide/Operation Manual/SQL Reference.md	
+++ b/docs/zh/UserGuide/Operation Manual/SQL Reference.md	
@@ -52,7 +52,8 @@ Note: FullPath can not include `*`
 DELETE STORAGE GROUP <FullPath> [COMMA <FullPath>]*
 Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.wt01
 Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.wt01, root.ln.wf01.wt02
-Note: FullPath can not include `*`
+Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.*
+Eg: IoTDB > DELETE STORAGE GROUP root.*
 ```
 
 * 创建时间序列语句
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
index 768f05e..9e1279e 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
@@ -21,7 +21,6 @@ package org.apache.iotdb.db.engine;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.ConcurrentModificationException;
 import java.util.HashMap;
 import java.util.List;
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index e8fbcbb..b05283f 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -149,6 +149,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PlanExecutor implements IPlanExecutor {
+
   // logger
   private static final Logger logger = LoggerFactory.getLogger(PlanExecutor.class);
 
@@ -724,7 +725,8 @@ public class PlanExecutor implements IPlanExecutor {
   @Override
   public void delete(DeletePlan deletePlan) throws QueryProcessException {
     for (PartialPath path : deletePlan.getPaths()) {
-      delete(path, deletePlan.getDeleteStartTime(), deletePlan.getDeleteEndTime(), deletePlan.getIndex());
+      delete(path, deletePlan.getDeleteStartTime(), deletePlan.getDeleteEndTime(),
+          deletePlan.getIndex());
     }
   }
 
@@ -894,7 +896,8 @@ public class PlanExecutor implements IPlanExecutor {
   }
 
   @Override
-  public void delete(PartialPath path, long startTime, long endTime, long planIndex) throws
QueryProcessException {
+  public void delete(PartialPath path, long startTime, long endTime, long planIndex)
+      throws QueryProcessException {
     try {
       if (!IoTDB.metaManager.isPathExist(path)) {
         throw new QueryProcessException(
@@ -1055,13 +1058,19 @@ public class PlanExecutor implements IPlanExecutor {
   private boolean createMultiTimeSeries(CreateMultiTimeSeriesPlan createMultiTimeSeriesPlan)
{
     Map<Integer, Exception> results = new HashMap<>(createMultiTimeSeriesPlan.getPaths().size());
     for (int i = 0; i < createMultiTimeSeriesPlan.getPaths().size(); i++) {
-      CreateTimeSeriesPlan plan = new CreateTimeSeriesPlan(createMultiTimeSeriesPlan.getPaths().get(i),
-        createMultiTimeSeriesPlan.getDataTypes().get(i), createMultiTimeSeriesPlan.getEncodings().get(i),
-        createMultiTimeSeriesPlan.getCompressors().get(i),
-        createMultiTimeSeriesPlan.getProps() == null ? null : createMultiTimeSeriesPlan.getProps().get(i),
-        createMultiTimeSeriesPlan.getTags() == null ? null : createMultiTimeSeriesPlan.getTags().get(i),
-        createMultiTimeSeriesPlan.getAttributes() == null ? null : createMultiTimeSeriesPlan.getAttributes().get(i),
-        createMultiTimeSeriesPlan.getAlias() == null ? null : createMultiTimeSeriesPlan.getAlias().get(i));
+      CreateTimeSeriesPlan plan = new CreateTimeSeriesPlan(
+          createMultiTimeSeriesPlan.getPaths().get(i),
+          createMultiTimeSeriesPlan.getDataTypes().get(i),
+          createMultiTimeSeriesPlan.getEncodings().get(i),
+          createMultiTimeSeriesPlan.getCompressors().get(i),
+          createMultiTimeSeriesPlan.getProps() == null ? null
+              : createMultiTimeSeriesPlan.getProps().get(i),
+          createMultiTimeSeriesPlan.getTags() == null ? null
+              : createMultiTimeSeriesPlan.getTags().get(i),
+          createMultiTimeSeriesPlan.getAttributes() == null ? null
+              : createMultiTimeSeriesPlan.getAttributes().get(i),
+          createMultiTimeSeriesPlan.getAlias() == null ? null
+              : createMultiTimeSeriesPlan.getAlias().get(i));
 
       try {
         createTimeSeries(plan);
@@ -1150,8 +1159,15 @@ public class PlanExecutor implements IPlanExecutor {
     List<PartialPath> deletePathList = new ArrayList<>();
     try {
       for (PartialPath storageGroupPath : deleteStorageGroupPlan.getPaths()) {
-        StorageEngine.getInstance().deleteStorageGroup(storageGroupPath);
-        deletePathList.add(storageGroupPath);
+        List<PartialPath> allRelatedStorageGroupPath = IoTDB.metaManager
+            .getStorageGroupPaths(storageGroupPath);
+        if (allRelatedStorageGroupPath.isEmpty()) {
+          throw new PathNotExistException(storageGroupPath.getFullPath());
+        }
+        for (PartialPath path : allRelatedStorageGroupPath) {
+          StorageEngine.getInstance().deleteStorageGroup(path);
+          deletePathList.add(path);
+        }
       }
       IoTDB.metaManager.deleteStorageGroups(deletePathList);
     } catch (MetadataException e) {
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeleteStorageGroupIT.java
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeleteStorageGroupIT.java
index 189fffd..d723c6d 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeleteStorageGroupIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeleteStorageGroupIT.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -80,42 +79,22 @@ public class IoTDBDeleteStorageGroupIT {
     }
   }
 
-  /**
-   * Star is not allowed in delete storage group statement
-   *
-   * @throws SQLException
-   * @throws ClassNotFoundException
-   */
-  @Test(expected = IoTDBSQLException.class)
-  public void testDeleteStorageGroupWithStar() throws Exception {
-    Class.forName(Config.JDBC_DRIVER_NAME);
-    try (Connection connection = DriverManager.
-            getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
-         Statement statement = connection.createStatement();) {
-      statement.execute("SET STORAGE GROUP TO root.ln1.wf01.wt01");
-      statement.execute("SET STORAGE GROUP TO root.ln1.wf01.wt02");
-      statement.execute("SET STORAGE GROUP TO root.ln1.wf02.wt03");
-      statement.execute("SET STORAGE GROUP TO root.ln1.wf02.wt04");
-      statement.execute("DELETE STORAGE GROUP root.ln1.wf02.*");
-    }
-  }
-
   @Test
   public void testDeleteMultipleStorageGroupWithQuote() throws Exception {
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection = DriverManager
             .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
          Statement statement = connection.createStatement();) {
-      statement.execute("SET STORAGE GROUP TO root.ln2.wf01.wt01");
-      statement.execute("SET STORAGE GROUP TO root.ln2.wf01.wt02");
-      statement.execute("SET STORAGE GROUP TO root.ln2.wf02.wt03");
-      statement.execute("SET STORAGE GROUP TO root.ln2.wf02.wt04");
-      statement.execute("DELETE STORAGE GROUP root.ln2.wf01.wt01, root.ln2.wf02.wt03");
+      statement.execute("SET STORAGE GROUP TO root.ln1.wf01.wt01");
+      statement.execute("SET STORAGE GROUP TO root.ln1.wf01.wt02");
+      statement.execute("SET STORAGE GROUP TO root.ln1.wf02.wt03");
+      statement.execute("SET STORAGE GROUP TO root.ln1.wf02.wt04");
+      statement.execute("DELETE STORAGE GROUP root.ln1.wf01.wt01, root.ln1.wf02.wt03");
       boolean hasResult = statement.execute("SHOW STORAGE GROUP");
       assertTrue(hasResult);
       String[] expected = new String[]{
-              "root.ln2.wf01.wt02",
-              "root.ln2.wf02.wt04"
+              "root.ln1.wf01.wt02",
+              "root.ln1.wf02.wt04"
       };
       List<String> expectedList = new ArrayList<>();
       Collections.addAll(expectedList, expected);
@@ -136,8 +115,61 @@ public class IoTDBDeleteStorageGroupIT {
     try (Connection connection = DriverManager.
             getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
          Statement statement = connection.createStatement();) {
+      statement.execute("SET STORAGE GROUP TO root.ln2.wf01.wt01");
+      statement.execute("DELETE STORAGE GROUP root.ln2.wf01.wt02");
+    }
+  }
+
+  @Test
+  public void testDeleteStorageGroupWithStar() throws Exception {
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    try (Connection connection = DriverManager.
+        getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement();) {
+      statement.execute("SET STORAGE GROUP TO root.ln3.wf01.wt01");
+      statement.execute("SET STORAGE GROUP TO root.ln3.wf01.wt02");
+      statement.execute("SET STORAGE GROUP TO root.ln3.wf02.wt03");
+      statement.execute("SET STORAGE GROUP TO root.ln3.wf02.wt04");
+      statement.execute("DELETE STORAGE GROUP root.ln3.wf02.*");
+      boolean hasResult = statement.execute("SHOW STORAGE GROUP");
+      assertTrue(hasResult);
+      String[] expected = new String[]{
+          "root.ln3.wf01.wt01",
+          "root.ln3.wf01.wt02"
+      };
+      List<String> expectedList = new ArrayList<>();
+      Collections.addAll(expectedList, expected);
+      List<String> result = new ArrayList<>();
+      try (ResultSet resultSet = statement.getResultSet()) {
+        while (resultSet.next()) {
+          result.add(resultSet.getString(1));
+        }
+      }
+      assertEquals(expected.length, result.size());
+      assertTrue(expectedList.containsAll(result));
+    }
+  }
+
+  @Test
+  public void testDeleteAllStorageGroups() throws Exception {
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    try (Connection connection = DriverManager.
+        getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement();) {
       statement.execute("SET STORAGE GROUP TO root.ln4.wf01.wt01");
-      statement.execute("DELETE STORAGE GROUP root.ln4.wf01.wt02");
+      statement.execute("SET STORAGE GROUP TO root.ln4.wf01.wt02");
+      statement.execute("SET STORAGE GROUP TO root.ln4.wf02.wt03");
+      statement.execute("SET STORAGE GROUP TO root.ln4.wf02.wt04");
+      statement.execute("DELETE STORAGE GROUP root.*");
+      boolean hasResult = statement.execute("SHOW STORAGE GROUP");
+      assertTrue(hasResult);
+      List<String> result = new ArrayList<>();
+      try (ResultSet resultSet = statement.getResultSet()) {
+        while (resultSet.next()) {
+          result.add(resultSet.getString(1));
+        }
+      }
+      assertEquals(0, result.size());
     }
   }
 }


Mime
View raw message