Search in sources :

Example 1 with IgniteTableScan

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

the class JoinCommutePlannerTest method testInnerCommute.

@Test
public void testInnerCommute() throws Exception {
    String sql = "SELECT COUNT(*) FROM SMALL s JOIN HUGE h on h.id = s.id";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
    assertNotNull(phys);
    IgniteNestedLoopJoin join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
    assertNotNull(join);
    IgniteProject proj = findFirstNode(phys, byClass(IgniteProject.class));
    assertNotNull(proj);
    IgniteTableScan rightScan = findFirstNode(join.getRight(), byClass(IgniteTableScan.class));
    assertNotNull(rightScan);
    IgniteTableScan leftScan = findFirstNode(join.getLeft(), byClass(IgniteTableScan.class));
    assertNotNull(leftScan);
    List<String> rightSchemaWithName = rightScan.getTable().getQualifiedName();
    assertEquals(2, rightSchemaWithName.size());
    assertEquals(rightSchemaWithName.get(1), "SMALL");
    List<String> leftSchemaWithName = leftScan.getTable().getQualifiedName();
    assertEquals(leftSchemaWithName.get(1), "HUGE");
    assertEquals(JoinRelType.INNER, join.getJoinType());
    PlanningContext ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin");
    RelOptPlanner pl = ctx.cluster().getPlanner();
    RelOptCost costWithCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
    assertNotNull(costWithCommute);
    System.out.println("plan: " + RelOptUtil.toString(phys));
    assertNotNull(phys);
    phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
    join = findFirstNode(phys, byClass(IgniteNestedLoopJoin.class));
    proj = findFirstNode(phys, byClass(IgniteProject.class));
    rightScan = findFirstNode(join.getRight(), byClass(IgniteTableScan.class));
    leftScan = findFirstNode(join.getLeft(), byClass(IgniteTableScan.class));
    assertNotNull(join);
    assertNull(proj);
    assertNotNull(rightScan);
    assertNotNull(leftScan);
    rightSchemaWithName = rightScan.getTable().getQualifiedName();
    assertEquals(2, rightSchemaWithName.size());
    // no commute
    assertEquals(rightSchemaWithName.get(1), "HUGE");
    leftSchemaWithName = leftScan.getTable().getQualifiedName();
    assertEquals(leftSchemaWithName.get(1), "SMALL");
    // no commute
    assertEquals(JoinRelType.INNER, join.getJoinType());
    ctx = plannerCtx(sql, publicSchema, "MergeJoinConverter", "CorrelatedNestedLoopJoin", "JoinCommuteRule");
    pl = ctx.cluster().getPlanner();
    RelOptCost costWithoutCommute = pl.getCost(phys, phys.getCluster().getMetadataQuery());
    System.out.println("plan: " + RelOptUtil.toString(phys));
    assertTrue(costWithCommute.isLt(costWithoutCommute));
}
Also used : IgniteProject(org.apache.ignite.internal.sql.engine.rel.IgniteProject) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) RelOptCost(org.apache.calcite.plan.RelOptCost) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteNestedLoopJoin(org.apache.ignite.internal.sql.engine.rel.IgniteNestedLoopJoin) IgniteTableScan(org.apache.ignite.internal.sql.engine.rel.IgniteTableScan) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) Test(org.junit.jupiter.api.Test)

Example 2 with IgniteTableScan

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

the class RelJsonReaderTest method fromJson.

/**
 * Test verifies that during deserialization table being resolved by its ID.
 */
@Test
void fromJson() {
    UUID tableId = UUID.randomUUID();
    int tableVer = 2;
    IgniteTable igniteTableMock = mock(IgniteTable.class);
    when(igniteTableMock.getStatistic()).thenReturn(new Statistic() {
    });
    when(igniteTableMock.getRowType(any())).thenReturn(mock(RelDataType.class));
    SqlSchemaManager schemaMock = mock(SqlSchemaManager.class);
    when(schemaMock.tableById(tableId, tableVer)).thenReturn(igniteTableMock);
    String json = "" + "{\n" + "  \"rels\" : [ {\n" + "    \"id\" : \"0\",\n" + "    \"relOp\" : \"IgniteTableScan\",\n" + "    \"table\" : [\"PUBLIC\", \"TEST\"],\n" + "    \"tableId\" : \"" + tableId + "\",\n" + "    \"tableVer\" : " + tableVer + ",\n" + "    \"inputs\" : [ ]\n" + "  } ]\n" + "}";
    RelNode node = RelJsonReader.fromJson(schemaMock, json);
    assertThat(node, isA(IgniteTableScan.class));
    assertThat(node.getTable(), notNullValue());
    assertThat(node.getTable().unwrap(IgniteTable.class), is(igniteTableMock));
    Mockito.verify(schemaMock).tableById(tableId, tableVer);
}
Also used : SqlSchemaManager(org.apache.ignite.internal.sql.engine.schema.SqlSchemaManager) IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) Statistic(org.apache.calcite.schema.Statistic) RelNode(org.apache.calcite.rel.RelNode) RelDataType(org.apache.calcite.rel.type.RelDataType) UUID(java.util.UUID) IgniteTableScan(org.apache.ignite.internal.sql.engine.rel.IgniteTableScan) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteTableScan (org.apache.ignite.internal.sql.engine.rel.IgniteTableScan)2 Test (org.junit.jupiter.api.Test)2 UUID (java.util.UUID)1 RelOptCost (org.apache.calcite.plan.RelOptCost)1 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)1 RelNode (org.apache.calcite.rel.RelNode)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 Statistic (org.apache.calcite.schema.Statistic)1 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)1 IgniteNestedLoopJoin (org.apache.ignite.internal.sql.engine.rel.IgniteNestedLoopJoin)1 IgniteProject (org.apache.ignite.internal.sql.engine.rel.IgniteProject)1 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)1 IgniteTable (org.apache.ignite.internal.sql.engine.schema.IgniteTable)1 SqlSchemaManager (org.apache.ignite.internal.sql.engine.schema.SqlSchemaManager)1