You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2021/11/25 05:56:41 UTC

[ignite] branch sql-calcite updated: IGNITE-15603 Add project correlates to trait for table scan/index scan - Fixes #9593.

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

alexpl pushed a commit to branch sql-calcite
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/sql-calcite by this push:
     new 48b8d7c  IGNITE-15603 Add project correlates to trait for table scan/index scan - Fixes #9593.
48b8d7c is described below

commit 48b8d7caefd1b4f0660765e0b58285c0c5c96d45
Author: Vladimir Steshin <vl...@gmail.com>
AuthorDate: Thu Nov 25 08:54:38 2021 +0300

    IGNITE-15603 Add project correlates to trait for table scan/index scan - Fixes #9593.
    
    Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
 .../query/calcite/rule/LogicalScanConverterRule.java      | 14 ++++++++++++++
 .../query/calcite/CalciteQueryProcessorTest.java          | 15 +++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/LogicalScanConverterRule.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/LogicalScanConverterRule.java
index 32e33eb..525d11d 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/LogicalScanConverterRule.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/LogicalScanConverterRule.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.query.calcite.rule;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -46,6 +47,7 @@ import org.apache.ignite.internal.processors.query.calcite.schema.IgniteTable;
 import org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait;
 import org.apache.ignite.internal.processors.query.calcite.trait.RewindabilityTrait;
 import org.apache.ignite.internal.processors.query.calcite.util.RexUtils;
+import org.apache.ignite.internal.util.typedef.F;
 
 /** */
 public abstract class LogicalScanConverterRule<T extends ProjectableFilterableTableScan> extends AbstractIgniteConverterRule<T> {
@@ -81,6 +83,12 @@ public abstract class LogicalScanConverterRule<T extends ProjectableFilterableTa
                     .replace(collation);
 
                 Set<CorrelationId> corrIds = RexUtils.extractCorrelationIds(rel.condition());
+
+                if (!F.isEmpty(rel.projects())) {
+                    corrIds = new HashSet<>(corrIds);
+                    corrIds.addAll(RexUtils.extractCorrelationIds(rel.projects()));
+                }
+
                 if (!corrIds.isEmpty())
                     traits = traits.replace(CorrelationTrait.correlations(corrIds));
 
@@ -125,6 +133,12 @@ public abstract class LogicalScanConverterRule<T extends ProjectableFilterableTa
                     .replace(distribution);
 
                 Set<CorrelationId> corrIds = RexUtils.extractCorrelationIds(rel.condition());
+
+                if (!F.isEmpty(rel.projects())) {
+                    corrIds = new HashSet<>(corrIds);
+                    corrIds.addAll(RexUtils.extractCorrelationIds(rel.projects()));
+                }
+
                 if (!corrIds.isEmpty())
                     traits = traits.replace(CorrelationTrait.correlations(corrIds));
 
diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
index d9d5e4d..a88fc6a 100644
--- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java
@@ -1148,6 +1148,21 @@ public class CalciteQueryProcessorTest extends GridCommonAbstractTest {
             .check();
     }
 
+    /**
+     * Checks correlates are assigned before access.
+     */
+    @Test
+    public void testCorrelatesAssignedBeforeAccess() throws IgniteInterruptedCheckedException {
+        sql("create table test_tbl(v INTEGER)", true);
+
+        sql("INSERT INTO test_tbl VALUES (1)", true);
+
+        List<List<?>> res = sql("SELECT t0.v, (SELECT t0.v + t1.v FROM test_tbl t1) AS j FROM test_tbl t0");
+
+        assertEquals(res.size(), 1);
+        assertEquals((Integer)res.get(0).get(0) * 2, res.get(0).get(1));
+    }
+
     /** */
     private static List<String> deriveColumnNamesFromCursor(FieldsQueryCursor cursor) {
         List<String> names = new ArrayList<>(cursor.getColumnsCount());