Search in sources :

Example 36 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft16.

/**
 * 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 testInnerPassThroughOrderByLeft16() 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 ASC NULLS FIRST, LEFT_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), 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 37 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft5.

/**
 * 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 testInnerPassThroughOrderByLeft5() 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";
    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));
    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 38 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class MergeJoinPlannerTest method testInnerDerivePreserveLeft12.

/**
 * Test verifies the collation propagation from a parent node.
 *
 * <p>In case of inner join, left collation that is superset of join keys and has a common prefix could be derived as is.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void testInnerDerivePreserveLeft12() 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), new RelFieldCollation(2, ASCENDING)), "idx");
    IgniteSchema schema = createSchema(left, 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 NULLS LAST, LEFT_T.c2 NULLS LAST, LEFT_T.c3 NULLS LAST";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    assertNull(sortOnTopOfJoin(rel));
    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 39 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class MergeJoinPlannerTest method testInnerDerivePreserveLeft1.

/**
 * Test verifies the collation propagation from a parent node.
 *
 * <p>In case of inner join, left collation that is superset or equal to join keys could be derived as is.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void testInnerDerivePreserveLeft1() 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");
    IgniteSchema schema = createSchema(left, 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 ";
    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 40 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft8.

/**
 * 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 testInnerPassThroughOrderByLeft8() 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, 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, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(2, DESCENDING, RelFieldCollation.NullDirection.LAST)), sortNodes.get(0).collation());
    assertEquals(RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), 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)

Aggregations

IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)115 Test (org.junit.jupiter.api.Test)105 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)93 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)66 IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)42 RelCollation (org.apache.calcite.rel.RelCollation)33 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)28 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)20 RelNode (org.apache.calcite.rel.RelNode)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 IgniteIndex (org.apache.ignite.internal.sql.engine.schema.IgniteIndex)9 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)9 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)7 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)7 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)7 RexNode (org.apache.calcite.rex.RexNode)6 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