Search in sources :

Example 11 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema 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 12 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class ProjectFilterScanMergePlannerTest method setup.

/**
 * {@inheritDoc}
 */
@BeforeAll
public void setup() {
    publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    RelDataType type = new RelDataTypeFactory.Builder(f).add("A", f.createSqlType(SqlTypeName.INTEGER)).add("B", f.createSqlType(SqlTypeName.INTEGER)).add("C", f.createSqlType(SqlTypeName.INTEGER)).build();
    createTable(publicSchema, "TBL", type, IgniteDistributions.single());
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 13 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class SetOpPlannerTest method setup.

/**
 * Setup.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@BeforeAll
public void setup() {
    publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    RelDataType type = new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).add("SALARY", f.createJavaType(Double.class)).build();
    createTable(publicSchema, "RANDOM_TBL1", type, IgniteDistributions.random());
    createTable(publicSchema, "RANDOM_TBL2", type, IgniteDistributions.random());
    createTable(publicSchema, "BROADCAST_TBL1", type, IgniteDistributions.broadcast());
    createTable(publicSchema, "BROADCAST_TBL2", type, IgniteDistributions.broadcast());
    createTable(publicSchema, "SINGLE_TBL1", type, IgniteDistributions.single());
    createTable(publicSchema, "SINGLE_TBL2", type, IgniteDistributions.single());
    createTable(publicSchema, "AFFINITY_TBL1", type, IgniteDistributions.affinity(0, "Test1", "hash"));
    createTable(publicSchema, "AFFINITY_TBL2", type, IgniteDistributions.affinity(0, "Test2", "hash"));
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 14 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.

the class SortAggregatePlannerTest method collationPermuteSingle.

/**
 * CollationPermuteSingle.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void collationPermuteSingle() throws Exception {
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    TestTable tbl = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("VAL0", f.createJavaType(Integer.class)).add("VAL1", f.createJavaType(Integer.class)).add("GRP0", f.createJavaType(Integer.class)).add("GRP1", f.createJavaType(Integer.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(3, 4)), "grp0_1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT MIN(val0) FROM test GROUP BY grp1, grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, "HashSingleAggregateConverterRule", "HashMapReduceAggregateConverterRule");
    IgniteSingleSortAggregate agg = findFirstNode(phys, byClass(IgniteSingleSortAggregate.class));
    assertNotNull(agg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertNull(findFirstNode(phys, byClass(IgniteSort.class)), "Invalid plan\n" + RelOptUtil.toString(phys));
}
Also used : IgniteSingleSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleSortAggregate) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteDistribution(org.apache.ignite.internal.sql.engine.trait.IgniteDistribution) Test(org.junit.jupiter.api.Test)

Example 15 with IgniteSchema

use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema 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());
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteExchange(org.apache.ignite.internal.sql.engine.rel.IgniteExchange) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)115 Test (org.junit.jupiter.api.Test)105 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)93 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)66 IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)42 RelCollation (org.apache.calcite.rel.RelCollation)33 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)28 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)20 RelNode (org.apache.calcite.rel.RelNode)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 IgniteIndex (org.apache.ignite.internal.sql.engine.schema.IgniteIndex)9 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)9 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)7 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)7 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)7 RexNode (org.apache.calcite.rex.RexNode)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