This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new e6e8286c3f7 [fix](view)fix reset view def for restore wrong replace (#50567) e6e8286c3f7 is described below commit e6e8286c3f72ca886542f5406f2fb5c2cd87ceef Author: koarz <li...@selectdb.com> AuthorDate: Tue May 6 11:03:27 2025 +0800 [fix](view)fix reset view def for restore wrong replace (#50567) backup restore when the view will do resetViewDefForRestore, here directly replaceAll, did not accurately go to find the dbName, if the srcName is a substring of inlineViewDef or dbName, the replacement will be a big problem! --- fe/fe-core/src/main/java/org/apache/doris/catalog/View.java | 3 ++- .../src/test/java/org/apache/doris/catalog/CreateViewTest.java | 10 ++++++++++ .../suites/backup_restore/test_backup_restore_with_view.groovy | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java index 69f8b5ebeca..96b0fdf290d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java @@ -269,7 +269,8 @@ public class View extends Table implements GsonPostProcessable { public void resetViewDefForRestore(String srcDbName, String dbName) { // the source db name is not setted in old BackupMeta, keep compatible with the old one. if (srcDbName != null) { - inlineViewDef = inlineViewDef.replaceAll(srcDbName, dbName); + // replace dbName with a regular expression + inlineViewDef = inlineViewDef.replaceAll("(?<=`internal`\\.`)([^`]+)(?=`\\.`)", dbName); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateViewTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateViewTest.java index 46bf3ddcde9..01c8a4f0ab9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateViewTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateViewTest.java @@ -190,4 +190,14 @@ public class CreateViewTest { + "ORDER BY `w1` ASC NULLS FIRST", alter1.getInlineViewDef()); } + + @Test + public void testResetViewDefForRestore() { + View view = new View(); + view.setInlineViewDefWithSqlMode("SELECT `internal`.`test`.`test`.`k2` AS `k1`, " + + "FROM `internal`.`test`.`test`;", 1); + view.resetViewDefForRestore("test", "test1"); + Assert.assertEquals("SELECT `internal`.`test1`.`test`.`k2` AS `k1`, " + + "FROM `internal`.`test1`.`test`;", view.getInlineViewDef()); + } } diff --git a/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy b/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy index d46791dff05..91328355eca 100644 --- a/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy +++ b/regression-test/suites/backup_restore/test_backup_restore_with_view.groovy @@ -125,6 +125,8 @@ suite("test_backup_restore_with_view", "backup_restore") { restore_result.last() logger.info("show restore result: ${restore_result}") assertTrue(restore_result.last().State == "FINISHED") + def res = sql "SHOW VIEW FROM ${dbName1}.${tableName}" + assertTrue(res.size() > 0) sql "DROP TABLE ${dbName}.${tableName} FORCE" sql "DROP VIEW ${dbName}.${viewName}" --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org