Search in sources :

Example 11 with IgniteRel

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

the class JoinCommutePlannerTest method testInnerCommute.

@Test
public void testInnerCommute() throws Exception {
    String sql = "SELECT COUNT(*) FROM SMALL s JOIN HUGE h on h.id = s.id";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
    assertNotNull(phys);
    IgniteNestedLoopJoin join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
    assertNotNull(join);
    IgniteProject proj = findFirstNode(phys, byClass(IgniteProject.class));
    assertNotNull(proj);
    IgniteTableScan rightScan = findFirstNode(join.getRight(), byClass(IgniteTableScan.class));
    assertNotNull(rightScan);
    IgniteTableScan leftScan = findFirstNode(join.getLeft(), byClass(IgniteTableScan.class));
    assertNotNull(leftScan);
    List<String> rightSchemaWithName = rightScan.getTable().getQualifiedName();
    assertEquals(2, rightSchemaWithName.size());
    assertEquals(rightSchemaWithName.get(1), "SMALL");
    List<String> leftSchemaWithName = leftScan.getTable().getQualifiedName();
    assertEquals(leftSchemaWithName.get(1), "HUGE");
    assertEquals(JoinRelType.INNER, join.getJoinType());
    PlanningContext ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
    RelOptPlanner pl = ctx.cluster().getPlanner();
    RelOptCost costWithCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
    assertNotNull(costWithCommute);
    System.out.println("plan: " + RelOptUtil.toString(phys));
    assertNotNull(phys);
    phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
    join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
    proj = findFirstNode(phys, byClass(IgniteProject.class));
    rightScan = findFirstNode(join.getRight(), byClass(IgniteTableScan.class));
    leftScan = findFirstNode(join.getLeft(), byClass(IgniteTableScan.class));
    assertNotNull(join);
    assertNull(proj);
    assertNotNull(rightScan);
    assertNotNull(leftScan);
    rightSchemaWithName = rightScan.getTable().getQualifiedName();
    assertEquals(2, rightSchemaWithName.size());
    // no commute
    assertEquals(rightSchemaWithName.get(1), "HUGE");
    leftSchemaWithName = leftScan.getTable().getQualifiedName();
    assertEquals(leftSchemaWithName.get(1), "SMALL");
    // no commute
    assertEquals(JoinRelType.INNER, join.getJoinType());
    ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
    pl = ctx.cluster().getPlanner();
    RelOptCost costWithoutCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
    System.out.println("plan: " + RelOptUtil.toString(phys));
    assertTrue(costWithCommute.isLt(costWithoutCommute));
}
Also used : IgniteProject(org.apache.ignite.internal.sql.engine.rel.IgniteProject) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) RelOptCost(org.apache.calcite.plan.RelOptCost) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteNestedLoopJoin(org.apache.ignite.internal.sql.engine.rel.IgniteNestedLoopJoin) IgniteTableScan(org.apache.ignite.internal.sql.engine.rel.IgniteTableScan) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) Test(org.junit.jupiter.api.Test)

Example 12 with IgniteRel

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

the class JoinCommutePlannerTest method testOuterCommute.

@Test
public void testOuterCommute() throws Exception {
    String sql = "SELECT COUNT(*) FROM SMALL s RIGHT JOIN HUGE h on h.id = s.id";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
    assertNotNull(phys);
    IgniteNestedLoopJoin join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
    IgniteProject proj = findFirstNode(phys, byClass(IgniteProject.class));
    assertNotNull(proj);
    assertEquals(JoinRelType.LEFT, join.getJoinType());
    PlanningContext ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
    RelOptPlanner pl = ctx.cluster().getPlanner();
    RelOptCost costWithCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
    assertNotNull(costWithCommute);
    System.out.println("plan: " + RelOptUtil.toString(phys));
    assertNotNull(phys);
    phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
    join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
    proj = findFirstNode(phys, byClass(IgniteProject.class));
    assertNull(proj);
    // no commute
    assertEquals(JoinRelType.RIGHT, join.getJoinType());
    ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
    pl = ctx.cluster().getPlanner();
    RelOptCost costWithoutCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
    System.out.println("plan: " + RelOptUtil.toString(phys));
    assertTrue(costWithCommute.isLt(costWithoutCommute));
}
Also used : IgniteProject(org.apache.ignite.internal.sql.engine.rel.IgniteProject) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) RelOptCost(org.apache.calcite.plan.RelOptCost) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteNestedLoopJoin(org.apache.ignite.internal.sql.engine.rel.IgniteNestedLoopJoin) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) Test(org.junit.jupiter.api.Test)

