Search in sources :

Example 46 with IgniteRel

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

the class MergeJoinPlannerTest method testLeftPassThroughOrderByRight2.

/**
 * 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 testLeftPassThroughOrderByRight2() 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 " + "   and LEFT_T.c3 = RIGHT_T.c3 " + " 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), 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 47 with IgniteRel

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

the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft6.

/**
 * 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 testInnerPassThroughOrderByLeft6() 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, LEFT_T.c2, LEFT_T.c3";
    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, RelFieldCollation.NullDirection.FIRST), 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, RelFieldCollation.NullDirection.FIRST)), 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 48 with IgniteRel

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

the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft11.

/**
 * Test verifies the collation propagation from a parent node.
 *
 * <p>In case of inner join, collation that is superset of join keys, but its prefix contains columns outside of join keys, can't be
 * propagated.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void testInnerPassThroughOrderByLeft11() 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.c3, LEFT_T.c2, LEFT_T.c1";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    IgniteSort topSortNode = sortOnTopOfJoin(rel);
    assertEquals(RelCollations.of(new RelFieldCollation(2, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST)), topSortNode.collation());
    List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING), new RelFieldCollation(1, ASCENDING)), sortNodes.get(0).collation());
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING), 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 49 with IgniteRel

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

the class MergeJoinPlannerTest method testInnerDeriveMixed1.

/**
 * Test verifies the collation propagation from a parent node.
 *
 * <p>In case of inner join, left collation should be preferred if it fully covers join keys.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void testInnerDeriveMixed1() throws Exception {
    TestTable left = createTable("LEFT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class);
    left.addIndex(RelCollations.of(new RelFieldCollation(0, ASCENDING), new RelFieldCollation(1, ASCENDING)), "idx");
    TestTable right = createTable("RIGHT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class);
    right.addIndex(RelCollations.of(new RelFieldCollation(1, ASCENDING), new RelFieldCollation(0, ASCENDING)), "idx");
    IgniteSchema schema = createSchema(left, right);
    String sql = "" + "select * " + "  from LEFT_T " + "  join RIGHT_T " + "    on LEFT_T.c1 = RIGHT_T.c1 " + "   and LEFT_T.c2 = RIGHT_T.c2 ";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    assertNull(sortOnTopOfScan(rel, "LEFT_T"));
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING), new RelFieldCollation(1, ASCENDING)), sortOnTopOfScan(rel, "RIGHT_T").collation());
}
Also used : IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 50 with IgniteRel

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

the class MergeJoinPlannerTest method testRightPassThroughOrderByLeft1.

/**
 * Test verifies the collation propagation from a parent node.
 *
 * <p>In case of right join, collation consisted of left keys can't be propagated.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void testRightPassThroughOrderByLeft1() 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 LEFT_T.c1, LEFT_T.c2";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    IgniteSort topSortNode = sortOnTopOfJoin(rel);
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING, RelFieldCollation.NullDirection.FIRST)), topSortNode.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)

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