Search in sources :

Example 1 with IgniteRel

use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.

the class MergeJoinPlannerTest method testLeftPassThroughOrderByRight1.

/**
 * Test verifies the collation propagation from a parent node.
 *
 * <p>In case of left join, collation consisted of join keys of right table can't be propagated.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void testLeftPassThroughOrderByRight1() 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 " + "  left join RIGHT_T " + "    on LEFT_T.c1 = RIGHT_T.c1 " + "   and LEFT_T.c2 = RIGHT_T.c2 " + " order by RIGHT_T.c1, RIGHT_T.c2";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    assertEquals(RelCollations.of(new RelFieldCollation(3, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(4, ASCENDING, RelFieldCollation.NullDirection.FIRST)), sortOnTopOfJoin(rel).collation());
    List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
    RelCollation expected = RelCollations.of(new RelFieldCollation(0, ASCENDING), new RelFieldCollation(1, ASCENDING));
    assertEquals(expected, sortNodes.get(0).collation());
    assertEquals(expected, sortNodes.get(1).collation());
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 2 with IgniteRel

use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.

the class MergeJoinPlannerTest method testInnerPassThroughOrderByLeft10.

/**
 * 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 testInnerPassThroughOrderByLeft10() 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 ASC NULLS FIRST, LEFT_T.c2 ASC NULLS LAST, LEFT_T.c3 ASC NULLS FIRST";
    IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
    assertNull(sortOnTopOfJoin(rel));
    List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING), new RelFieldCollation(2, ASCENDING, RelFieldCollation.NullDirection.FIRST)), sortNodes.get(0).collation());
    assertEquals(RelCollations.of(new RelFieldCollation(0, ASCENDING, RelFieldCollation.NullDirection.FIRST), new RelFieldCollation(1, ASCENDING)), sortNodes.get(1).collation());
}
Also used : IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 3 with IgniteRel

use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.

the class PlannerTest method testNotStandardFunctions.

@Test
public void testNotStandardFunctions() throws Exception {
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    publicSchema.addTable("TEST", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "TEST", "hash");
        }
    });
    String[] queries = { // MYSQL
    "select REVERSE(val) from TEST", // ORACLE
    "select TO_DATE(val, 'yyyymmdd') from TEST" };
    for (String sql : queries) {
        IgniteRel phys = physicalPlan(sql, publicSchema);
        checkSplitAndSerialization(phys, publicSchema);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) 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 4 with IgniteRel

use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.

the class PlannerTest method testJoinPushExpressionRule.

@Test
public void testJoinPushExpressionRule() 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()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    };
    TestTable dept = new TestTable(new RelDataTypeFactory.Builder(f).add("DEPTNO", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.broadcast();
        }
    };
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("EMP", emp);
    publicSchema.addTable("DEPT", dept);
    SchemaPlus schema = createRootSchema(false).add("PUBLIC", publicSchema);
    String sql = "select d.deptno, e.deptno " + "from dept d, emp e " + "where d.deptno + e.deptno = 2";
    PlanningContext ctx = PlanningContext.builder().parentContext(BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).costFactory(new IgniteCostFactory(1, 100, 1, 1)).build()).build()).query(sql).build();
    RelRoot relRoot;
    try (IgnitePlanner planner = ctx.planner()) {
        assertNotNull(planner);
        String qry = ctx.query();
        assertNotNull(qry);
        // Parse
        SqlNode sqlNode = planner.parse(qry);
        // Validate
        sqlNode = planner.validate(sqlNode);
        // Convert to Relational operators graph
        relRoot = planner.rel(sqlNode);
        RelNode rel = relRoot.rel;
        assertNotNull(rel);
        assertEquals("LogicalProject(DEPTNO=[$0], DEPTNO0=[$4])\n" + "  LogicalFilter(condition=[=(CAST(+($0, $4)):INTEGER, 2)])\n" + "    LogicalJoin(condition=[true], joinType=[inner])\n" + "      IgniteLogicalTableScan(table=[[PUBLIC, DEPT]])\n" + "      IgniteLogicalTableScan(table=[[PUBLIC, EMP]])\n", RelOptUtil.toString(rel));
        // Transformation chain
        RelTraitSet desired = rel.getCluster().traitSet().replace(IgniteConvention.INSTANCE).replace(IgniteDistributions.single()).replace(CorrelationTrait.UNCORRELATED).simplify();
        IgniteRel phys = planner.transform(PlannerPhase.OPTIMIZATION, desired, rel);
        assertNotNull(phys);
        assertEquals("IgniteProject(DEPTNO=[$3], DEPTNO0=[$2])\n" + "  IgniteCorrelatedNestedLoopJoin(condition=[=(CAST(+($3, $2)):INTEGER, 2)], joinType=[inner], " + "correlationVariables=[[$cor2]])\n" + "    IgniteTableScan(table=[[PUBLIC, EMP]])\n" + "    IgniteTableScan(table=[[PUBLIC, DEPT]], filters=[=(CAST(+($t0, $cor2.DEPTNO)):INTEGER, 2)])\n", RelOptUtil.toString(phys), "Invalid plan:\n" + RelOptUtil.toString(phys));
        checkSplitAndSerialization(phys, publicSchema);
    }
}
Also used : IgniteCostFactory(org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCostFactory) PlanningContext(org.apache.ignite.internal.sql.engine.prepare.PlanningContext) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) Frameworks.newConfigBuilder(org.apache.calcite.tools.Frameworks.newConfigBuilder) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) SchemaPlus(org.apache.calcite.schema.SchemaPlus) RelRoot(org.apache.calcite.rel.RelRoot) RelTraitSet(org.apache.calcite.plan.RelTraitSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgnitePlanner(org.apache.ignite.internal.sql.engine.prepare.IgnitePlanner) RelNode(org.apache.calcite.rel.RelNode) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.jupiter.api.Test)

Example 5 with IgniteRel

use of org.apache.ignite.internal.sql.engine.rel.IgniteRel 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)

Aggregations

IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)102 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)93 Test (org.junit.jupiter.api.Test)89 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)64 IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)39 RelCollation (org.apache.calcite.rel.RelCollation)33 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)19 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)16 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)7 RexNode (org.apache.calcite.rex.RexNode)7 SchemaPlus (org.apache.calcite.schema.SchemaPlus)7 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)7 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 QueryTemplate (org.apache.ignite.internal.sql.engine.prepare.QueryTemplate)6 Splitter (org.apache.ignite.internal.sql.engine.prepare.Splitter)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6