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();
}
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);
}
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);
}
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;
}
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");
}
Aggregations