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());
}
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));
}
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));
}
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));
}
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());
}
Aggregations