use of org.apache.ignite.internal.sql.engine.rel.IgniteRel 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());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft14.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of inner join, collation that is subset of join keys should be propagated as is.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testInnerPassThroughOrderByLeft14() throws Exception {
IgniteSchema schema = createSchema(createTable("LEFT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class), createTable("RIGHT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class));
String sql = "" + "select * " + " from LEFT_T " + " join RIGHT_T " + " on LEFT_T.c1 = RIGHT_T.c1 " + " and LEFT_T.c2 = RIGHT_T.c2 " + " and LEFT_T.c3 = RIGHT_T.c3 " + " order by LEFT_T.c1 DESC, LEFT_T.c2 ASC";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfJoin(rel));
List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
RelCollation expected = RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(1, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(2, ASCENDING));
assertEquals(expected, sortNodes.get(0).collation());
assertEquals(expected, sortNodes.get(1).collation());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class MergeJoinPlannerTest method testRightPassThroughOrderByRight5.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of right join, collation consisted of join keys only should be propagated as is.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testRightPassThroughOrderByRight5() throws Exception {
IgniteSchema schema = createSchema(createTable("LEFT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class), createTable("RIGHT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class));
String sql = "" + "select * " + " from LEFT_T " + " right join RIGHT_T " + " on LEFT_T.c1 = RIGHT_T.c1 " + " and LEFT_T.c2 = RIGHT_T.c2 " + " order by RIGHT_T.c1 ASC NULLS FIRST, RIGHT_T.c2 ASC NULLS LAST";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfJoin(rel));
List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
RelCollation expected = RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING));
assertEquals(expected, sortNodes.get(0).collation());
assertEquals(expected, sortNodes.get(1).collation());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class MergeJoinPlannerTest method testInnerDerivePreserveRight9.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of inner join, right collation that is superset of join keys could be derived as is.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testInnerDerivePreserveRight9() throws Exception {
TestTable right = createTable("RIGHT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class);
right.addIndex(RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(2, ASCENDING, RelFieldCollation.NullDirection.FIRST)), "idx");
IgniteSchema schema = createSchema(createTable("LEFT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class), right);
String sql = "" + "select * " + " from LEFT_T " + " join RIGHT_T " + " on LEFT_T.c1 = RIGHT_T.c1 " + " and LEFT_T.c2 = RIGHT_T.c2 ";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfScan(rel, "RIGHT_T"));
assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING, RelFieldCollation.NullDirection.FIRST)), sortOnTopOfScan(rel, "LEFT_T").collation());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft7.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of inner join, collation that is superset of join keys should be propagated as is, if it doesn't include fields from right
* table.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testInnerPassThroughOrderByLeft7() throws Exception {
IgniteSchema schema = createSchema(createTable("LEFT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class), createTable("RIGHT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class));
String sql = "" + "select * " + " from LEFT_T " + " join RIGHT_T " + " on LEFT_T.c1 = RIGHT_T.c1 " + " and LEFT_T.c2 = RIGHT_T.c2 " + " order by LEFT_T.c1 DESC, LEFT_T.c2 DESC, LEFT_T.c3 DESC";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfJoin(rel));
List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
assertEquals(RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(1, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(2, DESCENDING, RelFieldCollation.NullDirection.LAST)), sortNodes.get(0).collation());
assertEquals(RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(1, DESCENDING, RelFieldCollation.NullDirection.LAST)), sortNodes.get(1).collation());
}
Aggregations