-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Stalary <[email protected]>
- Loading branch information
Showing
8 changed files
with
251 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCreateMaterializedViewStmt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// 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.ScalarType; | ||
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 lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
/** | ||
* SHOW CREATE MATERIALIZED VIEW mv_name ON table_name. | ||
**/ | ||
@AllArgsConstructor | ||
@Getter | ||
public class ShowCreateMaterializedViewStmt extends ShowStmt { | ||
|
||
private static final ShowResultSetMetaData META_DATA = | ||
ShowResultSetMetaData.builder() | ||
.addColumn(new Column("TableName", ScalarType.createVarchar(255))) | ||
.addColumn(new Column("ViewName", ScalarType.createVarchar(255))) | ||
.addColumn(new Column("CreateStmt", ScalarType.createVarchar(65535))) | ||
.build(); | ||
|
||
private String mvName; | ||
|
||
private TableName tableName; | ||
|
||
@Override | ||
public void analyze(Analyzer analyzer) throws UserException { | ||
super.analyze(analyzer); | ||
tableName.analyze(analyzer); | ||
if (!Catalog.getCurrentCatalog().getAuth() | ||
.checkTblPriv(ConnectContext.get(), tableName.getDb(), tableName.getTbl(), PrivPredicate.SHOW)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "SHOW CREATE MATERIALIZED", | ||
ConnectContext.get().getQualifiedUser(), | ||
ConnectContext.get().getRemoteIP(), | ||
tableName.toSql()); | ||
} | ||
} | ||
|
||
@Override | ||
public ShowResultSetMetaData getMetaData() { | ||
return META_DATA; | ||
} | ||
|
||
@Override | ||
public String toSql() { | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
stringBuilder.append("SHOW CREATE MATERIALIZED VIEW "); | ||
stringBuilder.append("`").append(mvName).append("` "); | ||
stringBuilder.append("ON ").append(tableName.toSql()); | ||
return stringBuilder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
fe/fe-core/src/test/java/org/apache/doris/analysis/ShowCreateMaterializedViewStmtTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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.common.AnalysisException; | ||
import org.apache.doris.common.ExceptionChecker; | ||
import org.apache.doris.qe.ConnectContext; | ||
import org.apache.doris.qe.ShowExecutor; | ||
import org.apache.doris.utframe.DorisAssert; | ||
import org.apache.doris.utframe.UtFrameUtils; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.util.UUID; | ||
|
||
/** | ||
* test for ShowCreateMaterializedViewStmt. | ||
**/ | ||
public class ShowCreateMaterializedViewStmtTest { | ||
|
||
private static String runningDir = "fe/mocked/ShowCreateMaterializedViewStmtTest/" + UUID.randomUUID() + "/"; | ||
|
||
private static ConnectContext connectContext; | ||
|
||
private static DorisAssert dorisAssert; | ||
|
||
/** | ||
* init. | ||
**/ | ||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
UtFrameUtils.createDorisCluster(runningDir); | ||
|
||
// create connect context | ||
connectContext = UtFrameUtils.createDefaultCtx(); | ||
dorisAssert = new DorisAssert(connectContext); | ||
dorisAssert.withDatabase("test") | ||
.withTable("create table test.table1 (k1 int, k2 int) distributed by hash(k1) " | ||
+ "buckets 1 properties(\"replication_num\" = \"1\");") | ||
.withMaterializedView("CREATE MATERIALIZED VIEW test_mv as select k1 from test.table1;"); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
File file = new File(runningDir); | ||
file.delete(); | ||
} | ||
|
||
@Test | ||
public void testNormal() throws Exception { | ||
String showMvSql = "SHOW CREATE MATERIALIZED VIEW test_mv on test.table1;"; | ||
ShowCreateMaterializedViewStmt showStmt = | ||
(ShowCreateMaterializedViewStmt) UtFrameUtils.parseAndAnalyzeStmt(showMvSql, connectContext); | ||
ShowExecutor executor = new ShowExecutor(connectContext, showStmt); | ||
Assert.assertEquals(executor.execute().getResultRows().get(0).get(2), | ||
"CREATE MATERIALIZED VIEW test_mv as select k1 from test.table1;"); | ||
} | ||
|
||
@Test | ||
public void testNoView() throws Exception { | ||
String showMvSql = "SHOW CREATE MATERIALIZED VIEW test_mv_empty on test.table1;"; | ||
ShowCreateMaterializedViewStmt showStmt = | ||
(ShowCreateMaterializedViewStmt) UtFrameUtils.parseAndAnalyzeStmt(showMvSql, connectContext); | ||
ShowExecutor executor = new ShowExecutor(connectContext, showStmt); | ||
Assert.assertTrue(executor.execute().getResultRows().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testNoTable() throws Exception { | ||
String showMvSql = "SHOW CREATE MATERIALIZED VIEW test_mv on test.table1_error;"; | ||
ShowCreateMaterializedViewStmt showStmt = | ||
(ShowCreateMaterializedViewStmt) UtFrameUtils.parseAndAnalyzeStmt(showMvSql, connectContext); | ||
ShowExecutor executor = new ShowExecutor(connectContext, showStmt); | ||
ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, | ||
"Unknown table 'table1_error' in default_cluster:test", executor::execute); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters