Search in sources :

Example 1 with PlanningContext

use of org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext in project ignite by apache.

the class PlannerTest method testSplitterNonColocated.

/**
 * @throws Exception If failed.
 */
@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 p.id0, d.id " + "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(ctx);
    assertNotNull(phys);
    MultiStepPlan plan = new MultiStepQueryPlan(new QueryTemplate(new Splitter().go(phys)), null);
    assertNotNull(plan);
    plan.init(this::intermediateMapping, Commons.mapContext(F.first(nodes), AffinityTopologyVersion.NONE));
    assertNotNull(plan);
    assertEquals(2, plan.fragments().size());
}
Also used : QueryTemplate(org.apache.ignite.internal.processors.query.calcite.prepare.QueryTemplate) MappingQueryContext(org.apache.ignite.internal.processors.query.calcite.prepare.MappingQueryContext) PlanningContext(org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext) Splitter(org.apache.ignite.internal.processors.query.calcite.prepare.Splitter) MultiStepPlan(org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepPlan) IgniteTypeFactory(org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel) SchemaPlus(org.apache.calcite.schema.SchemaPlus) MultiStepQueryPlan(org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepQueryPlan) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema) Test(org.junit.Test)

Example 2 with PlanningContext

use of org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext in project ignite by apache.

the class PlannerTest method testPhysicalPlan.

/**
 * @throws Exception If failed.
 */
@Test
public void testPhysicalPlan() throws Exception {
    executors = new ArrayList<>();
    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 <Row> Iterable<Row> scan(ExecutionContext<Row> execCtx, ColocationGroup group, Predicate<Row> filter, Function<Row, Row> transformer, ImmutableBitSet requiredColumns) {
            return Arrays.asList(row(execCtx, requiredColumns, 0, "Igor", 0), row(execCtx, requiredColumns, 1, "Roman", 0));
        }

        @Override
        public ColocationGroup colocationGroup(MappingQueryContext ctx) {
            return ColocationGroup.forNodes(select(nodes, 1));
        }

        @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 <Row> Iterable<Row> scan(ExecutionContext<Row> execCtx, ColocationGroup group, Predicate<Row> filter, Function<Row, Row> transformer, ImmutableBitSet requiredColumns) {
            return Arrays.asList(row(execCtx, requiredColumns, 0, "Calcite", 1), row(execCtx, requiredColumns, 1, "Ignite", 1));
        }

        @Override
        public ColocationGroup colocationGroup(MappingQueryContext ctx) {
            return ColocationGroup.forNodes(select(nodes, 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.name0, p.ver0 " + "FROM PUBLIC.Developer d JOIN (" + "SELECT pp.id as id0, pp.name as name0, pp.ver as ver0 FROM PUBLIC.Project pp" + ") p " + "ON d.projectId = p.id0 " + "WHERE (d.projectId + 1) > ?";
    BaseQueryContext qctx = BaseQueryContext.builder().logger(log).frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG).defaultSchema(schema).build()).build();
    PlanningContext ctx = PlanningContext.builder().parentContext(qctx).query(sql).parameters(-10).build();
    IgniteRel phys = physicalPlan(ctx);
    assertNotNull(phys);
    MultiStepPlan plan = new MultiStepQueryPlan(new QueryTemplate(new Splitter().go(phys)), null);
    assertNotNull(plan);
    plan.init(this::intermediateMapping, Commons.mapContext(F.first(nodes), AffinityTopologyVersion.NONE));
    List<Fragment> fragments = plan.fragments();
    assertEquals(2, fragments.size());
    UUID qryId = UUID.randomUUID();
    TestIoManager mgr = new TestIoManager();
    GridTestKernalContext kernal;
    QueryTaskExecutorImpl taskExecutor;
    MessageServiceImpl msgSvc;
    MailboxRegistryImpl mailboxRegistry;
    ExchangeServiceImpl exchangeSvc;
    ExecutionContext<Object[]> ectx;
    Node<Object[]> exec;
    // // Local part
    Fragment fragment = fragments.get(0);
    assert fragment.rootFragment();
    kernal = newContext();
    taskExecutor = new QueryTaskExecutorImpl(kernal);
    taskExecutor.stripedThreadPoolExecutor(new IgniteStripedThreadPoolExecutor(kernal.config().getQueryThreadPoolSize(), kernal.igniteInstanceName(), "calciteQry", (t, ex) -> {
        log().error(ex.getMessage(), ex);
        lastE = ex;
    }, true, DFLT_THREAD_KEEP_ALIVE_TIME));
    executors.add(taskExecutor);
    msgSvc = new TestMessageServiceImpl(kernal, mgr);
    msgSvc.localNodeId(nodes.get(0));
    msgSvc.taskExecutor(taskExecutor);
    mgr.register(msgSvc);
    mailboxRegistry = new MailboxRegistryImpl(kernal);
    exchangeSvc = new ExchangeServiceImpl(kernal);
    exchangeSvc.taskExecutor(taskExecutor);
    exchangeSvc.messageService(msgSvc);
    exchangeSvc.mailboxRegistry(mailboxRegistry);
    exchangeSvc.queryRegistry(new QueryRegistryImpl(kernal));
    exchangeSvc.init();
    ectx = new ExecutionContext<>(qctx, taskExecutor, qryId, F.first(nodes), F.first(nodes), AffinityTopologyVersion.NONE, new FragmentDescription(fragment.fragmentId(), fragment.mapping(), plan.target(fragment), plan.remotes(fragment)), ArrayRowHandler.INSTANCE, Commons.parametersMap(ctx.parameters()));
    exec = new LogicalRelImplementor<>(ectx, c1 -> r1 -> 0, mailboxRegistry, exchangeSvc, new TestFailureProcessor(kernal)).go(fragment.root());
    RootNode<Object[]> consumer = new RootNode<>(ectx, exec.rowType());
    consumer.register(exec);
    // // Remote part
    fragment = fragments.get(1);
    assert !fragment.rootFragment();
    kernal = newContext();
    taskExecutor = new QueryTaskExecutorImpl(kernal);
    taskExecutor.stripedThreadPoolExecutor(new IgniteStripedThreadPoolExecutor(kernal.config().getQueryThreadPoolSize(), kernal.igniteInstanceName(), "calciteQry", (t, ex) -> {
        log().error(ex.getMessage(), ex);
        lastE = ex;
    }, true, DFLT_THREAD_KEEP_ALIVE_TIME));
    executors.add(taskExecutor);
    msgSvc = new TestMessageServiceImpl(kernal, mgr);
    msgSvc.localNodeId(nodes.get(1));
    msgSvc.taskExecutor(taskExecutor);
    mgr.register(msgSvc);
    mailboxRegistry = new MailboxRegistryImpl(kernal);
    exchangeSvc = new ExchangeServiceImpl(kernal);
    exchangeSvc.taskExecutor(taskExecutor);
    exchangeSvc.messageService(msgSvc);
    exchangeSvc.mailboxRegistry(mailboxRegistry);
    exchangeSvc.queryRegistry(new QueryRegistryImpl(kernal));
    exchangeSvc.init();
    ectx = new ExecutionContext<>(qctx, taskExecutor, qryId, nodes.get(1), F.first(nodes), AffinityTopologyVersion.NONE, new FragmentDescription(fragment.fragmentId(), fragment.mapping(), plan.target(fragment), plan.remotes(fragment)), ArrayRowHandler.INSTANCE, Commons.parametersMap(ctx.parameters()));
    exec = new LogicalRelImplementor<>(ectx, c -> r -> 0, mailboxRegistry, exchangeSvc, new TestFailureProcessor(kernal)).go(fragment.root());
    assert exec instanceof Outbox;
    Outbox<Object[]> outbox = (Outbox<Object[]>) exec;
    exec.context().execute(outbox::init, outbox::onError);
    ArrayList<Object[]> res = new ArrayList<>();
    while (consumer.hasNext()) res.add(consumer.next());
    assertFalse(res.isEmpty());
    Assert.assertArrayEquals(new Object[] { 0, "Igor", 0, "Calcite", 1 }, res.get(0));
    Assert.assertArrayEquals(new Object[] { 1, "Roman", 0, "Calcite", 1 }, res.get(1));
}
Also used : RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) Arrays(java.util.Arrays) CorrelationTrait(org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait) LogicalRelImplementor(org.apache.ignite.internal.processors.query.calcite.exec.LogicalRelImplementor) SqlNode(org.apache.calcite.sql.SqlNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MultiStepQueryPlan(org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepQueryPlan) ExecutionContext(org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext) IgniteTypeFactory(org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory) RelTraitSet(org.apache.calcite.plan.RelTraitSet) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) DFLT_THREAD_KEEP_ALIVE_TIME(org.apache.ignite.configuration.IgniteConfiguration.DFLT_THREAD_KEEP_ALIVE_TIME) Predicate(java.util.function.Predicate) QueryTaskExecutorImpl(org.apache.ignite.internal.processors.query.calcite.exec.QueryTaskExecutorImpl) UUID(java.util.UUID) IgniteTypeSystem(org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeSystem) RelVisitor(org.apache.calcite.rel.RelVisitor) IgniteSchema(org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema) IgniteDistribution(org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistribution) IgniteFilter(org.apache.ignite.internal.processors.query.calcite.rel.IgniteFilter) List(java.util.List) QueryTemplate(org.apache.ignite.internal.processors.query.calcite.prepare.QueryTemplate) IgniteRel(org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel) Splitter(org.apache.ignite.internal.processors.query.calcite.prepare.Splitter) IgniteConvention(org.apache.ignite.internal.processors.query.calcite.rel.IgniteConvention) Commons(org.apache.ignite.internal.processors.query.calcite.util.Commons) MessageServiceImpl(org.apache.ignite.internal.processors.query.calcite.message.MessageServiceImpl) Frameworks.newConfigBuilder(org.apache.calcite.tools.Frameworks.newConfigBuilder) Outbox(org.apache.ignite.internal.processors.query.calcite.exec.rel.Outbox) Fragment(org.apache.ignite.internal.processors.query.calcite.prepare.Fragment) IgniteStripedThreadPoolExecutor(org.apache.ignite.thread.IgniteStripedThreadPoolExecutor) MappingQueryContext(org.apache.ignite.internal.processors.query.calcite.prepare.MappingQueryContext) ExchangeServiceImpl(org.apache.ignite.internal.processors.query.calcite.exec.ExchangeServiceImpl) ArrayRowHandler(org.apache.ignite.internal.processors.query.calcite.exec.ArrayRowHandler) IgnitePlanner(org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner) PlanningContext(org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext) RelRoot(org.apache.calcite.rel.RelRoot) Frameworks.createRootSchema(org.apache.calcite.tools.Frameworks.createRootSchema) Function(java.util.function.Function) RelOptUtil(org.apache.calcite.plan.RelOptUtil) ArrayList(java.util.ArrayList) BaseQueryContext(org.apache.ignite.internal.processors.query.calcite.prepare.BaseQueryContext) ColocationGroup(org.apache.ignite.internal.processors.query.calcite.metadata.ColocationGroup) FragmentDescription(org.apache.ignite.internal.processors.query.calcite.metadata.FragmentDescription) IgniteCostFactory(org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCostFactory) MultiStepPlan(org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepPlan) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RootNode(org.apache.ignite.internal.processors.query.calcite.exec.rel.RootNode) Node(org.apache.ignite.internal.processors.query.calcite.exec.rel.Node) IgniteDistributions(org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions) FRAMEWORK_CONFIG(org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor.FRAMEWORK_CONFIG) F(org.apache.ignite.internal.util.typedef.F) SchemaPlus(org.apache.calcite.schema.SchemaPlus) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) PlannerPhase(org.apache.ignite.internal.processors.query.calcite.prepare.PlannerPhase) Test(org.junit.Test) RelNode(org.apache.calcite.rel.RelNode) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) QueryRegistryImpl(org.apache.ignite.internal.processors.query.calcite.QueryRegistryImpl) MailboxRegistryImpl(org.apache.ignite.internal.processors.query.calcite.exec.MailboxRegistryImpl) TestIoManager(org.apache.ignite.internal.processors.query.calcite.message.TestIoManager) Assert(org.junit.Assert) PlanningContext(org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) LogicalRelImplementor(org.apache.ignite.internal.processors.query.calcite.exec.LogicalRelImplementor) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) MultiStepQueryPlan(org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepQueryPlan) ArrayList(java.util.ArrayList) Fragment(org.apache.ignite.internal.processors.query.calcite.prepare.Fragment) Predicate(java.util.function.Predicate) ColocationGroup(org.apache.ignite.internal.processors.query.calcite.metadata.ColocationGroup) IgniteSchema(org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema) UUID(java.util.UUID) FragmentDescription(org.apache.ignite.internal.processors.query.calcite.metadata.FragmentDescription) MappingQueryContext(org.apache.ignite.internal.processors.query.calcite.prepare.MappingQueryContext) MultiStepPlan(org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepPlan) Outbox(org.apache.ignite.internal.processors.query.calcite.exec.rel.Outbox) TestIoManager(org.apache.ignite.internal.processors.query.calcite.message.TestIoManager) ExecutionContext(org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext) QueryTemplate(org.apache.ignite.internal.processors.query.calcite.prepare.QueryTemplate) ExchangeServiceImpl(org.apache.ignite.internal.processors.query.calcite.exec.ExchangeServiceImpl) RootNode(org.apache.ignite.internal.processors.query.calcite.exec.rel.RootNode) BaseQueryContext(org.apache.ignite.internal.processors.query.calcite.prepare.BaseQueryContext) MessageServiceImpl(org.apache.ignite.internal.processors.query.calcite.message.MessageServiceImpl) IgniteRel(org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel) QueryTaskExecutorImpl(org.apache.ignite.internal.processors.query.calcite.exec.QueryTaskExecutorImpl) Function(java.util.function.Function) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteStripedThreadPoolExecutor(org.apache.ignite.thread.IgniteStripedThreadPoolExecutor) Splitter(org.apache.ignite.internal.processors.query.calcite.prepare.Splitter) IgniteTypeFactory(org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory) SchemaPlus(org.apache.calcite.schema.SchemaPlus) MailboxRegistryImpl(org.apache.ignite.internal.processors.query.calcite.exec.MailboxRegistryImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryRegistryImpl(org.apache.ignite.internal.processors.query.calcite.QueryRegistryImpl) Test(org.junit.Test)

Example 3 with PlanningContext

use of org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext in project ignite by apache.

the class PlannerTimeoutTest method testLongPlanningTimeout.

/**
 */
@Test
public void testLongPlanningTimeout() throws Exception {
    IgniteSchema schema = createSchema(createTestTable("T1", "A", Integer.class, "B", Integer.class), createTestTable("T2", "A", Integer.class, "B", Integer.class));
    String sql = "SELECT * FROM T1 JOIN T2 ON T1.A = T2.A";
    PlanningContext ctx = PlanningContext.builder().parentContext(baseQueryContext(Collections.singletonList(schema))).plannerTimeout(PLANNER_TIMEOUT).query(sql).build();
    AtomicReference<IgniteRel> plan = new AtomicReference<>();
    AtomicReference<RelOptPlanner.CannotPlanException> plannerError = new AtomicReference<>();
    GridTestUtils.assertTimeout(3 * PLANNER_TIMEOUT, TimeUnit.MILLISECONDS, () -> {
        try (IgnitePlanner planner = ctx.planner()) {
            plan.set(physicalPlan(planner, ctx.query()));
            VolcanoPlanner volcanoPlanner = (VolcanoPlanner) ctx.cluster().getPlanner();
            assertNotNull(volcanoPlanner);
            GridTestUtils.assertThrowsWithCause(volcanoPlanner::checkCancel, VolcanoTimeoutException.class);
        } catch (RelOptPlanner.CannotPlanException e) {
            plannerError.set(e);
        } catch (Exception e) {
            throw new RuntimeException("Planning failed", e);
        }
    });
    assertTrue(plan.get() != null || plannerError.get() != null);
    if (plan.get() != null) {
        new RelVisitor() {

            @Override
            public void visit(RelNode node, int ordinal, RelNode parent) {
                assertNotNull(node.getTraitSet().getTrait(IgniteConvention.INSTANCE.getTraitDef()));
                super.visit(node, ordinal, parent);
            }
        }.go(plan.get());
    }
}
Also used : PlanningContext(org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext) IgniteRel(org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel) AtomicReference(java.util.concurrent.atomic.AtomicReference) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) VolcanoTimeoutException(org.apache.calcite.plan.volcano.VolcanoTimeoutException) IgnitePlanner(org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner) RelNode(org.apache.calcite.rel.RelNode) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) RelVisitor(org.apache.calcite.rel.RelVisitor) IgniteSchema(org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema) Test(org.junit.Test)

