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));
}
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));
}
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);
}
}
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));
}
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)));
}
}
Aggregations