use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.
the class TableSpoolPlannerTest method tableSpoolDistributed.
/**
* TableSpoolDistributed.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @throws Exception If failed.
*/
@Test
public void tableSpoolDistributed() throws Exception {
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
TestTable t0 = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "T0", "hash");
}
};
TestTable t1 = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "T1", "hash");
}
};
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("T0", t0);
publicSchema.addTable("T1", t1);
String sql = "select * " + "from t0 " + "join t1 on t0.jid > t1.jid";
IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeRule");
assertNotNull(phys);
IgniteTableSpool tblSpool = findFirstNode(phys, byClass(IgniteTableSpool.class));
assertNotNull(tblSpool, "Invalid plan:\n" + RelOptUtil.toString(phys));
checkSplitAndSerialization(phys, publicSchema);
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.
the class UnionPlannerTest method testUnionAll.
@Test
public void testUnionAll() throws Exception {
IgniteSchema publicSchema = prepareSchema();
String sql = "" + "SELECT * FROM table1 " + "UNION ALL " + "SELECT * FROM table2 " + "UNION ALL " + "SELECT * FROM table3 ";
assertPlan(sql, publicSchema, isInstanceOf(IgniteUnionAll.class).and(input(0, hasChildThat(isTableScan("TABLE1")))).and(input(1, hasChildThat(isTableScan("TABLE2")))).and(input(2, hasChildThat(isTableScan("TABLE3")))));
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.
the class UnionPlannerTest method testUnion.
@Test
public void testUnion() throws Exception {
IgniteSchema publicSchema = prepareSchema();
String sql = "" + "SELECT * FROM table1 " + "UNION " + "SELECT * FROM table2 " + "UNION " + "SELECT * FROM table3 ";
assertPlan(sql, publicSchema, isInstanceOf(IgniteReduceAggregateBase.class).and(hasChildThat(isInstanceOf(Union.class))));
assertPlan(sql, publicSchema, isInstanceOf(IgniteReduceAggregateBase.class).and(hasChildThat(isInstanceOf(Union.class).and(input(0, isTableScan("TABLE1"))).and(input(1, isTableScan("TABLE2"))).and(input(2, isTableScan("TABLE3"))))));
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.
the class PlannerTest method testSplitterColocatedReplicatedReplicated.
@Test
public void testSplitterColocatedReplicatedReplicated() 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, 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.forNodes(select(NODES, 0, 1, 2, 3));
}
@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.id + 1) as id2, 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 " + "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(1, plan.fragments().size());
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.
the class PlannerTest method testSplitterPartiallyColocatedReplicatedAndPartitioned.
@Test
public void testSplitterPartiallyColocatedReplicatedAndPartitioned() 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, 2), select(NODES, 2, 3), select(NODES, 3, 0), select(NODES, 0, 1)));
}
@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 " + "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());
}
Aggregations