Example 4 with PlanningContext

use of org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext in project ignite by apache.

the class CorrelatedSubqueryPlannerTest method testCorrelatesCollisionsLeftHand.

/**
 * Test verifies resolving of collisions in the left hand of correlates.
 */
@Test
public void testCorrelatesCollisionsLeftHand() throws Exception {
    IgniteSchema schema = createSchema(createTable("T1", IgniteDistributions.single(), "A", Integer.class, "B", Integer.class, "C", Integer.class, "D", Integer.class));
    String sql = "SELECT * FROM t1 as cor WHERE " + "EXISTS (SELECT 1 FROM t1 WHERE t1.b = cor.a) AND " + "EXISTS (SELECT 1 FROM t1 WHERE t1.c = cor.a) AND " + "EXISTS (SELECT 1 FROM t1 WHERE t1.d = cor.a)";
    PlanningContext ctx = plannerCtx(sql, schema);
    try (IgnitePlanner planner = ctx.planner()) {
        RelNode rel = convertSubQueries(planner, ctx);
        List<LogicalCorrelate> correlates = findNodes(rel, byClass(LogicalCorrelate.class));
        assertEquals(3, correlates.size());
        // There are collisions by correlation id.
        assertEquals(correlates.get(0).getCorrelationId(), correlates.get(1).getCorrelationId());
        assertEquals(correlates.get(0).getCorrelationId(), correlates.get(2).getCorrelationId());
        rel = planner.replaceCorrelatesCollisions(rel);
        correlates = findNodes(rel, byClass(LogicalCorrelate.class));
        assertEquals(3, correlates.size());
        // There are no collisions by correlation id.
        assertFalse(correlates.get(0).getCorrelationId().equals(correlates.get(1).getCorrelationId()));
        assertFalse(correlates.get(0).getCorrelationId().equals(correlates.get(2).getCorrelationId()));
        assertFalse(correlates.get(1).getCorrelationId().equals(correlates.get(2).getCorrelationId()));
        List<LogicalFilter> filters = findNodes(rel, byClass(LogicalFilter.class).and(f -> RexUtils.hasCorrelation(((Filter) f).getCondition())));
        assertEquals(3, filters.size());
        // Filters match correlates in reverse order (we find outer correlate first, but inner filter first).
        assertEquals(Collections.singleton(correlates.get(0).getCorrelationId()), RexUtils.extractCorrelationIds(filters.get(2).getCondition()));
        assertEquals(Collections.singleton(correlates.get(1).getCorrelationId()), RexUtils.extractCorrelationIds(filters.get(1).getCondition()));
        assertEquals(Collections.singleton(correlates.get(2).getCorrelationId()), RexUtils.extractCorrelationIds(filters.get(0).getCondition()));
    }
}
Also used : Project(org.apache.calcite.rel.core.Project) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) IgnitePlanner(org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) PlannerPhase(org.apache.ignite.internal.processors.query.calcite.prepare.PlannerPhase) PlanningContext(org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext) Test(org.junit.Test) RelNode(org.apache.calcite.rel.RelNode) Filter(org.apache.calcite.rel.core.Filter) IgniteSchema(org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema) IgniteCorrelatedNestedLoopJoin(org.apache.ignite.internal.processors.query.calcite.rel.IgniteCorrelatedNestedLoopJoin) IgniteFilter(org.apache.ignite.internal.processors.query.calcite.rel.IgniteFilter) List(java.util.List) SqlNode(org.apache.calcite.sql.SqlNode) IgniteRel(org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel) RexNode(org.apache.calcite.rex.RexNode) RexCorrelVariable(org.apache.calcite.rex.RexCorrelVariable) LogicalCorrelate(org.apache.calcite.rel.logical.LogicalCorrelate) Collections(java.util.Collections) RexUtils(org.apache.ignite.internal.processors.query.calcite.util.RexUtils) IgniteDistributions(org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions) RexCall(org.apache.calcite.rex.RexCall) PlanningContext(org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext) IgnitePlanner(org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner) RelNode(org.apache.calcite.rel.RelNode) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) IgniteSchema(org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema) LogicalCorrelate(org.apache.calcite.rel.logical.LogicalCorrelate) Test(org.junit.Test)

