Search in sources :

Example 1 with IgniteMergeJoin

use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.

the class JoinColocationPlannerTest method joinComplexToComplexAffWithDifferentOrder.

/**
 * Re-hashing for complex affinity is not supported.
 */
@Test
public void joinComplexToComplexAffWithDifferentOrder() throws Exception {
    TestTable complexTblDirect = createTable("COMPLEX_TBL_DIRECT", IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    complexTblDirect.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTblDirect));
    TestTable complexTblIndirect = createTable("COMPLEX_TBL_INDIRECT", IgniteDistributions.affinity(ImmutableIntList.of(1, 0), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    complexTblIndirect.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTblIndirect));
    IgniteSchema schema = createSchema(complexTblDirect, complexTblIndirect);
    String sql = "select count(*) " + "from COMPLEX_TBL_DIRECT t1 " + "join COMPLEX_TBL_INDIRECT t2 on t1.id1 = t2.id1 and t1.id2 = t2.id2";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin exchange = findFirstNode(phys, node -> node instanceof IgniteExchange && ((IgniteRel) node).distribution().function().affinity());
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, exchange, nullValue());
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteExchange(org.apache.ignite.internal.sql.engine.rel.IgniteExchange) Test(org.junit.jupiter.api.Test)

Example 2 with IgniteMergeJoin

use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.

the class MergeJoinConverterRule method convert.

/**
 * {@inheritDoc}
 */
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalJoin rel) {
    RelOptCluster cluster = rel.getCluster();
    JoinInfo joinInfo = JoinInfo.of(rel.getLeft(), rel.getRight(), rel.getCondition());
    RelTraitSet leftInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(RelCollations.of(joinInfo.leftKeys));
    RelTraitSet outTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
    RelTraitSet rightInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(RelCollations.of(joinInfo.rightKeys));
    RelNode left = convert(rel.getLeft(), leftInTraits);
    RelNode right = convert(rel.getRight(), rightInTraits);
    return new IgniteMergeJoin(cluster, outTraits, left, right, rel.getCondition(), rel.getVariablesSet(), rel.getJoinType());
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) JoinInfo(org.apache.calcite.rel.core.JoinInfo) IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 3 with IgniteMergeJoin

use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.

the class JoinColocationPlannerTest method joinSameTableSimpleAff.

/**
 * Join of the same tables with a simple affinity is expected to be colocated.
 */
@Test
public void joinSameTableSimpleAff() throws Exception {
    TestTable tbl = createTable("TEST_TBL", IgniteDistributions.affinity(0, "default", "hash"), "ID", Integer.class, "VAL", String.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(0), "PK", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "select count(*) " + "from TEST_TBL t1 " + "join TEST_TBL t2 on t1.id = t2.id";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    assertThat(invalidPlanMsg, join.getLeft(), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, join.getRight(), instanceOf(IgniteIndexScan.class));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 4 with IgniteMergeJoin

use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.

the class JoinColocationPlannerTest method joinSameTableComplexAff.

/**
 * Join of the same tables with a complex affinity is expected to be colocated.
 */
@Test
public void joinSameTableComplexAff() throws Exception {
    TestTable tbl = createTable("TEST_TBL", IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "select count(*) " + "from TEST_TBL t1 " + "join TEST_TBL t2 on t1.id1 = t2.id1 and t1.id2 = t2.id2";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    assertThat(invalidPlanMsg, join.getLeft(), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, join.getRight(), instanceOf(IgniteIndexScan.class));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 5 with IgniteMergeJoin

use of org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin in project ignite-3 by apache.

the class JoinColocationPlannerTest method joinComplexToSimpleAff.

/**
 * Re-hashing based on simple affinity is possible, so bigger table with complex affinity should be sended to the smaller one.
 */
@Test
public void joinComplexToSimpleAff() throws Exception {
    TestTable complexTbl = createTable("COMPLEX_TBL", 2 * DEFAULT_TBL_SIZE, IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    complexTbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTbl));
    TestTable simpleTbl = createTable("SIMPLE_TBL", DEFAULT_TBL_SIZE, IgniteDistributions.affinity(0, "default", "hash"), "ID", Integer.class, "VAL", String.class);
    simpleTbl.addIndex(new IgniteIndex(RelCollations.of(0), "PK", simpleTbl));
    IgniteSchema schema = createSchema(complexTbl, simpleTbl);
    String sql = "select count(*) " + "from COMPLEX_TBL t1 " + "join SIMPLE_TBL t2 on t1.id1 = t2.id";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    List<IgniteExchange> exchanges = findNodes(phys, node -> node instanceof IgniteExchange && ((IgniteRel) node).distribution().function().affinity());
    assertThat(invalidPlanMsg, exchanges, hasSize(1));
    assertThat(invalidPlanMsg, exchanges.get(0).getInput(0), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, exchanges.get(0).getInput(0).getTable().unwrap(TestTable.class), equalTo(complexTbl));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteExchange(org.apache.ignite.internal.sql.engine.rel.IgniteExchange) Test(org.junit.jupiter.api.Test)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)5 IgniteMergeJoin (org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin)5 IgniteIndex (org.apache.ignite.internal.sql.engine.schema.IgniteIndex)4 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)4 Test (org.junit.jupiter.api.Test)4 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)3 IgniteExchange (org.apache.ignite.internal.sql.engine.rel.IgniteExchange)2 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 JoinInfo (org.apache.calcite.rel.core.JoinInfo)1