use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.
the class PlannerTest method testMergeJoinIsNotAppliedForNonEquiJoin.
@Test
public void testMergeJoinIsNotAppliedForNonEquiJoin() throws Exception {
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
TestTable emp = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).add("DEPTNO", f.createJavaType(Integer.class)).build(), 1000) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
emp.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(1, 2)), "emp_idx", emp));
TestTable dept = new TestTable(new RelDataTypeFactory.Builder(f).add("DEPTNO", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).build(), 100) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
dept.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "dep_idx", dept));
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("EMP", emp);
publicSchema.addTable("DEPT", dept);
String sql = "select d.deptno, d.name, e.id, e.name from dept d join emp e " + "on d.deptno = e.deptno and e.name >= d.name order by e.name, d.deptno";
RelNode phys = physicalPlan(sql, publicSchema, "CorrelatedNestedLoopJoin");
assertNotNull(phys);
assertEquals("IgniteSort(sort0=[$3], sort1=[$0], dir0=[ASC-nulls-first], dir1=[ASC-nulls-first])\n" + " IgniteProject(DEPTNO=[$3], NAME=[$4], ID=[$0], NAME0=[$1])\n" + " IgniteNestedLoopJoin(condition=[AND(=($3, $2), >=($1, $4))], joinType=[inner])\n" + " IgniteTableScan(table=[[PUBLIC, EMP]])\n" + " IgniteTableScan(table=[[PUBLIC, DEPT]])\n", RelOptUtil.toString(phys));
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.
the class PlannerTest method testSplitterColocatedPartitionedPartitioned.
@Test
public void testSplitterColocatedPartitionedPartitioned() throws Exception {
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
TestTable developer = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).add("PROJECTID", f.createJavaType(Integer.class)).build()) {
@Override
public IgniteIndex getIndex(String idxName) {
return new IgniteIndex(null, null, null);
}
@Override
public ColocationGroup colocationGroup(MappingQueryContext ctx) {
return ColocationGroup.forAssignments(Arrays.asList(select(NODES, 0, 1), select(NODES, 1, 2), select(NODES, 2, 0), select(NODES, 0, 1), select(NODES, 1, 2)));
}
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "Developer", "hash");
}
};
TestTable project = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).add("VER", f.createJavaType(Integer.class)).build()) {
@Override
public ColocationGroup colocationGroup(MappingQueryContext ctx) {
return ColocationGroup.forAssignments(Arrays.asList(select(NODES, 0, 1), select(NODES, 1, 2), select(NODES, 2, 0), select(NODES, 0, 1), select(NODES, 1, 2)));
}
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "Project", "hash");
}
};
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("DEVELOPER", developer);
publicSchema.addTable("PROJECT", project);
SchemaPlus schema = createRootSchema(false).add("PUBLIC", publicSchema);
String sql = "SELECT d.id, d.name, d.projectId, p.id0, p.ver0 " + "FROM PUBLIC.Developer d JOIN (" + "SELECT pp.id as id0, pp.ver as ver0 FROM PUBLIC.Project pp" + ") p " + "ON d.id = p.id0";
PlanningContext ctx = PlanningContext.builder().parentContext(BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).build()).build()).query(sql).parameters(2).build();
assertNotNull(ctx);
IgniteRel phys = physicalPlan(sql, ctx);
assertNotNull(phys);
MultiStepPlan plan = new MultiStepQueryPlan(new QueryTemplate(new Splitter().go(phys)), null);
assertNotNull(plan);
plan.init(this::intermediateMapping, mapContext(CollectionUtils.first(NODES), 0L));
assertNotNull(plan);
assertEquals(2, plan.fragments().size());
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.
the class ProjectFilterScanMergePlannerTest method testIdentityFilterMergeIndex.
@Test
public void testIdentityFilterMergeIndex() throws Exception {
// Test project and filter merge into index scan.
TestTable tbl = ((TestTable) publicSchema.getTable("TBL"));
tbl.addIndex(new IgniteIndex(RelCollations.of(2), "IDX_C", tbl));
// Without index condition shift.
assertPlan("SELECT a, b, c FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() == null).and(scan -> scan.condition() != null).and(scan -> "=($t2, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(0, 1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().upperCondition().toString())));
// Index condition shift and identity.
assertPlan("SELECT b, c FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() == null).and(scan -> scan.condition() != null).and(scan -> "=($t1, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().upperCondition().toString())));
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.
the class ProjectFilterScanMergePlannerTest method testProjectFilterMergeIndex.
@Test
public void testProjectFilterMergeIndex() throws Exception {
// Test project and filter merge into index scan.
TestTable tbl = ((TestTable) publicSchema.getTable("TBL"));
tbl.addIndex(new IgniteIndex(RelCollations.of(2), "IDX_C", tbl));
// Without index condition shift.
assertPlan("SELECT a, b FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() != null).and(scan -> "[$t0, $t1]".equals(scan.projects().toString())).and(scan -> scan.condition() != null).and(scan -> "=($t2, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(0, 1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().upperCondition().toString())));
// Index condition shifted according to requiredColumns.
assertPlan("SELECT b FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() != null).and(scan -> "[$t0]".equals(scan.projects().toString())).and(scan -> scan.condition() != null).and(scan -> "=($t1, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().upperCondition().toString())));
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.
the class JoinColocationPlannerTest method joinComplexToComplexAffWithDifferentOrder.
/**
* Re-hashing for complex affinity is not supported.
*/
@Test
public void joinComplexToComplexAffWithDifferentOrder() throws Exception {
TestTable complexTblDirect = createTable("COMPLEX_TBL_DIRECT", IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
complexTblDirect.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTblDirect));
TestTable complexTblIndirect = createTable("COMPLEX_TBL_INDIRECT", IgniteDistributions.affinity(ImmutableIntList.of(1, 0), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
complexTblIndirect.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTblIndirect));
IgniteSchema schema = createSchema(complexTblDirect, complexTblIndirect);
String sql = "select count(*) " + "from COMPLEX_TBL_DIRECT t1 " + "join COMPLEX_TBL_INDIRECT t2 on t1.id1 = t2.id1 and t1.id2 = t2.id2";
RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
IgniteMergeJoin exchange = findFirstNode(phys, node -> node instanceof IgniteExchange && ((IgniteRel) node).distribution().function().affinity());
String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
assertThat(invalidPlanMsg, exchange, nullValue());
}
Aggregations