Search in sources :

Example 1 with IgniteSort

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

the class MergeJoinPlannerTest method testLeftPassThroughOrderByRight1.

/**
 * Test verifies the collation propagation from a parent node.
 *
 * <p>In case of left join, collation consisted of join keys of right table can't be propagated.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void testLeftPassThroughOrderByRight1() 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 " + "  left join RIGHT_T " + "    on LEFT_T.c1 = RIGHT_T.c1 " + "   and LEFT_T.c2 = RIGHT_T.c2 " + " order by RIGHT_T.c1, RIGHT_T.c2";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    assertEquals(RelCollations.of(new RelFieldCollation(3, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(4, ASCENDING, RelFieldCollation.NullDirection.FIRST)), sortOnTopOfJoin(rel).collation());
    List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
    RelCollation expected = RelCollations.of(new RelFieldCollation(0, ASCENDING), new RelFieldCollation(1, ASCENDING));
    assertEquals(expected, sortNodes.get(0).collation());
    assertEquals(expected, sortNodes.get(1).collation());
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 2 with IgniteSort

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

the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft10.

/**
 * 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 testInnerPassThroughOrderByLeft10() 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 ASC NULLS FIRST, LEFT_T.c2 ASC NULLS LAST, LEFT_T.c3 ASC NULLS FIRST";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    assertNull(sortOnTopOfJoin(rel));
    List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING), new RelFieldCollation(2, ASCENDING, RelFieldCollation.NullDirection.FIRST)), sortNodes.get(0).collation());
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING)), sortNodes.get(1).collation());
}
Also used : IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 3 with IgniteSort

use of org.apache.ignite.internal.sql.engine.rel.IgniteSort 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());
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 4 with IgniteSort

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

the class MergeJoinPlannerTest method testInnerPassThroughOrderByRight8.

/**
 * 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 testInnerPassThroughOrderByRight8() 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 RIGHT_T.c1 DESC, RIGHT_T.c2 DESC";
    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, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(2, ASCENDING));
    assertEquals(expected, sortNodes.get(0).collation());
    assertEquals(expected, sortNodes.get(1).collation());
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 5 with IgniteSort

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

the class MergeJoinPlannerTest method testInnerPassThroughOrderByRight10.

/**
 * 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 testInnerPassThroughOrderByRight10() 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 RIGHT_T.c1 ASC NULLS LAST, 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), new RelFieldCollation(1, ASCENDING), new RelFieldCollation(2, ASCENDING));
    assertEquals(expected, sortNodes.get(0).collation());
    assertEquals(expected, sortNodes.get(1).collation());
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)40 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)38 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)38 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)38 Test (org.junit.jupiter.api.Test)38 RelCollation (org.apache.calcite.rel.RelCollation)33 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelNode (org.apache.calcite.rel.RelNode)1 Sort (org.apache.calcite.rel.core.Sort)1 LogicalSort (org.apache.calcite.rel.logical.LogicalSort)1 IgniteLimit (org.apache.ignite.internal.sql.engine.rel.IgniteLimit)1 Nullable (org.jetbrains.annotations.Nullable)1