strongduanmu commented on code in PR #16877:
URL: https://github.com/apache/shardingsphere/pull/16877#discussion_r851898880


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingInsertStatementValidator.java:
##########
@@ -53,22 +55,34 @@ public final class ShardingInsertStatementValidator extends 
ShardingDMLStatement
     @Override
     public void preValidate(final ShardingRule shardingRule, final 
SQLStatementContext<InsertStatement> sqlStatementContext,
                             final List<Object> parameters, final 
ShardingSphereSchema schema) {
-        if (null == ((InsertStatementContext) 
sqlStatementContext).getInsertSelectContext()) {
+        if (!getInsertSelectContext(sqlStatementContext).isPresent()) {
             validateMultipleTable(shardingRule, sqlStatementContext);
         }
-        String tableName = 
sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
         Optional<SubquerySegment> insertSelectSegment = 
sqlStatementContext.getSqlStatement().getInsertSelect();
-        if (insertSelectSegment.isPresent() && 
isContainsKeyGenerateStrategy(shardingRule, tableName)
-                && !isContainsKeyGenerateColumn(shardingRule, 
sqlStatementContext.getSqlStatement().getColumns(), tableName)) {
-            throw new ShardingSphereException("INSERT INTO ... SELECT can not 
support applying keyGenerator to absent generateKeyColumn.");
+        Collection<String> tableNames = 
sqlStatementContext.getTablesContext().getTableNames();
+        for (String tableName : tableNames) {
+            if (insertSelectSegment.isPresent() && 
isContainsKeyGenerateStrategy(shardingRule, tableName)
+                    && !isContainsKeyGenerateColumn(shardingRule, 
sqlStatementContext.getSqlStatement().getColumns(), tableName)) {
+                throw new ShardingSphereException("INSERT INTO ... SELECT can 
not support applying keyGenerator to absent generateKeyColumn.");
+            }
         }
+        
         TablesContext tablesContext = sqlStatementContext.getTablesContext();
         if (insertSelectSegment.isPresent() && 
shardingRule.tableRuleExists(tablesContext.getTableNames()) 
                 && !isAllSameTables(tablesContext.getTableNames()) && 
!shardingRule.isAllBindingTables(tablesContext.getTableNames())) {
             throw new ShardingSphereException("The table inserted and the 
table selected must be the same or bind tables.");
         }
     }
     
+    private Optional<InsertSelectContext> getInsertSelectContext(final 
SQLStatementContext<InsertStatement> sqlStatementContext) {
+        if (sqlStatementContext instanceof OracleMultiInsertStatementContext) {

Review Comment:
   Why add a new OracleMultiInsertStatementContext? I think use 
InsertStatementContext is better.



##########
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/OracleMultiInsertStatementContext.java:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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.infra.binder.statement.dml;
+
+import lombok.Getter;
+import org.apache.shardingsphere.infra.binder.aware.ParameterAware;
+import 
org.apache.shardingsphere.infra.binder.segment.insert.keygen.GeneratedKeyContext;
+import 
org.apache.shardingsphere.infra.binder.segment.insert.keygen.engine.GeneratedKeyContextEngine;
+import 
org.apache.shardingsphere.infra.binder.segment.insert.values.InsertSelectContext;
+import 
org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
+import 
org.apache.shardingsphere.infra.binder.segment.insert.values.OnDuplicateUpdateContext;
+import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
+import 
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.binder.type.TableAvailable;
+import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import 
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.OnDuplicateKeyColumnsSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.handler.dml.InsertStatementHandler;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleInsertStatement;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Oracle Multi Insert SQL statement context.
+ */
+@Getter
+public final class OracleMultiInsertStatementContext extends 
CommonSQLStatementContext<InsertStatement> implements TableAvailable, 
ParameterAware {

Review Comment:
   @cheese8 Maybe we should merge this logic to InsertStatementContext.



-- 
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]

Reply via email to