morrySnow commented on code in PR #26075:
URL: https://github.com/apache/doris/pull/26075#discussion_r1378584820


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/InsertIntoTableCommand.java:
##########
@@ -140,7 +157,15 @@ public void run(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
         }
 
         OlapTableSink sink = ((OlapTableSink) 
planner.getFragments().get(0).getSink());
-
+        if (ctx.getSessionVariable().enableInsertGroupCommit) {
+            // group commit
+            if (!analyzeGroupCommit(sink, physicalOlapTableSink)) {
+                throw new AnalysisException("Nereids does not support 
group_commit "
+                        + "for this SQL statement, query id: " + 
ctx.queryId());
+            }
+            handleGroupCommit(ctx, sink, physicalOlapTableSink);

Review Comment:
   u could get fragment here, so i think u could reuse legacy planner group 
commit process code to avoid write same code twice.



##########
regression-test/suites/insert_p0/insert_group_commit_with_prepare_stmt_nereids.groovy:
##########
@@ -0,0 +1,86 @@
+// 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.
+
+import com.mysql.cj.jdbc.StatementImpl
+
+suite("insert_group_commit_with_prepare_stmt_nereids") {
+    def db = "regression_test_insert_p0"
+    def table = "insert_group_commit_with_prepare_stmt_nereids"
+
+    def getRowCount = { expectedRowCount ->
+        def retry = 0
+        while (retry < 30) {
+            sleep(2000)
+            def rowCount = sql "select count(*) from ${table}"
+            logger.info("rowCount: " + rowCount + ", retry: " + retry)
+            if (rowCount[0][0] >= expectedRowCount) {
+                break
+            }
+            retry++
+        }
+    }
+
+    def group_commit_insert = { sql, expected_row_count ->
+        def stmt = prepareStatement """ ${sql}  """
+        def result = stmt.executeUpdate()
+        logger.info("insert result: " + result)
+        def serverInfo = (((StatementImpl) stmt).results).getServerInfo()
+        logger.info("result server info: " + serverInfo)
+        if (result != expected_row_count) {
+            logger.warn("insert result: " + result + ", expected_row_count: " 
+ expected_row_count + ", sql: " + sql)
+        }
+        assertEquals(result, expected_row_count)
+        assertTrue(serverInfo.contains("'status':'PREPARE'"))
+        assertTrue(serverInfo.contains("'label':'group_commit_"))
+        assertTrue(serverInfo.contains("'optimizer':'nereids"))
+    }
+
+    try {
+        // create table
+        sql """ drop table if exists ${table}; """
+
+        sql """
+        CREATE TABLE `${table}` (
+            `id` int(11),
+            `name` varchar(1100) NULL,
+            `score` int(11) NULL default "-1"
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`id`, `name`)
+        DISTRIBUTED BY HASH(`id`) BUCKETS 1
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+        """
+
+        connect(user = context.config.jdbcUser, password = 
context.config.jdbcPassword, url = context.config.jdbcUrl) {
+            sql """ set enable_nereids_dml = true; """
+            sql """ set experimental_enable_nereids_planner=true; """

Review Comment:
   ```suggestion
               sql """ set enable_nereids_planner=true; """
   ```



##########
regression-test/suites/insert_p0/insert_group_commit_with_prepare_stmt_nereids.groovy:
##########
@@ -0,0 +1,86 @@
+// 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.
+
+import com.mysql.cj.jdbc.StatementImpl
+
+suite("insert_group_commit_with_prepare_stmt_nereids") {
+    def db = "regression_test_insert_p0"
+    def table = "insert_group_commit_with_prepare_stmt_nereids"
+
+    def getRowCount = { expectedRowCount ->
+        def retry = 0
+        while (retry < 30) {
+            sleep(2000)
+            def rowCount = sql "select count(*) from ${table}"
+            logger.info("rowCount: " + rowCount + ", retry: " + retry)
+            if (rowCount[0][0] >= expectedRowCount) {
+                break
+            }
+            retry++
+        }
+    }
+
+    def group_commit_insert = { sql, expected_row_count ->
+        def stmt = prepareStatement """ ${sql}  """
+        def result = stmt.executeUpdate()
+        logger.info("insert result: " + result)
+        def serverInfo = (((StatementImpl) stmt).results).getServerInfo()
+        logger.info("result server info: " + serverInfo)
+        if (result != expected_row_count) {
+            logger.warn("insert result: " + result + ", expected_row_count: " 
+ expected_row_count + ", sql: " + sql)
+        }
+        assertEquals(result, expected_row_count)
+        assertTrue(serverInfo.contains("'status':'PREPARE'"))
+        assertTrue(serverInfo.contains("'label':'group_commit_"))
+        assertTrue(serverInfo.contains("'optimizer':'nereids"))
+    }
+
+    try {
+        // create table
+        sql """ drop table if exists ${table}; """
+
+        sql """
+        CREATE TABLE `${table}` (
+            `id` int(11),
+            `name` varchar(1100) NULL,
+            `score` int(11) NULL default "-1"
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`id`, `name`)
+        DISTRIBUTED BY HASH(`id`) BUCKETS 1
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+        """
+
+        connect(user = context.config.jdbcUser, password = 
context.config.jdbcPassword, url = context.config.jdbcUrl) {
+            sql """ set enable_nereids_dml = true; """
+            sql """ set experimental_enable_nereids_planner=true; """
+            sql """ set enable_insert_group_commit = true; """
+            sql """ use ${db}; """

Review Comment:
   i think no need to use db manually



##########
regression-test/suites/insert_p0/insert_group_commit_with_prepare_stmt_nereids.groovy:
##########
@@ -0,0 +1,86 @@
+// 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.
+
+import com.mysql.cj.jdbc.StatementImpl
+
+suite("insert_group_commit_with_prepare_stmt_nereids") {
+    def db = "regression_test_insert_p0"
+    def table = "insert_group_commit_with_prepare_stmt_nereids"
+
+    def getRowCount = { expectedRowCount ->
+        def retry = 0
+        while (retry < 30) {
+            sleep(2000)
+            def rowCount = sql "select count(*) from ${table}"
+            logger.info("rowCount: " + rowCount + ", retry: " + retry)
+            if (rowCount[0][0] >= expectedRowCount) {
+                break
+            }
+            retry++
+        }
+    }
+
+    def group_commit_insert = { sql, expected_row_count ->
+        def stmt = prepareStatement """ ${sql}  """
+        def result = stmt.executeUpdate()
+        logger.info("insert result: " + result)
+        def serverInfo = (((StatementImpl) stmt).results).getServerInfo()
+        logger.info("result server info: " + serverInfo)
+        if (result != expected_row_count) {
+            logger.warn("insert result: " + result + ", expected_row_count: " 
+ expected_row_count + ", sql: " + sql)
+        }
+        assertEquals(result, expected_row_count)
+        assertTrue(serverInfo.contains("'status':'PREPARE'"))
+        assertTrue(serverInfo.contains("'label':'group_commit_"))
+        assertTrue(serverInfo.contains("'optimizer':'nereids"))
+    }
+
+    try {
+        // create table
+        sql """ drop table if exists ${table}; """
+
+        sql """
+        CREATE TABLE `${table}` (
+            `id` int(11),
+            `name` varchar(1100) NULL,
+            `score` int(11) NULL default "-1"
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`id`, `name`)
+        DISTRIBUTED BY HASH(`id`) BUCKETS 1
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+        """
+
+        connect(user = context.config.jdbcUser, password = 
context.config.jdbcPassword, url = context.config.jdbcUrl) {
+            sql """ set enable_nereids_dml = true; """
+            sql """ set experimental_enable_nereids_planner=true; """
+            sql """ set enable_insert_group_commit = true; """

Review Comment:
   add new variable: `set enable_fallback_to_original_planner=false`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to