use of org.apache.ignite.internal.sql.engine.prepare.PlanningContext in project ignite-3 by apache.
the class PlannerTest method testJoinPushExpressionRule.
@Test
public void testJoinPushExpressionRule() 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()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
TestTable dept = new TestTable(new RelDataTypeFactory.Builder(f).add("DEPTNO", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("EMP", emp);
publicSchema.addTable("DEPT", dept);
SchemaPlus schema = createRootSchema(false).add("PUBLIC", publicSchema);
String sql = "select d.deptno, e.deptno " + "from dept d, emp e " + "where d.deptno + e.deptno = 2";
PlanningContext ctx = PlanningContext.builder().parentContext(BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).costFactory(new IgniteCostFactory(1, 100, 1, 1)).build()).build()).query(sql).build();
RelRoot relRoot;
try (IgnitePlanner planner = ctx.planner()) {
assertNotNull(planner);
String qry = ctx.query();
assertNotNull(qry);
// Parse
SqlNode sqlNode = planner.parse(qry);
// Validate
sqlNode = planner.validate(sqlNode);
// Convert to Relational operators graph
relRoot = planner.rel(sqlNode);
RelNode rel = relRoot.rel;
assertNotNull(rel);
assertEquals("LogicalProject(DEPTNO=[$0], DEPTNO0=[$4])\n" + " LogicalFilter(condition=[=(CAST(+($0, $4)):INTEGER, 2)])\n" + " LogicalJoin(condition=[true], joinType=[inner])\n" + " IgniteLogicalTableScan(table=[[PUBLIC, DEPT]])\n" + " IgniteLogicalTableScan(table=[[PUBLIC, EMP]])\n", RelOptUtil.toString(rel));
// Transformation chain
RelTraitSet desired = rel.getCluster().traitSet().replace(IgniteConvention.INSTANCE).replace(IgniteDistributions.single()).replace(CorrelationTrait.UNCORRELATED).simplify();
IgniteRel phys = planner.transform(PlannerPhase.OPTIMIZATION, desired, rel);
assertNotNull(phys);
assertEquals("IgniteProject(DEPTNO=[$3], DEPTNO0=[$2])\n" + " IgniteCorrelatedNestedLoopJoin(condition=[=(CAST(+($3, $2)):INTEGER, 2)], joinType=[inner], " + "correlationVariables=[[$cor2]])\n" + " IgniteTableScan(table=[[PUBLIC, EMP]])\n" + " IgniteTableScan(table=[[PUBLIC, DEPT]], filters=[=(CAST(+($t0, $cor2.DEPTNO)):INTEGER, 2)])\n", RelOptUtil.toString(phys), "Invalid plan:\n" + RelOptUtil.toString(phys));
checkSplitAndSerialization(phys, publicSchema);
}
}
use of org.apache.ignite.internal.sql.engine.prepare.PlanningContext in project ignite-3 by apache.
the class PlannerTest method testSplitterNonColocated.
@Test
public void testSplitterNonColocated() 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 ColocationGroup colocationGroup(MappingQueryContext ctx) {
return ColocationGroup.forNodes(select(NODES, 2));
}
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
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.forNodes(select(NODES, 0, 1));
}
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
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.projectId = p.ver0 " + "WHERE (d.projectId + 1) > ?";
PlanningContext ctx = PlanningContext.builder().parentContext(BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).build()).build()).query(sql).parameters(2).build();
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.prepare.PlanningContext in project ignite-3 by apache.
the class PlannerTest method testSplitterPartiallyColocated2.
@Test
public void testSplitterPartiallyColocated2() 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 ColocationGroup colocationGroup(MappingQueryContext ctx) {
return ColocationGroup.forNodes(select(NODES, 0));
}
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
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, 1), select(NODES, 2), select(NODES, 3)));
}
@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.projectId = p.id0 " + "WHERE (d.projectId + 1) > ?";
PlanningContext ctx = PlanningContext.builder().parentContext(BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).build()).build()).query(sql).parameters(2).build();
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));
assertEquals(3, plan.fragments().size());
}
use of org.apache.ignite.internal.sql.engine.prepare.PlanningContext in project ignite-3 by apache.
the class PlannerTest method testSplitterPartiallyColocated1.
@Test
public void testSplitterPartiallyColocated1() 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 ColocationGroup colocationGroup(MappingQueryContext ctx) {
return ColocationGroup.forNodes(select(NODES, 1, 2, 3));
}
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
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), select(NODES, 1), select(NODES, 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.projectId = p.id0 " + "WHERE (d.projectId + 1) > ?";
PlanningContext ctx = PlanningContext.builder().parentContext(BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).build()).build()).query(sql).parameters(2).build();
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(3, plan.fragments().size());
}
use of org.apache.ignite.internal.sql.engine.prepare.PlanningContext 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());
}
Aggregations