This is an automated email from the ASF dual-hosted git repository.
hello-stephen 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 da92333115b [fix](mtmv) Quote the materialized view name in SHOW
CREATE MATERIALIZED VIEW (#70539)
da92333115b is described below
commit da92333115bf90438fbc0f0a92001ac8c27d04f4
Author: Mingyu Chen (Rayner) <[email protected]>
AuthorDate: Wed Nov 18 01:46:17 2026 +0800
[fix](mtmv) Quote the materialized view name in SHOW CREATE MATERIALIZED
VIEW (#70539)
### Background
`SHOW CREATE MATERIALIZED VIEW <mv>` prints the statement that creates
an async materialized view (MTMV): its name and column list, refresh
method, key, partitioning, distribution, properties and query, so that
users can copy it or re-create the MV. `Env.getMTMVDdl` builds the
statement. Since #66467 it quotes the column names with
`SqlUtils.getIdentSql`, as `SHOW CREATE TABLE` and `SHOW CREATE VIEW`
quote table and view names.
### What problem does this PR solve?
Issue Number: None
Related PR: #36188 (introduced SHOW CREATE MATERIALIZED VIEW), #66467
(quoted the column names of the same statement)
PR Type: Bugfix
Problem Summary:
`SHOW CREATE MATERIALIZED VIEW` prints the materialized view's name
without backquotes, so the statement it prints fails to execute when the
name needs them: a reserved word such as `select`, a name with `-` or
`$`, or a name that `enable_unicode_name_support` allows. Users who
re-create an MV from it, and tools that parse it, get a syntax error.
This PR quotes the name with `SqlUtils.getIdentSql`, as the column list
already is.
### Details
- **Frequency:** Always, for a name that needs quoting. For an MV
created as `` `mv-dash` ``, the output starts with `CREATE MATERIALIZED
VIEW mv-dash`, and executing it fails with `Possibly unquoted identifier
mv-dash detected`; for an MV named `select`, it fails with `mismatched
input 'select'`.
- **Root cause:** `Env.getMTMVDdl` appends `mtmv.getName()` as it is,
since #36188 added the statement. #66467 fixed the same problem for the
column list and left the name.
- **Why existing tests missed it:** Unit tests: `ShowCreateMTMVTest`
re-executes the DDL, but every MV in it has a plain name. Regression:
`mtmv_p0/test_show_create_mtmv` re-executes the output for the plain
name `test_show_create_mtmv_mv`, and the other suites that run the
statement use plain names too.
- **Fix:** quote the name with `SqlUtils.getIdentSql`, as the column
list is. `Env.getMTMVDdl` is the only place that builds the statement.
- **Other paths and branches:** `SHOW CREATE TABLE` refuses async MVs;
it and `SHOW CREATE VIEW` already quote names, and a synchronous MV
(`SHOW CREATE MATERIALIZED VIEW mv ON tbl`) prints the statement as the
user wrote it. branch-3.1, branch-4.0, branch-4.1 and branch-4.2 print
the bare name; #66467 reached only 4.1 and 4.2, so 3.1 and 4.0 print the
column list bare too. Since released output changes, this PR targets
master; picks are the committers' call.
- **Behavior change:** the first line gains backquotes for every MV, as
in `CREATE MATERIALIZED VIEW `mv1``. The statement still executes, but
scripts that match that line literally see the change.
### Testing
- FE UT `ShowCreateMTMVTest#testShowCreateQuotesMVName` creates MVs
named `select` and `mv-show-quoted-name`, checks that the DDL starts
with the quoted name, and re-creates a copy from it. `run-fe-ut.sh --run
org.apache.doris.catalog.ShowCreateMTMVTest`: 11 tests, 0 failures; with
`Env.java` reverted to master, the new test fails (`... but got: CREATE
MATERIALIZED VIEW select`) and the other 10 pass.
- Regression `mtmv_p0/test_show_create_mtmv` adds an MV named
`test_show_create_mtmv-mv`: the output starts with the quoted name, and
re-executing it re-creates the MV with the same output. On the unfixed
FE the suite fails at that assertion (the output starts with `CREATE
MATERIALIZED VIEW test_show_create_mtmv-mv`); on the fixed FE it passes.
- Both ran locally on a single-FE, single-BE cluster: an FE built from
this PR and a BE built from 6991e766329 (the change is FE-only). The
unfixed FE is apache/master e125ea85867 plus #70523, which touches only
`TableIf.java`; its `Env.java` equals this PR's base.
### Notes for Reviewers
- The suite drops `test_show_create_mtmv-mv` at its end, unlike the
usual practice of keeping objects for debugging: `check_before_quit`
runs `show create table` on every table with the name unquoted, and
records a failure for a name that needs quoting.
### Release note
`SHOW CREATE MATERIALIZED VIEW` quotes the materialized view's name with
backquotes, so the statement it prints executes for names such as
`select` or `mv-1`.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: code, tests, this description
- Human review: not stated
- Prompts: While integrating OpenMetadata with Doris, asked to fix Doris
output that is unreasonable in Doris instead of working around it in
OpenMetadata; after the agent reported that SHOW CREATE MATERIALIZED
VIEW prints the name bare, asked for a Doris PR.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../main/java/org/apache/doris/catalog/Env.java | 3 ++-
.../apache/doris/catalog/ShowCreateMTMVTest.java | 22 ++++++++++++++++++
.../suites/mtmv_p0/test_show_create_mtmv.groovy | 27 ++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)
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 a8a7b686227..4ebe226aa14 100644
--- 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
@@ -3925,7 +3925,8 @@ public class Env {
try {
boolean isIvm = mtmv.isIvm();
StringBuilder sb = new StringBuilder("CREATE MATERIALIZED VIEW ");
- sb.append(mtmv.getName());
+ // quote the name so that the DDL re-executes for names such as
`select` or `mv-1`
+ sb.append(SqlUtils.getIdentSql(mtmv.getName()));
addColNameAndComment(mtmv, sb, isIvm);
sb.append("\n");
sb.append(mtmv.getRefreshInfo());
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/ShowCreateMTMVTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/ShowCreateMTMVTest.java
index b34ac61f8c4..45358bce8de 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/ShowCreateMTMVTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/ShowCreateMTMVTest.java
@@ -250,6 +250,28 @@ public class ShowCreateMTMVTest extends SqlTestBase {
}
}
+ // SHOW CREATE quotes the MV name, so the DDL re-executes for a reserved
word or a name with '-'
+ @Test
+ public void testShowCreateQuotesMVName() throws Exception {
+ Database db =
Env.getCurrentEnv().getInternalCatalog().getDbOrAnalysisException("test");
+ for (String name : new String[] {"select", "mv-show-quoted-name"}) {
+ createMvByNereids("create materialized view `" + name + "` "
+ + "BUILD DEFERRED REFRESH COMPLETE ON MANUAL\n"
+ + "DISTRIBUTED BY RANDOM BUCKETS 1\n"
+ + "PROPERTIES ('replication_num' = '1')\n"
+ + "as select * from test.show_create_ivm_base;");
+
+ MTMV mtmv = (MTMV) db.getTableOrAnalysisException(name);
+ String ddl = Env.getMTMVDdl(mtmv);
+
+ Assertions.assertTrue(ddl.startsWith("CREATE MATERIALIZED VIEW `"
+ name + "`\n"),
+ "SHOW CREATE should quote the MV name, but got:\n" + ddl);
+ createMvByNereids(ddl.replace("`" + name + "`", "`" + name +
"_copy`"));
+ Assertions.assertNotNull(db.getTableNullable(name + "_copy"),
+ "The DDL from SHOW CREATE should re-create the MV:\n" +
ddl);
+ }
+ }
+
// TC-4-8: SHOW CREATE roundtrip - re-create IVM MV from DDL and verify
identical output
@Test
public void testShowCreateIvmRoundtrip() throws Exception {
diff --git a/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy
b/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy
index b25b715ad1b..85a084b8cd7 100644
--- a/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy
+++ b/regression-test/suites/mtmv_p0/test_show_create_mtmv.groovy
@@ -144,6 +144,33 @@ suite("test_show_create_mtmv","mtmv") {
logger.info("showCreateMTMVAgainResult: " +
showCreateMTMVResultAgain.toString())
assertEquals(showCreateMTMVResult.toString(),
showCreateMTMVResultAgain.toString())
+ // a name that needs back-quotes: the DDL re-executes only when SHOW
CREATE quotes it
+ String quotedMvName = "${suiteName}-mv"
+ sql """drop materialized view if exists `${quotedMvName}`;"""
+ sql """
+ CREATE MATERIALIZED VIEW `${quotedMvName}`
+ BUILD DEFERRED REFRESH AUTO ON MANUAL
+ DISTRIBUTED BY RANDOM BUCKETS 2
+ PROPERTIES (
+ 'replication_num' = '1'
+ )
+ AS
+ SELECT * FROM ${tableName};
+ """
+ showCreateMTMVResult = sql """show CREATE MATERIALIZED VIEW
`${quotedMvName}`"""
+ logger.info("showCreateMTMVResult: " + showCreateMTMVResult.toString())
+ assertTrue(showCreateMTMVResult[0][1].startsWith("CREATE MATERIALIZED VIEW
`${quotedMvName}`"))
+ sql """drop materialized view if exists `${quotedMvName}`;"""
+ sql """
+ ${showCreateMTMVResult[0][1]}
+ """
+ showCreateMTMVResultAgain = sql """show CREATE MATERIALIZED VIEW
`${quotedMvName}`"""
+ logger.info("showCreateMTMVAgainResult: " +
showCreateMTMVResultAgain.toString())
+ assertEquals(showCreateMTMVResult.toString(),
showCreateMTMVResultAgain.toString())
+
sql """drop table if exists `${tableName}`"""
sql """drop materialized view if exists ${mvName};"""
+ // check_before_quit runs SHOW CREATE TABLE on every table it finds with
the name unquoted,
+ // which fails for this name, so don't leave it behind
+ sql """drop materialized view if exists `${quotedMvName}`;"""
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]