|
17 | 17 |
|
18 | 18 | package org.apache.doris.catalog; |
19 | 19 |
|
| 20 | +import org.apache.doris.analysis.AlterViewStmt; |
20 | 21 | import org.apache.doris.analysis.CreateDbStmt; |
21 | 22 | import org.apache.doris.analysis.CreateTableStmt; |
22 | 23 | import org.apache.doris.analysis.CreateViewStmt; |
@@ -129,4 +130,22 @@ public void testNestedViews() throws Exception { |
129 | 130 | System.out.println(explainString); |
130 | 131 | Assert.assertTrue(explainString.contains("OlapScanNode")); |
131 | 132 | } |
| 133 | + |
| 134 | + @Test |
| 135 | + public void testAlterView() throws Exception { |
| 136 | + String originStmt = "select k1 as kc1, sum(k2) as kc2 from test.tbl1 group by kc1"; |
| 137 | + ExceptionChecker.expectThrowsNoException( |
| 138 | + () -> createView("create view test.alter1 as " + originStmt)); |
| 139 | + Database db = Catalog.getCurrentCatalog().getDbOrDdlException("default_cluster:test"); |
| 140 | + View alter1 = (View) db.getTableOrDdlException("alter1"); |
| 141 | + Assert.assertEquals("SELECT `k1` AS `kc1`, sum(`k2`) AS `kc2` FROM `default_cluster:test`.`tbl1` GROUP BY `kc1`", alter1.getInlineViewDef()); |
| 142 | + |
| 143 | + String alterStmt = "alter view test.alter1 as with test1_cte (w1, w2) as (select k1, k2 from test.tbl1) select w1 as c1, sum(w2) as c2 from test1_cte where w1 > 10 group by w1 order by w1"; |
| 144 | + AlterViewStmt alterViewStmt = (AlterViewStmt) UtFrameUtils.parseAndAnalyzeStmt(alterStmt, connectContext); |
| 145 | + Catalog.getCurrentCatalog().alterView(alterViewStmt); |
| 146 | + |
| 147 | + alter1 = (View) db.getTableOrDdlException("alter1"); |
| 148 | + System.out.println(alter1.getInlineViewDef()); |
| 149 | + Assert.assertEquals("WITH test1_cte(w1, w2) AS (SELECT `k1` AS `k1`, `k2` AS `k2` FROM `default_cluster:test`.`tbl1`) SELECT `w1` AS `c1`, sum(`w2`) AS `c2` FROM `test1_cte` WHERE `w1` > 10 GROUP BY `w1` ORDER BY `w1` ASC", alter1.getInlineViewDef()); |
| 150 | + } |
132 | 151 | } |
0 commit comments