Search in sources :

Example 6 with IgniteIndex

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

the class TableDmlPlannerTest method insertCachesIndexScan.

/**
 * InsertCachesIndexScan.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void insertCachesIndexScan() throws Exception {
    TestTable tbl = createTable("TEST", IgniteDistributions.random(), "VAL", Integer.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(0), "IDX", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "insert into test select 2 * val from test";
    RelNode phys = physicalPlan(sql, schema, "LogicalTableScanConverterRule");
    assertNotNull(phys);
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    IgniteTableModify modifyNode = findFirstNode(phys, byClass(IgniteTableModify.class));
    assertThat(invalidPlanMsg, modifyNode, notNullValue());
    assertThat(invalidPlanMsg, modifyNode.getInput(), instanceOf(Spool.class));
    Spool spool = (Spool) modifyNode.getInput();
    assertThat(invalidPlanMsg, spool.readType, equalTo(Spool.Type.EAGER));
    assertThat(invalidPlanMsg, findFirstNode(phys, byClass(IgniteIndexScan.class)), notNullValue());
}
Also used : IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteTableModify(org.apache.ignite.internal.sql.engine.rel.IgniteTableModify) Spool(org.apache.calcite.rel.core.Spool) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 7 with IgniteIndex

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

the class JoinColocationPlannerTest method joinSameTableSimpleAff.

/**
 * Join of the same tables with a simple affinity is expected to be colocated.
 */
@Test
public void joinSameTableSimpleAff() throws Exception {
    TestTable tbl = createTable("TEST_TBL", IgniteDistributions.affinity(0, "default", "hash"), "ID", Integer.class, "VAL", String.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(0), "PK", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "select count(*) " + "from TEST_TBL t1 " + "join TEST_TBL t2 on t1.id = t2.id";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    assertThat(invalidPlanMsg, join.getLeft(), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, join.getRight(), instanceOf(IgniteIndexScan.class));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 8 with IgniteIndex

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

the class JoinColocationPlannerTest method joinSameTableComplexAff.

/**
 * Join of the same tables with a complex affinity is expected to be colocated.
 */
@Test
public void joinSameTableComplexAff() throws Exception {
    TestTable tbl = createTable("TEST_TBL", IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "select count(*) " + "from TEST_TBL t1 " + "join TEST_TBL t2 on t1.id1 = t2.id1 and t1.id2 = t2.id2";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    assertThat(invalidPlanMsg, join.getLeft(), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, join.getRight(), instanceOf(IgniteIndexScan.class));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 9 with IgniteIndex

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

the class JoinColocationPlannerTest method joinComplexToSimpleAff.

/**
 * Re-hashing based on simple affinity is possible, so bigger table with complex affinity should be sended to the smaller one.
 */
@Test
public void joinComplexToSimpleAff() throws Exception {
    TestTable complexTbl = createTable("COMPLEX_TBL", 2 * DEFAULT_TBL_SIZE, IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    complexTbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTbl));
    TestTable simpleTbl = createTable("SIMPLE_TBL", DEFAULT_TBL_SIZE, IgniteDistributions.affinity(0, "default", "hash"), "ID", Integer.class, "VAL", String.class);
    simpleTbl.addIndex(new IgniteIndex(RelCollations.of(0), "PK", simpleTbl));
    IgniteSchema schema = createSchema(complexTbl, simpleTbl);
    String sql = "select count(*) " + "from COMPLEX_TBL t1 " + "join SIMPLE_TBL t2 on t1.id1 = t2.id";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    List<IgniteExchange> exchanges = findNodes(phys, node -> node instanceof IgniteExchange && ((IgniteRel) node).distribution().function().affinity());
    assertThat(invalidPlanMsg, exchanges, hasSize(1));
    assertThat(invalidPlanMsg, exchanges.get(0).getInput(0), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, exchanges.get(0).getInput(0).getTable().unwrap(TestTable.class), equalTo(complexTbl));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteExchange(org.apache.ignite.internal.sql.engine.rel.IgniteExchange) Test(org.junit.jupiter.api.Test)

Example 10 with IgniteIndex

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

the class TableDmlPlannerTest method updateNotCachesNonDependentIndexScan.

/**
 * UpdateNotCachesNonDependentIndexScan.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void updateNotCachesNonDependentIndexScan() throws Exception {
    TestTable tbl = createTable("TEST", IgniteDistributions.random(), "VAL", Integer.class, "IDX_VAL", Integer.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(1), "IDX", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "update test set val = 2 * val where idx_val between 2 and 10";
    RelNode phys = physicalPlan(sql, schema, "LogicalTableScanConverterRule");
    assertNotNull(phys);
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, findFirstNode(phys, byClass(Spool.class)), nullValue());
    assertThat(invalidPlanMsg, findFirstNode(phys, byClass(IgniteIndexScan.class)), notNullValue());
}
Also used : IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteIndex (org.apache.ignite.internal.sql.engine.schema.IgniteIndex)12 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)11 Test (org.junit.jupiter.api.Test)11 RelNode (org.apache.calcite.rel.RelNode)8 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)5 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)5 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)4 IgniteMergeJoin (org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin)4 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RelCollations (org.apache.calcite.rel.RelCollations)2 Spool (org.apache.calcite.rel.core.Spool)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)2 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)2 IgniteAggregate (org.apache.ignite.internal.sql.engine.rel.IgniteAggregate)2 IgniteExchange (org.apache.ignite.internal.sql.engine.rel.IgniteExchange)2 IgniteTableModify (org.apache.ignite.internal.sql.engine.rel.IgniteTableModify)2 IgniteTableScan (org.apache.ignite.internal.sql.engine.rel.IgniteTableScan)2 IgniteDistributions (org.apache.ignite.internal.sql.engine.trait.IgniteDistributions)2