|
17 | 17 |
|
18 | 18 | package org.apache.doris.catalog; |
19 | 19 |
|
| 20 | +import org.apache.doris.catalog.stream.OlapTableStream; |
20 | 21 | import org.apache.doris.common.Config; |
21 | 22 | import org.apache.doris.common.DdlException; |
22 | 23 | import org.apache.doris.common.ExceptionChecker; |
|
25 | 26 | import org.apache.doris.nereids.trees.plans.commands.DropStreamCommand; |
26 | 27 | import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; |
27 | 28 | import org.apache.doris.qe.StmtExecutor; |
| 29 | +import org.apache.doris.thrift.TRow; |
28 | 30 | import org.apache.doris.utframe.TestWithFeService; |
29 | 31 |
|
30 | 32 | import org.junit.jupiter.api.Assertions; |
31 | 33 | import org.junit.jupiter.api.Test; |
32 | 34 |
|
| 35 | +import java.util.ArrayList; |
| 36 | +import java.util.List; |
| 37 | + |
33 | 38 | public class DropTableStreamTest extends TestWithFeService { |
34 | 39 |
|
35 | 40 | @Override |
@@ -67,6 +72,33 @@ private void dropStream(String sql) throws Exception { |
67 | 72 | } |
68 | 73 | } |
69 | 74 |
|
| 75 | + private void createBaseTableAndStream(String tableName, String streamName) throws Exception { |
| 76 | + createTable("create table test_stream." + tableName + " (k1 int, k2 int) " |
| 77 | + + "unique key(k1) distributed by hash(k1) buckets 1 " |
| 78 | + + "properties('replication_num' = '1', 'binlog.enable' = 'true', 'binlog.format' = 'ROW', " |
| 79 | + + "'binlog.need_historical_value' = 'true')"); |
| 80 | + createTable("create stream test_stream." + streamName + " on table test_stream." + tableName |
| 81 | + + " properties('show_initial_rows' = 'true')"); |
| 82 | + } |
| 83 | + |
| 84 | + private TRow getStreamMetadataRow(String streamName) { |
| 85 | + List<TRow> rows = new ArrayList<>(); |
| 86 | + Env.getCurrentEnv().getTableStreamManager().fillTableStreamValuesMetadataResult(rows); |
| 87 | + return rows.stream() |
| 88 | + .filter(row -> streamName.equals(row.getColumnValue().get(1).getStringVal())) |
| 89 | + .findFirst() |
| 90 | + .orElseThrow(AssertionError::new); |
| 91 | + } |
| 92 | + |
| 93 | + private void assertStreamMetadataState(String streamName, String baseTableType, |
| 94 | + boolean enabled, boolean stale, String staleReason) { |
| 95 | + TRow row = getStreamMetadataRow(streamName); |
| 96 | + Assertions.assertEquals(baseTableType, row.getColumnValue().get(9).getStringVal()); |
| 97 | + Assertions.assertEquals(enabled, row.getColumnValue().get(10).isBoolVal()); |
| 98 | + Assertions.assertEquals(stale, row.getColumnValue().get(11).isBoolVal()); |
| 99 | + Assertions.assertEquals(staleReason, row.getColumnValue().get(12).getStringVal()); |
| 100 | + } |
| 101 | + |
70 | 102 | @Test |
71 | 103 | public void testNormalDropStream() throws Exception { |
72 | 104 | // test drop |
@@ -104,6 +136,43 @@ public void testCloudDropRequiresForce() { |
104 | 136 | } |
105 | 137 | } |
106 | 138 |
|
| 139 | + @Test |
| 140 | + public void testStreamMetadataFollowsRecoverableBaseTable() throws Exception { |
| 141 | + createBaseTableAndStream("tbl_recover", "s_recover"); |
| 142 | + Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("test_stream"); |
| 143 | + long baseTableId = db.getTableOrMetaException("tbl_recover").getId(); |
| 144 | + |
| 145 | + assertStreamMetadataState("s_recover", "OLAP", true, false, "N/A"); |
| 146 | + |
| 147 | + dropTableWithSql("drop table test_stream.tbl_recover"); |
| 148 | + assertStreamMetadataState("s_recover", "N/A", false, true, "Base table does not exist"); |
| 149 | + |
| 150 | + recoverTable("recover table test_stream.tbl_recover"); |
| 151 | + Assertions.assertEquals(baseTableId, db.getTableOrMetaException("tbl_recover").getId()); |
| 152 | + assertStreamMetadataState("s_recover", "OLAP", true, false, "N/A"); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void testStreamMetadataRejectsSameNameBaseTable() throws Exception { |
| 157 | + createBaseTableAndStream("tbl_force", "s_force"); |
| 158 | + Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("test_stream"); |
| 159 | + long oldBaseTableId = db.getTableOrMetaException("tbl_force").getId(); |
| 160 | + OlapTableStream stream = (OlapTableStream) db.getTableOrMetaException("s_force"); |
| 161 | + |
| 162 | + dropTableWithSql("drop table test_stream.tbl_force force"); |
| 163 | + Assertions.assertNull(stream.getBaseTableNullable()); |
| 164 | + assertStreamMetadataState("s_force", "N/A", false, true, "Base table does not exist"); |
| 165 | + |
| 166 | + createTable("create table test_stream.tbl_force (k1 int, k2 int) " |
| 167 | + + "unique key(k1) distributed by hash(k1) buckets 1 " |
| 168 | + + "properties('replication_num' = '1', 'binlog.enable' = 'true', 'binlog.format' = 'ROW', " |
| 169 | + + "'binlog.need_historical_value' = 'true')"); |
| 170 | + |
| 171 | + Assertions.assertNotEquals(oldBaseTableId, db.getTableOrMetaException("tbl_force").getId()); |
| 172 | + Assertions.assertNull(stream.getBaseTableNullable()); |
| 173 | + assertStreamMetadataState("s_force", "N/A", false, true, "Base table does not exist"); |
| 174 | + } |
| 175 | + |
107 | 176 | @Override |
108 | 177 | protected void runAfterAll() throws Exception { |
109 | 178 | dropDatabase("test_stream"); |
|
0 commit comments