You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/12/29 06:06:28 UTC

[iotdb] branch IOTDB-5217 created (now efc84bff71)

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

jackietien pushed a change to branch IOTDB-5217
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at efc84bff71 format code

This branch includes the following new commits:

     new efc84bff71 format code

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/01: format code

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch IOTDB-5217
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit efc84bff71c3858e3c9fd0397b2713aaa8ef387d
Author: JackieTien97 <ja...@gmail.com>
AuthorDate: Thu Dec 29 14:06:14 2022 +0800

    format code
---
 .../antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4  |  6 +-
 .../java/org/apache/iotdb/db/it/cq/IoTDBCQIT.java  | 88 ++++++++++++++++++++++
 .../iotdb/commons/auth/entity/PrivilegeType.java   |  3 +-
 .../org/apache/iotdb/db/auth/AuthorityChecker.java |  2 +
 4 files changed, 97 insertions(+), 2 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 94a5dc88cf..73cdfe0a69 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
@@ -744,7 +744,7 @@ PRIVILEGE_VALUE
     | GRANT_USER_PRIVILEGE | REVOKE_USER_PRIVILEGE | GRANT_USER_ROLE | REVOKE_USER_ROLE
     | CREATE_ROLE | DELETE_ROLE | LIST_ROLE | GRANT_ROLE_PRIVILEGE | REVOKE_ROLE_PRIVILEGE
     | CREATE_FUNCTION | DROP_FUNCTION | CREATE_TRIGGER | DROP_TRIGGER | START_TRIGGER | STOP_TRIGGER
-    | CREATE_CONTINUOUS_QUERY | DROP_CONTINUOUS_QUERY
+    | CREATE_CONTINUOUS_QUERY | DROP_CONTINUOUS_QUERY | SHOW_CONTINUOUS_QUERIES
     | APPLY_TEMPLATE | UPDATE_TEMPLATE | READ_TEMPLATE | READ_TEMPLATE_APPLICATION
     ;
 
@@ -868,6 +868,10 @@ DROP_CONTINUOUS_QUERY
     : D R O P '_' C O N T I N U O U S '_' Q U E R Y
     ;
 
+SHOW_CONTINUOUS_QUERIES
+    : S H O W '_' C O N T I N U O U S '_' Q U E R I E S
+    ;
+
 SCHEMA_REPLICATION_FACTOR
     : S C H E M A '_' R E P L I C A T I O N '_' F A C T O R
     ;
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/cq/IoTDBCQIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/cq/IoTDBCQIT.java
index 3a520e5a71..b03ddec6f1 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/cq/IoTDBCQIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/cq/IoTDBCQIT.java
@@ -481,6 +481,94 @@ public class IoTDBCQIT {
     }
   }
 
+  @Test
+  public void testShowAuth() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+
+      String[] cqIds = {"show_cq_1", "show_cq_2", "show_cq_3", "show_cq_4"};
+      String[] cqSQLs = {
+        "CREATE CQ show_cq_1 \n"
+            + "RESAMPLE \n"
+            + "  EVERY 30m\n"
+            + "  BOUNDARY 0\n"
+            + "  RANGE 30m, 10m\n"
+            + "TIMEOUT POLICY BLOCKED\n"
+            + "BEGIN \n"
+            + "  SELECT count(s1)  \n"
+            + "    INTO root.sg_count.d(count_s1)\n"
+            + "    FROM root.sg.d\n"
+            + "    GROUP BY(30m)\n"
+            + "END",
+        "CREATE CQ show_cq_2\n"
+            + "BEGIN \n"
+            + "  SELECT count(s1)  \n"
+            + "    INTO root.sg_count.d(count_s1)\n"
+            + "    FROM root.sg.d\n"
+            + "    GROUP BY(30m)\n"
+            + "END",
+        "CREATE CQ show_cq_3\n"
+            + "RESAMPLE RANGE 30m, 0m\n"
+            + "TIMEOUT POLICY DISCARD\n"
+            + "BEGIN \n"
+            + "  SELECT count(s1)  \n"
+            + "    INTO root.sg_count.d(count_s1)\n"
+            + "    FROM root.sg.d\n"
+            + "    GROUP BY(10m)\n"
+            + "END",
+        "CREATE CQ show_cq_4\n"
+            + "RESAMPLE EVERY 30m \n"
+            + "TIMEOUT POLICY DISCARD\n"
+            + "BEGIN \n"
+            + "  SELECT count(s1)  \n"
+            + "    INTO root.sg_count.d(count_s1)\n"
+            + "    FROM root.sg.d\n"
+            + "    GROUP BY(10m)\n"
+            + "END"
+      };
+
+      for (String sql : cqSQLs) {
+        statement.execute(sql);
+      }
+
+      statement.execute("CREATE USER `zmty` 'zmty'");
+
+      try (Connection connection2 = EnvFactory.getEnv().getConnection("zmty", "zmty");
+          Statement statement2 = connection2.createStatement()) {
+        try {
+          statement2.executeQuery("show CQS");
+          fail();
+        } catch (Exception e) {
+          assertEquals(
+              TSStatusCode.NO_PERMISSION.getStatusCode()
+                  + ": No permissions for this operation, please add privilege SHOW_CONTINUOUS_QUERIES",
+              e.getMessage());
+        }
+
+        statement.execute("GRANT USER `zmty` PRIVILEGES SHOW_CONTINUOUS_QUERIES");
+
+        try (ResultSet resultSet = statement2.executeQuery("show CQS")) {
+
+          int cnt = 0;
+          while (resultSet.next()) {
+            // No need to add time column for aggregation query
+            assertEquals(cqIds[cnt], resultSet.getString(1));
+            assertEquals(cqSQLs[cnt], resultSet.getString(2));
+            assertEquals("ACTIVE", resultSet.getString(3));
+            cnt++;
+          }
+          assertEquals(cqIds.length, cnt);
+        }
+      }
+
+      for (String cqId : cqIds) {
+        statement.execute(String.format("DROP CQ %s;", cqId));
+      }
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+  }
+
   // =======================================drop cq======================================
   @Test
   public void testDropCQ() {
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java b/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java
index 886d98d80b..36c2ecadca 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/PrivilegeType.java
@@ -55,7 +55,8 @@ public enum PrivilegeType {
   UPDATE_TEMPLATE,
   READ_TEMPLATE,
   APPLY_TEMPLATE(true),
-  READ_TEMPLATE_APPLICATION;
+  READ_TEMPLATE_APPLICATION,
+  SHOW_CONTINUOUS_QUERIES;
 
   private static final int PRIVILEGE_COUNT = values().length;
 
diff --git a/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java b/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java
index d240b3e545..99e9fbbbb1 100644
--- a/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java
+++ b/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java
@@ -229,6 +229,8 @@ public class AuthorityChecker {
       case SHOW_PATH_SET_SCHEMA_TEMPLATE:
       case SHOW_PATH_USING_SCHEMA_TEMPLATE:
         return PrivilegeType.READ_TEMPLATE_APPLICATION.ordinal();
+      case SHOW_CONTINUOUS_QUERIES:
+        return PrivilegeType.SHOW_CONTINUOUS_QUERIES.ordinal();
       default:
         logger.error("Unrecognizable operator type ({}) for AuthorityChecker.", type);
         return -1;