Skip to content

Commit

Permalink
MOD: review
Browse files Browse the repository at this point in the history
  • Loading branch information
stalary committed May 8, 2022
1 parent 39ff708 commit 7068326
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
26 changes: 14 additions & 12 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2187,19 +2187,21 @@ private void handleShowCreateMaterializedView() throws AnalysisException {
ShowCreateMaterializedViewStmt showStmt = (ShowCreateMaterializedViewStmt) stmt;
Database db = Catalog.getCurrentCatalog().getDbOrAnalysisException(showStmt.getTableName().getDb());
Table table = db.getTableOrAnalysisException(showStmt.getTableName().getTbl());
OlapTable baseTable = ((OlapTable) table);
Long indexIdByName = baseTable.getIndexIdByName(showStmt.getMvName());
MaterializedIndexMeta meta = baseTable.getIndexMetaByIndexId(indexIdByName);
if (meta == null || meta.getDefineStmt() == null) {
resultSet = new ShowResultSet(showStmt.getMetaData(), resultRowSet);
return;
if (table instanceof OlapTable) {
OlapTable baseTable = ((OlapTable) table);
Long indexIdByName = baseTable.getIndexIdByName(showStmt.getMvName());
if (indexIdByName != null) {
MaterializedIndexMeta meta = baseTable.getIndexMetaByIndexId(indexIdByName);
if (meta != null && meta.getDefineStmt() != null) {
String originStmt = meta.getDefineStmt().originStmt;
List<String> data = new ArrayList<>();
data.add(showStmt.getTableName().getTbl());
data.add(showStmt.getMvName());
data.add(originStmt);
resultRowSet.add(data);
}
}
}
String originStmt = meta.getDefineStmt().originStmt;
List<String> data = new ArrayList<>();
data.add(showStmt.getTableName().getTbl());
data.add(showStmt.getMvName());
data.add(originStmt);
resultRowSet.add(data);
resultSet = new ShowResultSet(showStmt.getMetaData(), resultRowSet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

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;
Expand Down Expand Up @@ -72,4 +74,24 @@ public void testNormal() throws Exception {
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);

}
}

0 comments on commit 7068326

Please sign in to comment.