You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/05/06 14:58:07 UTC

[GitHub] [ignite] korlov42 opened a new pull request #9084: IGNITE-14553 Duplicated result on insert

korlov42 opened a new pull request #9084:
URL: https://github.com/apache/ignite/pull/9084


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
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:
users@infra.apache.org



[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633545128



##########
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:
       There still some "insert node" phrases in javadocs.
   About "update" statement: "insert" statement as select from the same table it's a rare case, and memory overconsumption caused by table spool not so important here, but "update" statement will always be depended on the scan of the updated table and table spool always will be used. But for updates, it's not always needed. It's needed only if we modify columns used in the index we are iterating. Perhaps it's worth to include such optimization. WDYT? 




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 closed pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 closed pull request #9084:
URL: https://github.com/apache/ignite/pull/9084


   


-- 
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:
users@infra.apache.org



[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633405294



##########
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:
       `(int)pow(2, i - 1)` -> `1 << (i - 1)` ?

##########
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:
       Looks like this is redundant

##########
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:
       Why logic here is differ from `prepareDml`? If we can't use physical plan, perhaps we can check top-level node of AST for `prepareDml` as it used here?  

##########
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:
       Let's rename the class (and update javadocs), since it's already not only for insert node

##########
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:
       Got it, `prepareDml` is executed only for insert, update and delete, so it's not so important there.

##########
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:
       There still some "insert node" phrases in javadocs.
   About "update" statement: "insert" statement as select from the same table it's a rare case, and memory overconsumption caused by table spool not so important here, but "update" statement will always be depended on the scan of the updated table and table spool always will be used. But for updates, it's not always needed. It's needed only if we modify columns used in the index we are iterating. Perhaps it's worth to include such optimization. WDYT? 




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
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.




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633507694



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




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633597547



##########
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:
users@infra.apache.org



[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r630261846



##########
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:
       Typo: "isnert"

##########
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:
       If `IgniteTableModify` is always a top-level node, perhaps it's better to check this condition before recursive processing of the whole tree (to avoid redundant traversal for read-only queries).




-- 
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:
users@infra.apache.org



[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633405294



##########
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:
       `(int)pow(2, i - 1)` -> `1 << (i - 1)` ?

##########
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:
       Looks like this is redundant

##########
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:
       Why logic here is differ from `prepareDml`? If we can't use physical plan, perhaps we can check top-level node of AST for `prepareDml` as it used here?  

##########
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:
       Let's rename the class (and update javadocs), since it's already not only for insert node




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633358313



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




-- 
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:
users@infra.apache.org



[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633533293



##########
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:
       Got it, `prepareDml` is executed only for insert, update and delete, so it's not so important there.




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633507758



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




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633508658



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




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r634498268



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




-- 
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:
users@infra.apache.org



[GitHub] [ignite] korlov42 commented on a change in pull request #9084: IGNITE-14553 Duplicated result on insert

Posted by GitBox <gi...@apache.org>.
korlov42 commented on a change in pull request #9084:
URL: https://github.com/apache/ignite/pull/9084#discussion_r633544339



##########
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`




-- 
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:
users@infra.apache.org