You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/06/28 02:42:43 UTC

[doris] branch master updated: [feature-wip](multi-catalog) get catalog name from TableName (#10435)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1f2bf39140 [feature-wip](multi-catalog) get catalog name from TableName (#10435)
1f2bf39140 is described below

commit 1f2bf3914034b798d9945fd2a4292b4f70ebb007
Author: Ashin Gau <As...@users.noreply.github.com>
AuthorDate: Tue Jun 28 10:42:37 2022 +0800

    [feature-wip](multi-catalog) get catalog name from TableName (#10435)
---
 fe/fe-core/src/main/cup/sql_parser.cup                       | 12 ++++++++++++
 .../src/main/java/org/apache/doris/analysis/TableName.java   |  4 ++++
 .../test/java/org/apache/doris/analysis/SwitchStmtTest.java  |  8 +++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup
index 0d562e1620..5268236f21 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -1977,6 +1977,10 @@ tbl_pattern ::=
     {:
         RESULT = new TablePattern(db, tbl);
     :}
+    | ident_or_star:ctl DOT ident_or_star:db DOT ident_or_star:tbl
+    {:
+        RESULT = new TablePattern(ctl, db, tbl);
+    :}
     ;
 
 resource_pattern ::=
@@ -4157,6 +4161,10 @@ star_expr ::=
     {:
         RESULT = SelectListItem.createStarItem(new TableName(db, tbl));
     :}
+    | ident:ctl DOT ident:db DOT ident:tbl DOT STAR
+    {:
+        RESULT = SelectListItem.createStarItem(new TableName(ctl, db, tbl));
+    :}
     ;
 
 opt_table_name ::=
@@ -4174,6 +4182,8 @@ table_name ::=
     {: RESULT = new TableName(null, tbl); :}
     | ident:db DOT ident:tbl
     {: RESULT = new TableName(db, tbl); :}
+    | ident:ctl DOT ident:db DOT ident:tbl
+    {: RESULT = new TableName(ctl, db, tbl); :}
     ;
 
 encryptkey_name ::=
@@ -5292,6 +5302,8 @@ column_ref ::=
   {: RESULT = new SlotRef(new TableName(null, tbl), col); :}
   | ident:db DOT ident:tbl DOT ident:col
   {: RESULT = new SlotRef(new TableName(db, tbl), col); :}
+  | ident:ctl DOT ident:db DOT ident:tbl DOT ident:col
+  {: RESULT = new SlotRef(new TableName(ctl, db, tbl), col); :}
   ;
 
 column_subscript ::=
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java
index 5e71b26c82..52b8651ec6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java
@@ -28,6 +28,7 @@ import org.apache.doris.common.ErrorReport;
 import org.apache.doris.common.FeMetaVersion;
 import org.apache.doris.common.io.Text;
 import org.apache.doris.common.io.Writable;
+import org.apache.doris.common.util.Util;
 import org.apache.doris.datasource.InternalDataSource;
 import org.apache.doris.persist.gson.GsonUtils;
 
@@ -76,6 +77,9 @@ public class TableName implements Writable {
                 ctl = InternalDataSource.INTERNAL_DS_NAME;
             }
         }
+        if (!ctl.equals(InternalDataSource.INTERNAL_DS_NAME)) {
+            Util.checkCatalogEnabled();
+        }
         if (Strings.isNullOrEmpty(db)) {
             db = analyzer.getDefaultDb();
             if (Strings.isNullOrEmpty(db)) {
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/SwitchStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/SwitchStmtTest.java
index d90a8a68d2..3a2ac9cf84 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/SwitchStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/SwitchStmtTest.java
@@ -65,11 +65,17 @@ public class SwitchStmtTest {
         GrantStmt grantRole1 = (GrantStmt) UtFrameUtils.parseAndAnalyzeStmt(
                 "grant grant_priv on tpch.* to role 'role1';", rootCtx);
         auth.grant(grantRole1);
+        // grant with ctl.db.tbl. grant can succeed even if the catalog does not exist
+        GrantStmt grantRole1WithCtl = (GrantStmt) UtFrameUtils.parseAndAnalyzeStmt(
+                "grant select_priv on testc.testdb.* to role 'role1';", rootCtx);
+        auth.grant(grantRole1WithCtl);
         // user1 can't switch to hive
         auth.createUser((CreateUserStmt) UtFrameUtils.parseAndAnalyzeStmt(
                 "create user 'user1'@'%' identified by 'pwd1' default role 'role1';", rootCtx));
         user1 = new UserIdentity("user1", "%");
         user1.analyze(clusterName);
+        // user1 has the privileges of testc which is granted by ctl.db.tbl format.
+        Assert.assertTrue(auth.getDbPrivTable().hasPrivsOfCatalog(user1, "testc"));
 
         // create catalog
         CreateCatalogStmt hiveCatalog = (CreateCatalogStmt) UtFrameUtils.parseAndAnalyzeStmt(
@@ -136,7 +142,7 @@ public class SwitchStmtTest {
         Assert.assertEquals(user1ShowResult.size(), 1);
         Assert.assertEquals(user1ShowResult.get(0).get(0), InternalDataSource.INTERNAL_DS_NAME);
 
-        // mock the login of user1
+        // mock the login of user2
         ConnectContext user2Ctx = UtFrameUtils.createDefaultCtx(user2, "127.0.0.1");
         ShowCatalogStmt user2Show = (ShowCatalogStmt) UtFrameUtils.parseAndAnalyzeStmt("show catalogs;", user2Ctx);
         List<List<String>> user2ShowResult = catalog.getDataSourceMgr().showCatalogs(user2Show).getResultRows();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org