Search in sources :

Example 1 with Splitter

use of org.apache.ignite.internal.sql.engine.prepare.Splitter 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());
}
Also used : QueryTemplate(org.apache.ignite.internal.sql.engine.prepare.QueryTemplate) MappingQueryContext(org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) Splitter(org.apache.ignite.internal.sql.engine.prepare.Splitter) MultiStepPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) SchemaPlus(org.apache.calcite.schema.SchemaPlus) MultiStepQueryPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 2 with Splitter

use of org.apache.ignite.internal.sql.engine.prepare.Splitter 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());
}
Also used : QueryTemplate(org.apache.ignite.internal.sql.engine.prepare.QueryTemplate) MappingQueryContext(org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) Splitter(org.apache.ignite.internal.sql.engine.prepare.Splitter) MultiStepPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) SchemaPlus(org.apache.calcite.schema.SchemaPlus) MultiStepQueryPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 3 with Splitter

use of org.apache.ignite.internal.sql.engine.prepare.Splitter 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());
}
Also used : QueryTemplate(org.apache.ignite.internal.sql.engine.prepare.QueryTemplate) MappingQueryContext(org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) Splitter(org.apache.ignite.internal.sql.engine.prepare.Splitter) MultiStepPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) SchemaPlus(org.apache.calcite.schema.SchemaPlus) MultiStepQueryPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 4 with Splitter

use of org.apache.ignite.internal.sql.engine.prepare.Splitter 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());
}
Also used : QueryTemplate(org.apache.ignite.internal.sql.engine.prepare.QueryTemplate) MappingQueryContext(org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) Splitter(org.apache.ignite.internal.sql.engine.prepare.Splitter) MultiStepPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) SchemaPlus(org.apache.calcite.schema.SchemaPlus) MultiStepQueryPlan(org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 5 with Splitter

use of org.apache.ignite.internal.sql.engine.prepare.Splitter in project ignite-3 by apache.

the class AbstractPlannerTest method checkSplitAndSerialization.

protected void checkSplitAndSerialization(IgniteRel rel, IgniteSchema publicSchema) {
    assertNotNull(rel);
    rel = Cloner.clone(rel);
    List<Fragment> fragments = new Splitter().go(rel);
    List<String> serialized = new ArrayList<>(fragments.size());
    for (Fragment fragment : fragments) {
        serialized.add(toJson(fragment.root()));
    }
    assertNotNull(serialized);
    List<String> nodes = new ArrayList<>(4);
    for (int i = 0; i < 4; i++) {
        nodes.add(UUID.randomUUID().toString());
    }
    List<RelNode> deserializedNodes = new ArrayList<>();
    Map<UUID, IgniteTable> tableMap = publicSchema.getTableNames().stream().map(publicSchema::getTable).map(IgniteTable.class::cast).collect(Collectors.toMap(IgniteTable::id, Function.identity()));
    for (String s : serialized) {
        RelJsonReader reader = new RelJsonReader(new SqlSchemaManagerImpl(tableMap));
        deserializedNodes.add(reader.read(s));
    }
    List<RelNode> expectedRels = fragments.stream().map(Fragment::root).collect(Collectors.toList());
    assertEquals(expectedRels.size(), deserializedNodes.size(), "Invalid deserialization fragments count");
    for (int i = 0; i < expectedRels.size(); ++i) {
        RelNode expected = expectedRels.get(i);
        RelNode deserialized = deserializedNodes.get(i);
        clearTraits(expected);
        clearTraits(deserialized);
        if (!expected.deepEquals(deserialized)) {
            assertTrue(expected.deepEquals(deserialized), "Invalid serialization / deserialization.\n" + "Expected:\n" + RelOptUtil.toString(expected) + "Deserialized:\n" + RelOptUtil.toString(deserialized));
        }
    }
}
Also used : Splitter(org.apache.ignite.internal.sql.engine.prepare.Splitter) IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) ArrayList(java.util.ArrayList) Fragment(org.apache.ignite.internal.sql.engine.prepare.Fragment) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint) AbstractRelNode(org.apache.calcite.rel.AbstractRelNode) RelNode(org.apache.calcite.rel.RelNode) RelJsonReader(org.apache.ignite.internal.sql.engine.externalize.RelJsonReader) UUID(java.util.UUID)

Aggregations

Splitter (org.apache.ignite.internal.sql.engine.prepare.Splitter)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)6 SchemaPlus (org.apache.calcite.schema.SchemaPlus)6 MappingQueryContext (org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext)6 MultiStepPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan)6 MultiStepQueryPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan)6 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)6 QueryTemplate (org.apache.ignite.internal.sql.engine.prepare.QueryTemplate)6 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)6 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)6 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)6 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 AbstractRelNode (org.apache.calcite.rel.AbstractRelNode)1 RelNode (org.apache.calcite.rel.RelNode)1 RelReferentialConstraint (org.apache.calcite.rel.RelReferentialConstraint)1 RelJsonReader (org.apache.ignite.internal.sql.engine.externalize.RelJsonReader)1 Fragment (org.apache.ignite.internal.sql.engine.prepare.Fragment)1