Search in sources :

Example 16 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class VolcanoPlanner method clear.

@Override
public void clear() {
    super.clear();
    for (RelOptRule rule : ImmutableList.copyOf(ruleSet)) {
        removeRule(rule);
    }
    this.classOperands.clear();
    this.allSets.clear();
    this.mapDigestToRel.clear();
    this.mapRel2Subset.clear();
    this.relImportances.clear();
    this.ruleQueue.clear();
    this.ruleNames.clear();
    this.materializations.clear();
    this.latticeByName.clear();
}
Also used : RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 17 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class HepPlanner method executeInstruction.

void executeInstruction(HepInstruction.ConverterRules instruction) {
    assert currentProgram.group == null;
    if (instruction.ruleSet == null) {
        instruction.ruleSet = new LinkedHashSet<>();
        for (RelOptRule rule : allRules) {
            if (!(rule instanceof ConverterRule)) {
                continue;
            }
            ConverterRule converter = (ConverterRule) rule;
            if (converter.isGuaranteed() != instruction.guaranteed) {
                continue;
            }
            // Add the rule itself to work top-down
            instruction.ruleSet.add(converter);
            if (!instruction.guaranteed) {
                // Add a TraitMatchingRule to work bottom-up
                instruction.ruleSet.add(new TraitMatchingRule(converter, RelFactories.LOGICAL_BUILDER));
            }
        }
    }
    applyRules(instruction.ruleSet, instruction.guaranteed);
}
Also used : ConverterRule(org.apache.calcite.rel.convert.ConverterRule) TraitMatchingRule(org.apache.calcite.rel.convert.TraitMatchingRule) RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 18 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class HepPlanner method applyRules.

private void applyRules(Collection<RelOptRule> rules, boolean forceConversions) {
    if (currentProgram.group != null) {
        assert currentProgram.group.collecting;
        currentProgram.group.ruleSet.addAll(rules);
        return;
    }
    LOGGER.trace("Applying rule set {}", rules);
    boolean fullRestartAfterTransformation = currentProgram.matchOrder != HepMatchOrder.ARBITRARY && currentProgram.matchOrder != HepMatchOrder.DEPTH_FIRST;
    int nMatches = 0;
    boolean fixedPoint;
    do {
        Iterator<HepRelVertex> iter = getGraphIterator(root);
        fixedPoint = true;
        while (iter.hasNext()) {
            HepRelVertex vertex = iter.next();
            for (RelOptRule rule : rules) {
                HepRelVertex newVertex = applyRule(rule, vertex, forceConversions);
                if (newVertex == null || newVertex == vertex) {
                    continue;
                }
                ++nMatches;
                if (nMatches >= currentProgram.matchLimit) {
                    return;
                }
                if (fullRestartAfterTransformation) {
                    iter = getGraphIterator(root);
                } else {
                    // To the extent possible, pick up where we left
                    // off; have to create a new iterator because old
                    // one was invalidated by transformation.
                    iter = getGraphIterator(newVertex);
                    if (currentProgram.matchOrder == HepMatchOrder.DEPTH_FIRST) {
                        nMatches = depthFirstApply(iter, rules, forceConversions, nMatches);
                        if (nMatches >= currentProgram.matchLimit) {
                            return;
                        }
                    }
                    // Remember to go around again since we're
                    // skipping some stuff.
                    fixedPoint = false;
                }
                break;
            }
        }
    } while (!fixedPoint);
}
Also used : RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 19 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.

the class HepPlanner method depthFirstApply.

private int depthFirstApply(Iterator<HepRelVertex> iter, Collection<RelOptRule> rules, boolean forceConversions, int nMatches) {
    while (iter.hasNext()) {
        HepRelVertex vertex = iter.next();
        for (RelOptRule rule : rules) {
            HepRelVertex newVertex = applyRule(rule, vertex, forceConversions);
            if (newVertex == null || newVertex == vertex) {
                continue;
            }
            ++nMatches;
            if (nMatches >= currentProgram.matchLimit) {
                return nMatches;
            }
            // To the extent possible, pick up where we left
            // off; have to create a new iterator because old
            // one was invalidated by transformation.
            Iterator<HepRelVertex> depthIter = getGraphIterator(newVertex);
            nMatches = depthFirstApply(depthIter, rules, forceConversions, nMatches);
            break;
        }
    }
    return nMatches;
}
Also used : RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 20 with RelOptRule

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project beam by apache.

the class BigQueryIOPushDownIT method readUsingDirectReadMethod.

@Test
public void readUsingDirectReadMethod() {
    List<RelOptRule> ruleList = new ArrayList<>();
    for (RuleSet x : getRuleSets()) {
        x.iterator().forEachRemaining(ruleList::add);
    }
    // Remove push-down rule
    ruleList.remove(BeamIOPushDownRule.INSTANCE);
    InMemoryMetaStore inMemoryMetaStore = new InMemoryMetaStore();
    inMemoryMetaStore.registerProvider(new BigQueryPerfTableProvider(NAMESPACE, FIELDS_READ_METRIC));
    sqlEnv = BeamSqlEnv.builder(inMemoryMetaStore).setPipelineOptions(PipelineOptionsFactory.create()).setRuleSets(ImmutableList.of(RuleSets.ofList(ruleList))).build();
    sqlEnv.executeDdl(String.format(CREATE_TABLE_STATEMENT, Method.DIRECT_READ.toString()));
    BeamRelNode beamRelNode = sqlEnv.parseQuery(SELECT_STATEMENT);
    BeamSqlRelUtils.toPCollection(pipeline, beamRelNode).apply(ParDo.of(new TimeMonitor<>(NAMESPACE, READ_TIME_METRIC)));
    PipelineResult result = pipeline.run();
    result.waitUntilFinish();
    collectAndPublishMetrics(result, "_directread");
}
Also used : TimeMonitor(org.apache.beam.sdk.testutils.metrics.TimeMonitor) RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) ArrayList(java.util.ArrayList) PipelineResult(org.apache.beam.sdk.PipelineResult) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) RelOptRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule) Test(org.junit.Test)

Aggregations

RelOptRule (org.apache.calcite.plan.RelOptRule)19 Test (org.junit.Test)7 RuleSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet)6 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)6 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)5 RelNode (org.apache.calcite.rel.RelNode)5 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)4 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)4 ArrayList (java.util.ArrayList)3 RelOptRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 VolcanoPlanner (org.apache.calcite.plan.volcano.VolcanoPlanner)3 ImmutableList (com.google.common.collect.ImmutableList)2 Connection (java.sql.Connection)2 List (java.util.List)2 JoinCommuteRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule)2 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)2 JaninoRelMetadataProvider (org.apache.calcite.rel.metadata.JaninoRelMetadataProvider)2 Program (org.apache.calcite.tools.Program)2 RuleSet (org.apache.calcite.tools.RuleSet)2