You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by do...@apache.org on 2019/05/30 09:43:57 UTC

[incubator-iotdb] branch watermark-demo updated: add grant/revoke data auth sql support

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

dope pushed a commit to branch watermark-demo
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/watermark-demo by this push:
     new b890ca1  add grant/revoke data auth sql support
b890ca1 is described below

commit b890ca11b428dc13de42331eb83c8d86dedc6d44
Author: XuYi <xu...@126.com>
AuthorDate: Thu May 30 17:43:43 2019 +0800

    add grant/revoke data auth sql support
---
 .../antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g |  2 ++
 .../org/apache/iotdb/db/sql/parse/TSParser.g       | 14 ++++++++++
 .../org/apache/iotdb/db/sql/SQLParserTest.java     | 31 ++++++++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g b/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g
index f95bc92..77b3859 100644
--- a/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g
+++ b/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g
@@ -46,6 +46,8 @@ KW_OR : 'OR' | '|' | '||';
 KW_NOT : 'NOT' | '!';
 
 
+KW_DATA_AHTH : 'DATA_AUTHORITY';
+
 KW_ORDER : 'ORDER';
 KW_GROUP : 'GROUP';
 KW_FILL : 'FILL';
diff --git a/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g b/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g
index b9a5bd0..2c6813c 100644
--- a/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g
+++ b/iotdb/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g
@@ -78,6 +78,8 @@ TOK_SLIMIT;
 TOK_SOFFSET;
 TOK_LIMIT;
 
+TOK_GRANT_DATA_AUTH;
+TOK_REVOKE_DATA_AUTH;
 /*
   BELOW IS THE METADATA TOKEN
 */
@@ -499,6 +501,8 @@ authorStatement
     | revokeRole
     | grantRoleToUser
     | revokeRoleFromUser
+    | grantDataAuth
+    | revokeDataAuth
     ;
 
 loadStatement
@@ -528,6 +532,16 @@ dropRole
     -> ^(TOK_DROP ^(TOK_ROLE $roleName))
     ;
 
+grantDataAuth
+    : KW_GRANT KW_DATA_AHTH KW_TO Identifier (COMMA Identifier)*
+    -> ^(TOK_GRANT_DATA_AUTH Identifier+)
+    ;
+
+revokeDataAuth
+    : KW_REVOKE KW_DATA_AHTH KW_FROM Identifier (COMMA Identifier)*
+    -> ^(TOK_REVOKE_DATA_AUTH Identifier+)
+    ;
+
 grantUser
     : KW_GRANT KW_USER userName = Identifier privileges KW_ON prefixPath
     -> ^(TOK_GRANT ^(TOK_USER $userName) privileges prefixPath)
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/sql/SQLParserTest.java b/iotdb/src/test/java/org/apache/iotdb/db/sql/SQLParserTest.java
index 03a09db..748cb97 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/sql/SQLParserTest.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/sql/SQLParserTest.java
@@ -1484,6 +1484,37 @@ public class SQLParserTest {
     }
   }
 
+
+  @Test
+  public void grantDataAuth() throws ParseException, RecognitionException {
+    ArrayList<String> ans = new ArrayList<>(Arrays.asList("TOK_GRANT_DATA_AUTH", "a", "b"));
+    ArrayList<String> rec = new ArrayList<>();
+    AstNode astTree = ParseGenerator.generateAST("GRANT DATA_AUTHORITY to a,b");
+    astTree = ParseUtils.findRootNonNullToken(astTree);
+    recursivePrintSon(astTree, rec);
+
+    int i = 0;
+    while (i <= rec.size() - 1) {
+      assertEquals(rec.get(i), ans.get(i));
+      i++;
+    }
+  }
+
+  @Test
+  public void revokeDataAuth() throws ParseException, RecognitionException {
+    ArrayList<String> ans = new ArrayList<>(Arrays.asList("TOK_REVOKE_DATA_AUTH", "a", "b"));
+    ArrayList<String> rec = new ArrayList<>();
+    AstNode astTree = ParseGenerator.generateAST("revoke data_authority from a,b");
+    astTree = ParseUtils.findRootNonNullToken(astTree);
+    recursivePrintSon(astTree, rec);
+
+    int i = 0;
+    while (i <= rec.size() - 1) {
+      assertEquals(rec.get(i), ans.get(i));
+      i++;
+    }
+  }
+
   public void recursivePrintSon(Node ns, ArrayList<String> rec) {
     rec.add(ns.toString());
     if (ns.getChildren() != null) {