Example 5 with PlanningContext

use of org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext in project ignite by apache.

the class AbstractPlannerTest method plannerCtx.

/**
 */
protected PlanningContext plannerCtx(String sql, Collection<IgniteSchema> schemas, String... disabledRules) {
    PlanningContext ctx = PlanningContext.builder().parentContext(baseQueryContext(schemas)).query(sql).build();
    IgnitePlanner planner = ctx.planner();
    assertNotNull(planner);
    planner.setDisabledRules(ImmutableSet.copyOf(disabledRules));
    return ctx;
}
Also used : PlanningContext(org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext) IgnitePlanner(org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner)

Aggregations

PlanningContext (org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext)17 Test (org.junit.Test)15 IgniteRel (org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel)14 IgniteSchema (org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)9 SchemaPlus (org.apache.calcite.schema.SchemaPlus)9 IgnitePlanner (org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner)9 IgniteTypeFactory (org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory)9 RelNode (org.apache.calcite.rel.RelNode)8 MappingQueryContext (org.apache.ignite.internal.processors.query.calcite.prepare.MappingQueryContext)8 MultiStepPlan (org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepPlan)8 MultiStepQueryPlan (org.apache.ignite.internal.processors.query.calcite.prepare.MultiStepQueryPlan)8 QueryTemplate (org.apache.ignite.internal.processors.query.calcite.prepare.QueryTemplate)8 Splitter (org.apache.ignite.internal.processors.query.calcite.prepare.Splitter)8 SqlNode (org.apache.calcite.sql.SqlNode)6 List (java.util.List)4 RelRoot (org.apache.calcite.rel.RelRoot)4 PlannerPhase (org.apache.ignite.internal.processors.query.calcite.prepare.PlannerPhase)4 IgniteFilter (org.apache.ignite.internal.processors.query.calcite.rel.IgniteFilter)4