You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/05/13 22:42:38 UTC

[GitHub] [incubator-doris] xy720 opened a new pull request #5813: [Feature] Support show view statement for table

xy720 opened a new pull request #5813:
URL: https://github.com/apache/incubator-doris/pull/5813


   ## Proposed changes
   
   issue #5812 
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [x] New feature (non-breaking change which adds functionality)
   - [x] Documentation Update (if none of the other choices apply)
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [x] I have created an issue on (Fix #5812 ) and described the bug/feature there in detail
   - [x] Compiling and unit tests pass locally with my changes
   - [x] I have added tests that prove my fix is effective or that my feature works
   - [x] If these changes need document changes, I have updated the document
   - [x] Any dependent changes have been merged
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-doris] xy720 commented on a change in pull request #5813: [Feature] Support show view statement for table

Posted by GitBox <gi...@apache.org>.
xy720 commented on a change in pull request #5813:
URL: https://github.com/apache/incubator-doris/pull/5813#discussion_r634223848



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/ShowViewStmt.java
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.View;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.UserException;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSetMetaData;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+// Show view statement, used to show view information of one table.
+//
+// Syntax:
+//      SHOW VIEW { FROM | IN } table [ FROM db ]
+public class ShowViewStmt extends ShowStmt {
+    private static final ShowResultSetMetaData META_DATA =
+            ShowResultSetMetaData.builder()
+                    .addColumn(new Column("View", ScalarType.createVarchar(30)))
+                    .addColumn(new Column("Create View", ScalarType.createVarchar(65535)))
+                    .build();
+
+    private String db;
+    private TableName tbl;
+
+    private List<View> matchViews = Lists.newArrayList();;
+
+    public ShowViewStmt(String db, TableName tbl) {
+        this.db = db;
+        this.tbl = tbl;
+    }
+
+    public String getDb() {
+        return tbl.getDb();
+    }
+
+    public String getTbl() {
+        return tbl.getTbl();
+    }
+
+    public List<View> getMatchViews() {
+        return matchViews;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
+        super.analyze(analyzer);
+        if (tbl == null) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_TABLES_USED);
+        }
+        if (!Strings.isNullOrEmpty(db)) {
+            // if user specify the `from db`, overwrite the db in `tbl` with this db.
+            // for example:
+            //      show view from db1.tbl1 from db2;
+            // will be rewrote to:
+            //      show view from db2.tbl1;
+            // this act same as in MySQL
+            tbl.setDb(db);
+        }
+        tbl.analyze(analyzer);
+
+        String dbName = tbl.getDb();
+        Database database = Catalog.getCurrentCatalog().getDb(dbName);
+        if (database == null) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_DB_ERROR, dbName);
+        }
+        Table showTable = database.getTable(tbl.getTbl());
+        if (showTable == null) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_TABLE_ERROR, getTbl());
+        }
+        if (!(showTable instanceof OlapTable)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_NOT_OLAP_TABLE, getTbl());
+        }
+
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ConnectContext.get(), dbName, getTbl(), PrivPredicate.SHOW)) {

Review comment:
       ok. I have fixed it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-doris] morningman merged pull request #5813: [Feature] Support show view statement for table

Posted by GitBox <gi...@apache.org>.
morningman merged pull request #5813:
URL: https://github.com/apache/incubator-doris/pull/5813


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-doris] morningman commented on a change in pull request #5813: [Feature] Support show view statement for table

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #5813:
URL: https://github.com/apache/incubator-doris/pull/5813#discussion_r632353733



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/ShowViewStmt.java
##########
@@ -0,0 +1,146 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.View;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.UserException;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSetMetaData;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+// Show view statement, used to show view information of one table.
+//
+// Syntax:
+//      SHOW VIEW { FROM | IN } table [ FROM db ]
+public class ShowViewStmt extends ShowStmt {
+    private static final ShowResultSetMetaData META_DATA =
+            ShowResultSetMetaData.builder()
+                    .addColumn(new Column("View", ScalarType.createVarchar(30)))
+                    .addColumn(new Column("Create View", ScalarType.createVarchar(65535)))
+                    .build();
+
+    private String db;
+    private TableName tbl;
+
+    private List<View> matchViews = Lists.newArrayList();;
+
+    public ShowViewStmt(String db, TableName tbl) {
+        this.db = db;
+        this.tbl = tbl;
+    }
+
+    public String getDb() {
+        return tbl.getDb();
+    }
+
+    public String getTbl() {
+        return tbl.getTbl();
+    }
+
+    public List<View> getMatchViews() {
+        return matchViews;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
+        super.analyze(analyzer);
+        if (tbl == null) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_TABLES_USED);
+        }
+        if (!Strings.isNullOrEmpty(db)) {
+            // if user specify the `from db`, overwrite the db in `tbl` with this db.
+            // for example:
+            //      show view from db1.tbl1 from db2;
+            // will be rewrote to:
+            //      show view from db2.tbl1;
+            // this act same as in MySQL
+            tbl.setDb(db);
+        }
+        tbl.analyze(analyzer);
+
+        String dbName = tbl.getDb();
+        Database database = Catalog.getCurrentCatalog().getDb(dbName);
+        if (database == null) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_DB_ERROR, dbName);
+        }
+        Table showTable = database.getTable(tbl.getTbl());
+        if (showTable == null) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_TABLE_ERROR, getTbl());
+        }
+        if (!(showTable instanceof OlapTable)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_NOT_OLAP_TABLE, getTbl());
+        }
+
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ConnectContext.get(), dbName, getTbl(), PrivPredicate.SHOW)) {

Review comment:
       Check priv before check db/tbl's existence




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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