Search in sources :

Example 1 with IgniteIndex

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

the class PlannerTest method testMergeJoinIsNotAppliedForNonEquiJoin.

@Test
public void testMergeJoinIsNotAppliedForNonEquiJoin() 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(), 1000) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    };
    emp.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(1, 2)), "emp_idx", emp));
    TestTable dept = new TestTable(new RelDataTypeFactory.Builder(f).add("DEPTNO", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).build(), 100) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    };
    dept.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "dep_idx", dept));
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("EMP", emp);
    publicSchema.addTable("DEPT", dept);
    String sql = "select d.deptno, d.name, e.id, e.name from dept d join emp e " + "on d.deptno = e.deptno and e.name >= d.name order by e.name, d.deptno";
    RelNode phys = physicalPlan(sql, publicSchema, "CorrelatedNestedLoopJoin");
    assertNotNull(phys);
    assertEquals("IgniteSort(sort0=[$3], sort1=[$0], dir0=[ASC-nulls-first], dir1=[ASC-nulls-first])\n" + "  IgniteProject(DEPTNO=[$3], NAME=[$4], ID=[$0], NAME0=[$1])\n" + "    IgniteNestedLoopJoin(condition=[AND(=($3, $2), >=($1, $4))], joinType=[inner])\n" + "      IgniteTableScan(table=[[PUBLIC, EMP]])\n" + "      IgniteTableScan(table=[[PUBLIC, DEPT]])\n", RelOptUtil.toString(phys));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) Frameworks.newConfigBuilder(org.apache.calcite.tools.Frameworks.newConfigBuilder) 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 IgniteIndex

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

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

the class ProjectFilterScanMergePlannerTest method testIdentityFilterMergeIndex.

@Test
public void testIdentityFilterMergeIndex() throws Exception {
    // Test project and filter merge into index scan.
    TestTable tbl = ((TestTable) publicSchema.getTable("TBL"));
    tbl.addIndex(new IgniteIndex(RelCollations.of(2), "IDX_C", tbl));
    // Without index condition shift.
    assertPlan("SELECT a, b, c FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() == null).and(scan -> scan.condition() != null).and(scan -> "=($t2, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(0, 1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().upperCondition().toString())));
    // Index condition shift and identity.
    assertPlan("SELECT b, c FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() == null).and(scan -> scan.condition() != null).and(scan -> "=($t1, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().upperCondition().toString())));
}
Also used : RelCollations(org.apache.calcite.rel.RelCollations) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTableScan(org.apache.ignite.internal.sql.engine.rel.IgniteTableScan) IgniteDistributions(org.apache.ignite.internal.sql.engine.trait.IgniteDistributions) RelDataType(org.apache.calcite.rel.type.RelDataType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) Test(org.junit.jupiter.api.Test) TestInstance(org.junit.jupiter.api.TestInstance) IgniteTypeSystem(org.apache.ignite.internal.sql.engine.type.IgniteTypeSystem) BeforeAll(org.junit.jupiter.api.BeforeAll) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) Test(org.junit.jupiter.api.Test)

Example 4 with IgniteIndex

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

the class ProjectFilterScanMergePlannerTest method testProjectFilterMergeIndex.

@Test
public void testProjectFilterMergeIndex() throws Exception {
    // Test project and filter merge into index scan.
    TestTable tbl = ((TestTable) publicSchema.getTable("TBL"));
    tbl.addIndex(new IgniteIndex(RelCollations.of(2), "IDX_C", tbl));
    // Without index condition shift.
    assertPlan("SELECT a, b FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() != null).and(scan -> "[$t0, $t1]".equals(scan.projects().toString())).and(scan -> scan.condition() != null).and(scan -> "=($t2, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(0, 1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t2, 0)]".equals(scan.indexConditions().upperCondition().toString())));
    // Index condition shifted according to requiredColumns.
    assertPlan("SELECT b FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteIndexScan.class).and(scan -> scan.projects() != null).and(scan -> "[$t0]".equals(scan.projects().toString())).and(scan -> scan.condition() != null).and(scan -> "=($t1, 0)".equals(scan.condition().toString())).and(scan -> ImmutableBitSet.of(1, 2).equals(scan.requiredColumns())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().lowerCondition().toString())).and(scan -> "[=($t1, 0)]".equals(scan.indexConditions().upperCondition().toString())));
}
Also used : RelCollations(org.apache.calcite.rel.RelCollations) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTableScan(org.apache.ignite.internal.sql.engine.rel.IgniteTableScan) IgniteDistributions(org.apache.ignite.internal.sql.engine.trait.IgniteDistributions) RelDataType(org.apache.calcite.rel.type.RelDataType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) Test(org.junit.jupiter.api.Test) TestInstance(org.junit.jupiter.api.TestInstance) IgniteTypeSystem(org.apache.ignite.internal.sql.engine.type.IgniteTypeSystem) BeforeAll(org.junit.jupiter.api.BeforeAll) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) Test(org.junit.jupiter.api.Test)

Example 5 with IgniteIndex

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

IgniteIndex (org.apache.ignite.internal.sql.engine.schema.IgniteIndex)12 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)11 Test (org.junit.jupiter.api.Test)11 RelNode (org.apache.calcite.rel.RelNode)8 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)5 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)5 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)4 IgniteMergeJoin (org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin)4 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RelCollations (org.apache.calcite.rel.RelCollations)2 Spool (org.apache.calcite.rel.core.Spool)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)2 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)2 IgniteAggregate (org.apache.ignite.internal.sql.engine.rel.IgniteAggregate)2 IgniteExchange (org.apache.ignite.internal.sql.engine.rel.IgniteExchange)2 IgniteTableModify (org.apache.ignite.internal.sql.engine.rel.IgniteTableModify)2 IgniteTableScan (org.apache.ignite.internal.sql.engine.rel.IgniteTableScan)2 IgniteDistributions (org.apache.ignite.internal.sql.engine.trait.IgniteDistributions)2