Skip to content

Commit

Permalink
[fix](table) Supply rollup for get ddl for sync (#47732)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyxxxcat authored Feb 12, 2025
1 parent 44b50e1 commit 625db3e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -3978,6 +3978,36 @@ public static void getDdlStmt(DdlStmt ddlStmt, String dbName, TableIf table, Lis
index++;
}
}
// with all rollup
if (getDdlForSync) {
sb.append("\nROLLUP (\n");
List<Long> indexIds = new ArrayList<>(olapTable.getIndexIdToMeta().keySet());
for (int i = 0; i < indexIds.size(); i++) {
Long indexId = indexIds.get(i);
if (indexId == olapTable.getBaseIndexId()) {
continue;
}

MaterializedIndexMeta materializedIndexMeta = olapTable.getIndexIdToMeta().get(indexId);
String indexName = olapTable.getIndexNameById(indexId);
sb.append(indexName).append(" (");

List<Column> indexSchema = materializedIndexMeta.getSchema();
for (int j = 0; j < indexSchema.size(); j++) {
Column column = indexSchema.get(j);
sb.append(column.getName());
if (j != indexSchema.size() - 1) {
sb.append(", ");
}
}
sb.append(")");

if (i != indexIds.size() - 1) {
sb.append(",\n");
}
}
sb.append("\n)");
}

// properties
sb.append("\nPROPERTIES (\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,42 @@ public void testAbnormal() {
() -> checkCreateOlapTableLike(createTableWithRollup, createTableLikeWithRollupSq3, newDbName3,
existedDbName3, newTblName3, existedTblName3, 1));
}

@Test
public void checkSyncedTableWithRollup() throws Exception {
String createTableWithRollup = "CREATE TABLE IF NOT EXISTS test.table_with_rollup_synced\n" + "(\n"
+ " event_day DATE,\n"
+ " siteid INT DEFAULT '10',\n" + " citycode SMALLINT,\n"
+ " username VARCHAR(32) DEFAULT '',\n" + " pv BIGINT SUM DEFAULT '0'\n" + ")\n"
+ "AGGREGATE KEY(event_day, siteid, citycode, username)\n"
+ "PARTITION BY RANGE(event_day)\n"
+ "(\n" + " PARTITION p201706 VALUES LESS THAN ('2021-07-01'),\n"
+ " PARTITION p201707 VALUES LESS THAN ('2021-08-01'),\n"
+ " PARTITION p201708 VALUES LESS THAN ('2021-09-01')\n" + ")\n"
+ "DISTRIBUTED BY HASH(siteid) BUCKETS 10\n" + "ROLLUP\n" + "(\n" + "r(event_day,pv),\n"
+ "r1(event_day,siteid,pv),\n" + "r2(siteid,pv),\n" + "r3(siteid,citycode,username,pv)\n"
+ ")\n" + "PROPERTIES(\"replication_num\" = \"1\");";

String createTableLikeWithRollupSql = "create table test.table_like_rollup2"
+ " like test.table_with_rollup_synced with rollup";

String existedDbName = "test";
String existedTblName = "table_with_rollup_synced";

createTable(createTableWithRollup);
createTableLike(createTableLikeWithRollupSql);

Database existedDb = Env.getCurrentInternalCatalog()
.getDbOrDdlException(existedDbName);
OlapTable existedTbl = (OlapTable) existedDb.getTableOrDdlException(existedTblName);
List<String> existedTableStmt = Lists.newArrayList();
List<String> existedAddRollupStmt = Lists.newArrayList();
Env.getSyncedDdlStmt(existedTbl, existedTableStmt, null, existedAddRollupStmt, false, true,
-1L);

Assert.assertTrue(existedTableStmt.toString().contains("r1 (event_day, siteid, pv)"));
Assert.assertTrue(existedTableStmt.toString().contains("r3 (siteid, citycode, username, pv)"));
Assert.assertTrue(existedTableStmt.toString().contains("r (event_day, pv)"));
Assert.assertTrue(existedTableStmt.toString().contains("r2 (siteid, pv)"));
}
}

0 comments on commit 625db3e

Please sign in to comment.