This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new caad4a7ff1f branch-2.1: [fix](table) Filter base idx id for get sycned 
table ddl #47970 (#48065)
caad4a7ff1f is described below

commit caad4a7ff1f594c90a9f82cfe65c72968798d599
Author: Uniqueyou <wangyix...@selectdb.com>
AuthorDate: Wed Feb 19 19:26:50 2025 +0800

    branch-2.1: [fix](table) Filter base idx id for get sycned table ddl #47970 
(#48065)
    
    pick: https://github.com/apache/doris/pull/47970
---
 .../main/java/org/apache/doris/catalog/Env.java    | 18 ++++---
 .../apache/doris/catalog/CreateTableLikeTest.java  | 61 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 7 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index a736b306cb5..304bcd898d0 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -3697,14 +3697,19 @@ public class Env {
                 }
             }
             // with all rollup
-            if (getDdlForSync) {
-                sb.append("\nROLLUP (\n");
+            do {
+                if (!getDdlForSync) {
+                    break;
+                }
                 List<Long> indexIds = new 
ArrayList<>(olapTable.getIndexIdToMeta().keySet());
+                if (indexIds.size() == 1 && indexIds.get(0) == 
olapTable.getBaseIndexId()) {
+                    break;
+                }
+                indexIds = indexIds.stream().filter(item -> item != 
olapTable.getBaseIndexId())
+                        .collect(Collectors.toList());
+                sb.append("\nROLLUP (\n");
                 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);
@@ -3719,13 +3724,12 @@ public class Env {
                         }
                     }
                     sb.append(")");
-
                     if (i != indexIds.size() - 1) {
                         sb.append(",\n");
                     }
                 }
                 sb.append("\n)");
-            }
+            } while (false);
 
             // properties
             sb.append("\nPROPERTIES (\n");
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableLikeTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableLikeTest.java
index 9f108c83414..905ebdda485 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableLikeTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableLikeTest.java
@@ -406,4 +406,65 @@ public class CreateTableLikeTest {
         Assert.assertTrue(existedTableStmt.toString().contains("r (event_day, 
pv)"));
         Assert.assertTrue(existedTableStmt.toString().contains("r2 (siteid, 
pv)"));
     }
+
+    @Test
+    public void checkSyncedTableWithOutRollup() throws Exception {
+        String createTableWithRollup = "CREATE TABLE IF NOT EXISTS 
test.table_without_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"
+                        + "PROPERTIES(\"replication_num\" = \"1\");";
+
+        String existedDbName = "test";
+        String existedTblName = "table_without_rollup_synced";
+
+        createTable(createTableWithRollup);
+
+        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("ROLLUP"));
+    }
+
+    @Test
+    public void checkSyncedTableWithPartialRollup() throws Exception {
+        String createTableWithRollup = "CREATE TABLE IF NOT EXISTS 
test.table_with_partial_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"
+                        + ")\n" + "PROPERTIES(\"replication_num\" = \"1\");";
+
+        String existedDbName = "test";
+        String existedTblName = "table_with_partial_rollup_synced";
+
+        createTable(createTableWithRollup);
+
+        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("r (event_day, 
pv),"));
+        Assert.assertTrue(existedTableStmt.toString().contains("r (event_day, 
pv)"));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to