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 2025/03/20 15:24:55 UTC
(ignite) branch master updated: IGNITE-24730 SQL Calcite: Fix correlated distribution restoring failure - Fixes #11947.
This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new e76e768eee9 IGNITE-24730 SQL Calcite: Fix correlated distribution restoring failure - Fixes #11947.
e76e768eee9 is described below
commit e76e768eee907e6cffa0c57d0d2bb2d1a3366389
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Thu Mar 20 18:18:43 2025 +0300
IGNITE-24730 SQL Calcite: Fix correlated distribution restoring failure - Fixes #11947.
Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
.../internal/processors/query/calcite/rel/IgniteFilter.java | 10 ++++++++++
.../processors/query/calcite/integration/tpch/TpchQ20Test.java | 2 --
.../query/calcite/planner/CorrelatedSubqueryPlannerTest.java | 9 +++++++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteFilter.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteFilter.java
index 9cc11a9c72f..953afec0746 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteFilter.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteFilter.java
@@ -171,6 +171,16 @@ public class IgniteFilter extends Filter implements TraitsAwareIgniteRel {
// Remap correlate fields to input fields.
int corrFieldsCnt = ((RexNode)corr.getNode()).getType().getFieldCount();
int inputFieldsCnt = getRowType().getFieldCount();
+
+ // Calcite during planning sometimes can produce hash distribution for correlated nested loop joins
+ // on keys which are not part of RexCorrelVariable type.
+ // These keys can't be refered by RexFieldAccess and original hash distribution can't be restored,
+ // so, just ignore correlated distribution with these keys.
+ for (int i : corrDistr.getKeys()) {
+ if (i >= corrFieldsCnt)
+ return null;
+ }
+
Mapping mapping = Mappings.create(MappingType.PARTIAL_FUNCTION, corrFieldsCnt, inputFieldsCnt);
List<RexNode> conds = RelOptUtil.conjunctions(RexUtil.toCnf(getCluster().getRexBuilder(), condition));
diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/tpch/TpchQ20Test.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/tpch/TpchQ20Test.java
index e5f85a68bfd..5c134cd12fa 100644
--- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/tpch/TpchQ20Test.java
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/tpch/TpchQ20Test.java
@@ -18,7 +18,6 @@
package org.apache.ignite.internal.processors.query.calcite.integration.tpch;
import org.apache.ignite.internal.processors.query.calcite.integration.AbstractBasicIntegrationTest;
-import org.junit.Ignore;
import org.junit.Test;
/** */
@@ -27,7 +26,6 @@ public class TpchQ20Test extends AbstractBasicIntegrationTest {
* Test the Q20 TPC-H query can be planned and executed.
*/
@Test
- @Ignore("https://issues.apache.org/jira/browse/IGNITE-24730")
public void testQ20() throws Exception {
TpchHelper.createTables(client);
diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/CorrelatedSubqueryPlannerTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/CorrelatedSubqueryPlannerTest.java
index 6c998501ce3..def65d557d2 100644
--- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/CorrelatedSubqueryPlannerTest.java
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/CorrelatedSubqueryPlannerTest.java
@@ -35,6 +35,7 @@ import org.apache.calcite.sql.SqlNode;
import org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner;
import org.apache.ignite.internal.processors.query.calcite.prepare.PlannerPhase;
import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext;
+import org.apache.ignite.internal.processors.query.calcite.rel.AbstractIgniteJoin;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteCorrelatedNestedLoopJoin;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteExchange;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteFilter;
@@ -281,6 +282,14 @@ public class CorrelatedSubqueryPlannerTest extends AbstractPlannerTest {
")) FROM th1";
assertPlan(sql, schema, colocatedPredicate);
+ // Correlate on top of another join.
+ sql = "SELECT a FROM ta1 WHERE ta1.a IN (SELECT a FROM th1) AND EXISTS (SELECT 1 FROM ta2 WHERE ta2.b = ta1.a)";
+ assertPlan(sql, schema, hasChildThat(isInstanceOf(IgniteCorrelatedNestedLoopJoin.class)
+ .and(input(0, isInstanceOf(AbstractIgniteJoin.class)))
+ .and(input(1, isInstanceOf(IgniteColocatedAggregateBase.class)
+ .and(hasChildThat(isInstanceOf(IgniteExchange.class)).negate())
+ ))));
+
// Condition on not colocated column.
sql = "SELECT a FROM ta1 WHERE EXISTS (SELECT a FROM ta2 WHERE ta2.a = ta1.a)";
assertPlan(sql, schema, colocatedPredicate.negate());