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: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
