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

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 96efbb07f10 Enhance parsing the Doris create materialized view (#34943)
96efbb07f10 is described below

commit 96efbb07f10076089a1c46a5be53b9414a9eef52
Author: YUN CHIEH LEE <49186319+jay841...@users.noreply.github.com>
AuthorDate: Mon Apr 21 08:26:58 2025 +0800

    Enhance parsing the Doris create materialized view (#34943)
    
    * Fix the error in parsing the Doris create materialized view
    
    * mark the syntax differences from MySQL
    
    * update RELEASE-NOTES
    
    * fix systax rule
---
 RELEASE-NOTES.md                                   |  1 +
 .../src/main/antlr4/imports/doris/DDLStatement.g4  | 30 ++++++++++++++++
 .../src/main/antlr4/imports/doris/DorisKeyword.g4  | 40 ++++++++++++++++++++++
 .../sql/parser/autogen/DorisStatement.g4           |  1 +
 .../statement/type/DorisDDLStatementVisitor.java   |  7 ++++
 .../ddl/DorisCreateMaterializedViewStatement.java  | 27 +++++++++++++++
 .../case/ddl/create-materialized-view.xml          |  4 +++
 .../sql/supported/ddl/create-materialized-view.xml |  4 +++
 8 files changed, 114 insertions(+)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 5b452029f5c..b0cd6b43c99 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -25,6 +25,7 @@
 1. SQL Parser: Support MySQL SELECT MAX(ALL expr) statement parse - 
[#34639](https://github.com/apache/shardingsphere/pull/34639)
 1. SQL Parser: Support MySQL INSERT with GEOMCOLLECTION function parse - 
[#34654](https://github.com/apache/shardingsphere/pull/34654)
 1. SQL Parser: Support MySQL DELETE with statement parse - 
[#34817](https://github.com/apache/shardingsphere/pull/34817) 
+1. SQL Parser: Support Doris CREATE MATERIALIZED VIEW - 
[#31499](https://github.com/apache/shardingsphere/pull/31499)
 1. Encrypt: Use EncryptDerivedColumnSuffix to enhance encrypt table subquery 
rewrite logic - [#34829](https://github.com/apache/shardingsphere/pull/34829)
 1. Encrypt: Add quotes to encrypt rewrite derived columns - 
[#34950](https://github.com/apache/shardingsphere/pull/34950)
 1. SQL Router: Add check for select with union all routing to multi data 
sources - [#35037](https://github.com/apache/shardingsphere/pull/35037)
diff --git 
a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DDLStatement.g4 
b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DDLStatement.g4
index e3670c24407..62d492f7621 100644
--- a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DDLStatement.g4
+++ b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DDLStatement.g4
@@ -359,6 +359,36 @@ createView
       (WITH (CASCADED | LOCAL)? CHECK OPTION)?
     ;
 
+// DORIS ADDED BEGIN
+createMaterializedView
+    : CREATE MATERIALIZED VIEW ifNotExists? name (LP_ columnDefinition RP_)? 
buildMode? (REFRESH refreshMethod? refreshTrigger?)? ((DUPLICATE)? KEY keys= 
LP_ identifierList RP_)? commentClause? partitionClause? distributedbyClause? 
propertiesClause? AS select
+    ;
+// DORIS ADDED END
+
+// DORIS ADDED BEGIN
+buildMode
+    : BUILD (IMMEDIATE | DEFERRED)
+    ;
+// DORIS ADDED END
+
+// DORIS ADDED BEGIN
+refreshMethod
+    : COMPLETE | AUTO
+    ;
+// DORIS ADDED END
+
+// DORIS ADDED BEGIN
+refreshTrigger
+    : ON MANUAL | ON SCHEDULE refreshSchedule | ON COMMIT
+    ;
+// DORIS ADDED END
+
+// DORIS ADDED BEGIN
+refreshSchedule
+    : EVERY intervalValue (STARTS timestampValue)?
+    ;
+// DORIS ADDED END
+
 alterView
     : ALTER (ALGORITHM EQ_ (UNDEFINED | MERGE | TEMPTABLE))?
       ownerStatement?
diff --git 
a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4 
b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
index 447ea9bfdd5..d0192ffea2f 100644
--- a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
+++ b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
@@ -111,6 +111,10 @@ ATTRIBUTE
     : A T T R I B U T E
     ;
 
+AUTO
+    : A U T O
+    ;
+
 AUTOEXTEND_SIZE
     : A U T O E X T E N D UL_ S I Z E
     ;
@@ -201,6 +205,10 @@ BUCKETS
     : B U C K E T S
     ;
 
+BUILD
+    : B U I L D
+    ;
+
 BY
     : B Y
     ;
@@ -349,6 +357,12 @@ COMPLETION
     : C O M P L E T I O N
     ;
 
+// DORIS ADDED BEGIN
+COMPLETE
+    : C O M P L E T E
+    ;
+// DORIS ADDED END
+
 COMPONENT
     : C O M P O N E N T
     ;
@@ -531,6 +545,12 @@ DEFAULT_AUTH
     : D E F A U L T UL_ A U T H
     ;
 
+// DORIS ADDED BEGIN
+DEFERRED
+    : D E F E R R E D
+    ;
+// DORIS ADDED END
+
 DEFINER
     : D E F I N E R
     ;
@@ -1023,6 +1043,12 @@ IGNORE_SERVER_IDS
     : I G N O R E UL_ S E R V E R UL_ I D S
     ;
 
+// DORIS ADDED BEGIN
+IMMEDIATE
+    : I M M E D I A T E
+    ;
+// DORIS ADDED END
+
 IMPORT
     : I M P O R T
     ;
@@ -1338,6 +1364,10 @@ LOW_PRIORITY
     : L O W UL_ P R I O R I T Y
     ;
 
+MANUAL
+    : M A N U A L
+    ;
+
 MASTER
     : M A S T E R
     ;
@@ -1450,6 +1480,12 @@ MASTER_ZSTD_COMPRESSION_LEVEL
     : M A S T E R UL_ Z S T D UL_ C O M P R E S S I O N UL_ L E V E L
     ;
 
+// DORIS ADDED BEGIN
+MATERIALIZED
+    : M A T E R I A L I Z E D
+    ;
+// DORIS ADDED END
+
 MATCH
     : M A T C H
     ;
@@ -2024,6 +2060,10 @@ REFERENCES
     : R E F E R E N C E S
     ;
 
+REFRESH
+    : R E F R E S H
+    ;
+
 REGEXP
     : R E G E X P
     ;
diff --git 
a/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
 
b/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
index 1c4816f721e..ed59cbae36d 100644
--- 
a/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
+++ 
b/parser/sql/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
@@ -128,6 +128,7 @@ execute
     | dropTablespace
     | delimiter
     | startReplica
+    | createMaterializedView
     // TODO consider refactor following sytax to SEMI_? EOF
     ) (SEMI_ EOF? | EOF)
     | EOF
diff --git 
a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java
 
b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java
index 0813a7db2d2..c22e968b4f4 100644
--- 
a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java
+++ 
b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java
@@ -59,6 +59,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateF
 import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateIndexContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateLikeClauseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateLogfileGroupContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateMaterializedViewContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateProcedureContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateServerContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateTableContext;
@@ -165,6 +166,7 @@ import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateEvent
 import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateFunctionStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateIndexStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateLogfileGroupStatement;
+import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateMaterializedViewStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateProcedureStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateServerStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisCreateTableStatement;
@@ -1046,4 +1048,9 @@ public final class DorisDDLStatementVisitor extends 
DorisStatementVisitor implem
     public ASTNode visitDeallocate(final DeallocateContext ctx) {
         return new DorisDeallocateStatement();
     }
+    
+    @Override
+    public ASTNode visitCreateMaterializedView(final 
CreateMaterializedViewContext ctx) {
+        return new DorisCreateMaterializedViewStatement();
+    }
 }
diff --git 
a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/ddl/DorisCreateMaterializedViewStatement.java
 
b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/ddl/DorisCreateMaterializedViewStatement.java
new file mode 100644
index 00000000000..4150db002dd
--- /dev/null
+++ 
b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/ddl/DorisCreateMaterializedViewStatement.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.statement.doris.ddl;
+
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateMaterializedViewStatement;
+import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement;
+
+/**
+ * DorisSQL create materialized view statement.
+ */
+public final class DorisCreateMaterializedViewStatement extends 
CreateMaterializedViewStatement implements DorisStatement {
+}
diff --git 
a/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml 
b/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml
index d6287ba0871..433d59af518 100644
--- a/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml
+++ b/test/it/parser/src/main/resources/case/ddl/create-materialized-view.xml
@@ -36,4 +36,8 @@
     <create-materialized-view 
sql-case-id="create_materialized_view_with_pctfree_storage_build_deferred" />
     <create-materialized-view 
sql-case-id="create_materialized_view_refresh_fast_on_remand_as_select" />
     <create-materialized-view 
sql-case-id="create_materialized_view_refresh_with_date" />
+    <create-materialized-view 
sql-case-id="create_materialized_view_with_key_exists" />
+    <create-materialized-view 
sql-case-id="create_materialized_view_refresh_on_schedule" />
+    <create-materialized-view 
sql-case-id="create_materialized_view_refresh_complete" />
+    <create-materialized-view 
sql-case-id="create_materialized_view_build_immediate" />
 </sql-parser-test-cases>
diff --git 
a/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml
 
b/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml
index 181ee92afa8..fab9ced5f05 100644
--- 
a/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml
+++ 
b/test/it/parser/src/main/resources/sql/supported/ddl/create-materialized-view.xml
@@ -142,4 +142,8 @@
     AS SELECT * FROM sh.customers@remote
           UNION
        SELECT * FROM sh.customers@local;" db-types="Oracle" />
+    <sql-case id="create_materialized_view_with_key_exists" value="CREATE 
MATERIALIZED VIEW mv1 KEY(k1, k2) AS SELECT k1, k2 FROM test_table;" 
db-types="Doris" />
+    <sql-case id="create_materialized_view_refresh_on_schedule" value="CREATE 
MATERIALIZED VIEW mv1 REFRESH ON SCHEDULE EVERY 2 HOUR STARTS '2023-12-13 
21:07:09' AS SELECT k1, k2 FROM test_table;" db-types="Doris" />
+    <sql-case id="create_materialized_view_refresh_complete" value="CREATE 
MATERIALIZED VIEW mv1 REFRESH COMPLETE AS SELECT k1, k2 FROM test_table;" 
db-types="Doris" />
+    <sql-case id="create_materialized_view_build_immediate" value="CREATE 
MATERIALIZED VIEW mv1 BUILD IMMEDIATE AS SELECT k1, k2 FROM test_table;" 
db-types="Doris" />
 </sql-cases>

Reply via email to