korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633357771



##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ExecutionServiceImpl.java
##########
@@ -614,6 +622,8 @@ private QueryPlan prepareDml(SqlNode sqlNode, 
PlanningContext ctx) throws Valida
         // Convert to Relational operators graph
         IgniteRel igniteRel = optimize(sqlNode, planner);
 
+        igniteRel = new FixDependentInsertNodeShuttle().visit(igniteRel);

Review comment:
       Currently it is a top-level node, but after IGNITE-12692 we could get an 
aggregate node on top of TableModify.

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ExecutionServiceImpl.java
##########
@@ -1149,4 +1159,79 @@ private void onError(Throwable error) {
             tryClose();
         }
     }
+
+    static class FixDependentInsertNodeShuttle extends IgniteRelShuttle {
+        /**
+         * Flags indicate whether a {@link IgniteTableModify insert node}
+         * modifies the same table used for querying a data set to isnert.

Review comment:
       fixed

##########
File path: 
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDmlIntegrationTest.java
##########
@@ -128,19 +133,55 @@ public void 
testInsertAsSelectWithConcurrentDataModification() throws IgniteChec
         });
 
         for (int i = 8; i < 18; i++) {
-            int off = (int)Math.pow(2, i - 1);
+            int off = (int)pow(2, i - 1);

Review comment:
       fixed

##########
File path: 
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDmlIntegrationTest.java
##########
@@ -0,0 +1,309 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.cache.query.FieldsQueryCursor;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.query.QueryEngine;
+import 
org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor;
+import 
org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessorTest;
+import org.apache.ignite.internal.processors.query.calcite.util.Commons;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static java.lang.Math.pow;
+
+/** */
+public class TableDmlIntegrationTest extends GridCommonAbstractTest {
+    /** */
+    private static final String CLIENT_NODE_NAME = "client";
+
+    /** */
+    private static final String DATA_REGION_NAME = "test_data_region";
+
+    /** */
+    private IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(2);
+
+        client = startClientGrid(CLIENT_NODE_NAME);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setSqlConfiguration(
+                new SqlConfiguration().setSqlSchemas("MY_SCHEMA")
+            )
+            .setDataStorageConfiguration(

Review comment:
       fixed

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ExecutionServiceImpl.java
##########
@@ -1149,4 +1165,80 @@ private void onError(Throwable error) {
             tryClose();
         }
     }
+
+    /** */
+    private static class FixDependentInsertNodeShuttle extends 
IgniteRelShuttle {

Review comment:
       fixed. I've also added a javadoc describing problem this shuttle is 
supposed to fix.

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ExecutionServiceImpl.java
##########
@@ -674,16 +686,20 @@ private IgniteRel optimize(SqlNode sqlNode, IgnitePlanner 
planner) {
     }
 
     /** */
+    // TODO: prepareExplain should reuse prepare* methods for different query 
types
     private QueryPlan prepareExplain(SqlNode explain, PlanningContext ctx) 
throws ValidationException {
         IgnitePlanner planner = ctx.planner();
 
         SqlNode sql = ((SqlExplain)explain).getExplicandum();
 
         // Validate
-        explain = planner.validate(sql);
+        sql = planner.validate(sql);
 
         // Convert to Relational operators graph
-        IgniteRel igniteRel = optimize(explain, planner);
+        IgniteRel igniteRel = optimize(sql, planner);
+
+        if (sql.isA(ImmutableSet.of(SqlKind.INSERT, SqlKind.UPDATE)))

Review comment:
       Yes, `prepareExplain` is a separate branch that explains all types of 
other queries (regular query, DDL, DML).
   
   I think I was wrong about putting shuttle to `prepare*` method. Looks like 
`optimize` is better place since it's a common point for both `prepareDml` and 
`prepareExplain`

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ExecutionServiceImpl.java
##########
@@ -1149,4 +1165,80 @@ private void onError(Throwable error) {
             tryClose();
         }
     }
+
+    /** */
+    private static class FixDependentInsertNodeShuttle extends 
IgniteRelShuttle {

Review comment:
       > it's worth to include such optimization
   
   Sounds reasonable. I'll think how it would look like




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

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


Reply via email to