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 11:32:28 UTC
[ignite] branch sql-calcite updated: IGNITE-15982 Fix correlation trait propagation for table spool - Fixes #9601.
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 929c18d IGNITE-15982 Fix correlation trait propagation for table spool - Fixes #9601.
929c18d is described below
commit 929c18d489819627d31436b3369b3c00bd006e87
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Thu Nov 25 14:31:07 2021 +0300
IGNITE-15982 Fix correlation trait propagation for table spool - Fixes #9601.
Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
.../processors/query/calcite/trait/TraitUtils.java | 12 +++--
.../query/calcite/CalciteQueryProcessorTest.java | 15 ------
.../integration/CorrelatesIntegrationTest.java | 54 ++++++++++++++++++++++
.../ignite/testsuites/IntegrationTestSuite.java | 2 +
4 files changed, 65 insertions(+), 18 deletions(-)
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/trait/TraitUtils.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/trait/TraitUtils.java
index 702e8232..9bc73fc 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/trait/TraitUtils.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/trait/TraitUtils.java
@@ -175,9 +175,15 @@ public class TraitUtils {
return rel;
RelTraitSet traits = rel.getTraitSet()
- .replace(toTrait);
-
- return new IgniteTableSpool(rel.getCluster(), traits, Spool.Type.LAZY, rel);
+ .replace(toTrait)
+ .replace(CorrelationTrait.UNCORRELATED);
+
+ return new IgniteTableSpool(
+ rel.getCluster(),
+ traits,
+ Spool.Type.LAZY,
+ RelOptRule.convert(rel, rel.getTraitSet().replace(CorrelationTrait.UNCORRELATED))
+ );
}
/** */
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 a88fc6a..d9d5e4d 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,21 +1148,6 @@ 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());
diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CorrelatesIntegrationTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CorrelatesIntegrationTest.java
new file mode 100644
index 0000000..fcde9e8
--- /dev/null
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CorrelatesIntegrationTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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 org.apache.ignite.internal.processors.query.calcite.QueryChecker;
+import org.junit.Test;
+
+/**
+ * Tests correlated queries.
+ */
+public class CorrelatesIntegrationTest extends AbstractBasicIntegrationTest {
+ /**
+ * Checks correlates are assigned before access.
+ */
+ @Test
+ public void testCorrelatesAssignedBeforeAccess() {
+ sql("create table test_tbl(v INTEGER)");
+ sql("INSERT INTO test_tbl VALUES (1)");
+
+ assertQuery("SELECT t0.v, (SELECT t0.v + t1.v FROM test_tbl t1) AS j FROM test_tbl t0")
+ .returns(1, 2)
+ .check();
+ }
+
+ /**
+ * Checks that correlates can't be moved under the table spool.
+ */
+ @Test
+ public void testCorrelatesWithTableSpool() {
+ sql("CREATE TABLE test(i1 INT, i2 INT)");
+ sql("INSERT INTO test VALUES (1, 1), (2, 2)");
+
+ assertQuery("SELECT (SELECT t1.i1 + t1.i2 + t0.i2 FROM test t1 WHERE i1 = 1) FROM test t0")
+ .matches(QueryChecker.containsSubPlan("IgniteTableSpool"))
+ .returns(3)
+ .returns(4)
+ .check();
+ }
+}
diff --git a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java
index ea9bbba..83d6409 100644
--- a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java
+++ b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java
@@ -29,6 +29,7 @@ import org.apache.ignite.internal.processors.query.calcite.StdSqlOperatorsTest;
import org.apache.ignite.internal.processors.query.calcite.UnstableTopologyTest;
import org.apache.ignite.internal.processors.query.calcite.integration.AggregatesIntegrationTest;
import org.apache.ignite.internal.processors.query.calcite.integration.CalciteErrorHandlilngIntegrationTest;
+import org.apache.ignite.internal.processors.query.calcite.integration.CorrelatesIntegrationTest;
import org.apache.ignite.internal.processors.query.calcite.integration.IndexDdlIntegrationTest;
import org.apache.ignite.internal.processors.query.calcite.integration.IndexSpoolIntegrationTest;
import org.apache.ignite.internal.processors.query.calcite.integration.IntervalTest;
@@ -85,6 +86,7 @@ import org.junit.runners.Suite;
JoinIntegrationTest.class,
IntervalTest.class,
UserDefinedFunctionsIntegrationTest.class,
+ CorrelatesIntegrationTest.class,
})
public class IntegrationTestSuite {
}