use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class AggregatePlannerTest method mapReduceGroupBy.
/**
* MapReduceGroupBy.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @throws Exception If failed.
*/
@ParameterizedTest
@EnumSource
public void mapReduceGroupBy(AggregateAlgorithm algo) throws Exception {
TestTable tbl = createAffinityTable();
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("TEST", tbl);
String sql = "SELECT AVG(val0) FILTER (WHERE val1 > 10) FROM test GROUP BY grp1, grp0";
IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
IgniteMapAggregateBase mapAgg = findFirstNode(phys, byClass(algo.map));
IgniteReduceAggregateBase rdcAgg = findFirstNode(phys, byClass(algo.reduce));
assertNotNull(rdcAgg, "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
assertNotNull(mapAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(rdcAgg.getAggregateCalls()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(mapAgg.getAggCallList()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
if (algo == AggregateAlgorithm.SORT) {
assertNotNull(findFirstNode(phys, byClass(IgniteSort.class)));
}
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class CorrelatedNestedLoopJoinPlannerTest method testValidIndexExpressions.
/**
* Check equi-join. CorrelatedNestedLoopJoinTest is applicable for it.
*/
@Test
public void testValidIndexExpressions() throws Exception {
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
publicSchema.addTable("T0", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
});
publicSchema.addTable("T1", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
}.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid_idx"));
String sql = "select * " + "from t0 " + "join t1 on t0.jid = t1.jid";
IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter");
System.out.println("+++ " + RelOptUtil.toString(phys));
assertNotNull(phys);
IgniteIndexScan idxScan = findFirstNode(phys, byClass(IgniteIndexScan.class));
List<RexNode> lowerBound = idxScan.lowerBound();
assertNotNull(lowerBound, "Invalid plan\n" + RelOptUtil.toString(phys));
assertEquals(3, lowerBound.size());
assertTrue(((RexLiteral) lowerBound.get(0)).isNull());
assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
assertTrue(lowerBound.get(1) instanceof RexFieldAccess);
List<RexNode> upperBound = idxScan.upperBound();
assertNotNull(upperBound, "Invalid plan\n" + RelOptUtil.toString(phys));
assertEquals(3, upperBound.size());
assertTrue(((RexLiteral) upperBound.get(0)).isNull());
assertTrue(((RexLiteral) upperBound.get(2)).isNull());
assertTrue(upperBound.get(1) instanceof RexFieldAccess);
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class SortAggregatePlannerTest method collationPermuteMapReduce.
/**
* CollationPermuteMapReduce.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @throws Exception If failed.
*/
@Test
public void collationPermuteMapReduce() throws Exception {
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
TestTable tbl = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("VAL0", f.createJavaType(Integer.class)).add("VAL1", f.createJavaType(Integer.class)).add("GRP0", f.createJavaType(Integer.class)).add("GRP1", f.createJavaType(Integer.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "test", "hash");
}
}.addIndex(RelCollations.of(ImmutableIntList.of(3, 4)), "grp0_1");
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("TEST", tbl);
String sql = "SELECT MIN(val0) FROM test GROUP BY grp1, grp0";
IgniteRel phys = physicalPlan(sql, publicSchema, "HashSingleAggregateConverterRule", "HashMapReduceAggregateConverterRule");
IgniteReduceSortAggregate agg = findFirstNode(phys, byClass(IgniteReduceSortAggregate.class));
assertNotNull(agg, "Invalid plan\n" + RelOptUtil.toString(phys));
assertNull(findFirstNode(phys, byClass(IgniteSort.class)), "Invalid plan\n" + RelOptUtil.toString(phys));
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class SortedIndexSpoolPlannerTest method testPartialIndexForCondition.
/**
* Check case when exists index (collation) isn't applied not for whole join condition but may be used by part of
* condition.
*/
@Test
public void testPartialIndexForCondition() throws Exception {
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
publicSchema.addTable("T0", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID0", f.createJavaType(Integer.class)).add("JID1", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "T0", "hash");
}
});
publicSchema.addTable("T1", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID0", f.createJavaType(Integer.class)).add("JID1", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "T1", "hash");
}
}.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid0_idx"));
String sql = "select * " + "from t0 " + "join t1 on t0.jid0 = t1.jid0 and t0.jid1 = t1.jid1";
IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeToHashIndexSpoolRule");
System.out.println("+++ \n" + RelOptUtil.toString(phys));
IgniteSortedIndexSpool idxSpool = findFirstNode(phys, byClass(IgniteSortedIndexSpool.class));
List<RexNode> lowerBound = idxSpool.indexCondition().lowerBound();
assertNotNull(lowerBound);
assertEquals(4, lowerBound.size());
assertTrue(((RexLiteral) lowerBound.get(0)).isNull());
assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
assertTrue(((RexLiteral) lowerBound.get(3)).isNull());
assertTrue(lowerBound.get(1) instanceof RexFieldAccess);
List<RexNode> upperBound = idxSpool.indexCondition().upperBound();
assertNotNull(upperBound);
assertEquals(4, upperBound.size());
assertTrue(((RexLiteral) upperBound.get(0)).isNull());
assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
assertTrue(((RexLiteral) lowerBound.get(3)).isNull());
assertTrue(upperBound.get(1) instanceof RexFieldAccess);
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft3.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of inner join, collation consisted of join keys of left table should be propagated as is.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testInnerPassThroughOrderByLeft3() throws Exception {
IgniteSchema schema = createSchema(createTable("LEFT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class), createTable("RIGHT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class));
String sql = "" + "select * " + " from LEFT_T " + " join RIGHT_T " + " on LEFT_T.c1 = RIGHT_T.c1 " + " and LEFT_T.c2 = RIGHT_T.c2 " + " order by LEFT_T.c1 DESC, LEFT_T.c2 ASC";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfJoin(rel));
List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
RelCollation expected = RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(1, ASCENDING, RelFieldCollation.NullDirection.FIRST));
assertEquals(expected, sortNodes.get(0).collation());
assertEquals(expected, sortNodes.get(1).collation());
}
Aggregations