use of org.apache.ignite.internal.sql.engine.rel.IgniteSort in project ignite-3 by apache.
the class TraitUtils method convertCollation.
/**
* Convert collation. TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@Nullable
public static RelNode convertCollation(RelOptPlanner planner, RelCollation toTrait, RelNode rel) {
RelCollation fromTrait = collation(rel);
if (fromTrait.satisfies(toTrait)) {
return rel;
}
RelTraitSet traits = rel.getTraitSet().replace(toTrait);
return new IgniteSort(rel.getCluster(), traits, rel, toTrait);
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteSort in project ignite-3 by apache.
the class SortConverterRule method onMatch.
/**
* {@inheritDoc}
*/
@Override
public void onMatch(RelOptRuleCall call) {
final Sort sort = call.rel(0);
RelOptCluster cluster = sort.getCluster();
if (sort.fetch != null || sort.offset != null) {
RelTraitSet traits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(sort.getCollation()).replace(IgniteDistributions.single());
call.transformTo(new IgniteLimit(cluster, traits, convert(sort.getInput(), traits), sort.offset, sort.fetch));
} else {
RelTraitSet outTraits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(sort.getCollation());
RelTraitSet inTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
RelNode input = convert(sort.getInput(), inTraits);
call.transformTo(new IgniteSort(cluster, outTraits, input, sort.getCollation()));
}
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteSort in project ignite-3 by apache.
the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft14.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of inner join, collation that is subset of join keys should be propagated as is.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testInnerPassThroughOrderByLeft14() 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 " + " and LEFT_T.c3 = RIGHT_T.c3 " + " 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), new RelFieldCollation(2, ASCENDING));
assertEquals(expected, sortNodes.get(0).collation());
assertEquals(expected, sortNodes.get(1).collation());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteSort in project ignite-3 by apache.
the class MergeJoinPlannerTest method testRightPassThroughOrderByRight5.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of right join, collation consisted of join keys only should be propagated as is.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testRightPassThroughOrderByRight5() 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 " + " right join RIGHT_T " + " on LEFT_T.c1 = RIGHT_T.c1 " + " and LEFT_T.c2 = RIGHT_T.c2 " + " order by RIGHT_T.c1 ASC NULLS FIRST, RIGHT_T.c2 ASC NULLS LAST";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfJoin(rel));
List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
RelCollation expected = RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING));
assertEquals(expected, sortNodes.get(0).collation());
assertEquals(expected, sortNodes.get(1).collation());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteSort in project ignite-3 by apache.
the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft7.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of inner join, collation that is superset of join keys should be propagated as is, if it doesn't include fields from right
* table.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testInnerPassThroughOrderByLeft7() 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 DESC, LEFT_T.c3 DESC";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfJoin(rel));
List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
assertEquals(RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(1, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(2, DESCENDING, RelFieldCollation.NullDirection.LAST)), sortNodes.get(0).collation());
assertEquals(RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(1, DESCENDING, RelFieldCollation.NullDirection.LAST)), sortNodes.get(1).collation());
}
Aggregations