Example 13 with IgniteRel

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

the class AbstractPlannerTest method assertPlan.

protected <T extends RelNode> void assertPlan(String sql, IgniteSchema schema, Predicate<T> predicate, String... disabledRules) throws Exception {
    IgniteRel plan = physicalPlan(sql, schema, disabledRules);
    checkSplitAndSerialization(plan, schema);
    if (!predicate.test((T) plan)) {
        String invalidPlanMsg = "Invalid plan (" + lastErrorMsg + "):\n" + RelOptUtil.toString(plan, SqlExplainLevel.ALL_ATTRIBUTES);
        fail(invalidPlanMsg);
    }
}
Also used : IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel)

Example 14 with IgniteRel

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

the class AggregatePlannerTest method distribution.

/**
 * Test that aggregate has single distribution output even if parent node accept random distibution inputs.
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void distribution(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createAffinityTable().addIndex(RelCollations.of(ImmutableIntList.of(3)), "grp0");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT AVG(val0), grp0 FROM TEST GROUP BY grp0 UNION ALL SELECT val0, grp0 FROM test";
    IgniteRel phys = physicalPlan(sql, publicSchema, concat(algo.rulesToDisable, "SortMapReduceAggregateConverterRule", "HashMapReduceAggregateConverterRule"));
    IgniteSingleAggregateBase singleAgg = findFirstNode(phys, byClass(algo.single));
    assertEquals(IgniteDistributions.single(), TraitUtils.distribution(singleAgg));
    phys = physicalPlan(sql, publicSchema, concat(algo.rulesToDisable, "SortSingleAggregateConverterRule", "HashSingleAggregateConverterRule"));
    IgniteReduceAggregateBase rdcAgg = findFirstNode(phys, byClass(algo.reduce));
    assertEquals(IgniteDistributions.single(), TraitUtils.distribution(rdcAgg));
}
Also used : IgniteReduceAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSingleAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleAggregateBase) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with IgniteRel

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

the class AggregatePlannerTest method singleWithIndex.

/**
 * SingleWithIndex.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void singleWithIndex(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createBroadcastTable().addIndex(RelCollations.of(ImmutableIntList.of(3, 4)), "grp0_grp1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT AVG(val0) FILTER(WHERE val1 > 10) FROM test GROUP BY grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
    IgniteSingleAggregateBase agg = findFirstNode(phys, byClass(algo.single));
    assertNotNull(agg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(agg.getAggCallList()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
    if (algo == AggregateAlgorithm.SORT) {
        assertNotNull(findFirstNode(phys, byClass(IgniteIndexScan.class)));
    }
}
Also used : SqlAvgAggFunction(org.apache.calcite.sql.fun.SqlAvgAggFunction) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSingleAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleAggregateBase) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)102 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)93 Test (org.junit.jupiter.api.Test)89 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)64 IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)39 RelCollation (org.apache.calcite.rel.RelCollation)33 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)19 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)16 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)7 RexNode (org.apache.calcite.rex.RexNode)7 SchemaPlus (org.apache.calcite.schema.SchemaPlus)7 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)7 MappingQueryContext (org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext)6 MultiStepPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan)6 MultiStepQueryPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan)6 QueryTemplate (org.apache.ignite.internal.sql.engine.prepare.QueryTemplate)6 Splitter (org.apache.ignite.internal.sql.engine.prepare.Splitter)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6