use of org.apache.calcite.plan.volcano.VolcanoPlanner in project drill by apache.
the class SqlConverter method initPlanner.
private RelOptPlanner initPlanner() {
if (planner == null) {
planner = new VolcanoPlanner(costFactory, settings);
planner.setExecutor(new DrillConstExecutor(functions, util, settings));
planner.clearRelTraitDefs();
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
planner.addRelTraitDef(DrillDistributionTraitDef.INSTANCE);
planner.addRelTraitDef(RelCollationTraitDef.INSTANCE);
}
return planner;
}
use of org.apache.calcite.plan.volcano.VolcanoPlanner in project drill by apache.
the class DefaultSqlHandler method transform.
/**
* Transform RelNode to a new RelNode, targeting the provided set of traits. Also will log the outcome if asked.
*
* @param plannerType The type of Planner to use.
* @param phase The transformation phase we're running.
* @param input The original RelNode
* @param targetTraits The traits we are targeting for output.
* @param log Whether to log the planning phase.
* @return The transformed relnode.
*/
protected RelNode transform(PlannerType plannerType, PlannerPhase phase, RelNode input, RelTraitSet targetTraits, boolean log) {
final Stopwatch watch = Stopwatch.createStarted();
final RuleSet rules = config.getRules(phase);
final RelTraitSet toTraits = targetTraits.simplify();
final RelNode output;
switch(plannerType) {
case HEP_BOTTOM_UP:
case HEP:
{
final HepProgramBuilder hepPgmBldr = new HepProgramBuilder();
if (plannerType == PlannerType.HEP_BOTTOM_UP) {
hepPgmBldr.addMatchOrder(HepMatchOrder.BOTTOM_UP);
}
for (RelOptRule rule : rules) {
hepPgmBldr.addRuleInstance(rule);
}
// Set noDAG = true to avoid caching problems which lead to incorrect Drill work.
final HepPlanner planner = new HepPlanner(hepPgmBldr.build(), context.getPlannerSettings(), true, null, RelOptCostImpl.FACTORY);
JaninoRelMetadataProvider relMetadataProvider = Utilities.registerJaninoRelMetadataProvider();
// Modify RelMetaProvider for every RelNode in the SQL operator Rel tree.
input.accept(new MetaDataProviderModifier(relMetadataProvider));
planner.setRoot(input);
if (!input.getTraitSet().equals(targetTraits)) {
planner.changeTraits(input, toTraits);
}
output = planner.findBestExp();
break;
}
case VOLCANO:
default:
{
// as weird as it seems, the cluster's only planner is the volcano planner.
final RelOptPlanner planner = input.getCluster().getPlanner();
final Program program = Programs.of(rules);
Preconditions.checkArgument(planner instanceof VolcanoPlanner, "Cluster is expected to be constructed using VolcanoPlanner. Was actually of type %s.", planner.getClass().getName());
output = program.run(planner, input, toTraits, ImmutableList.of(), ImmutableList.of());
break;
}
}
if (log) {
log(plannerType, phase, output, logger, watch);
}
return output;
}
use of org.apache.calcite.plan.volcano.VolcanoPlanner in project drill by axbaretto.
the class SqlConverter method toRel.
public RelRoot toRel(final SqlNode validatedNode) {
if (planner == null) {
planner = new VolcanoPlanner(costFactory, settings);
planner.setExecutor(new DrillConstExecutor(functions, util, settings));
planner.clearRelTraitDefs();
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
planner.addRelTraitDef(DrillDistributionTraitDef.INSTANCE);
planner.addRelTraitDef(RelCollationTraitDef.INSTANCE);
}
if (cluster == null) {
initCluster();
}
final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(new Expander(), validator, catalog, cluster, DrillConvertletTable.INSTANCE, sqlToRelConverterConfig);
/*
* Sets value to false to avoid simplifying project expressions
* during creating new projects since it may cause changing data mode
* which causes to assertion errors during type validation
*/
Hook.REL_BUILDER_SIMPLIFY.add(Hook.property(false));
// To avoid unexpected column errors set a value of top to false
final RelRoot rel = sqlToRelConverter.convertQuery(validatedNode, false, false);
final RelRoot rel2 = rel.withRel(sqlToRelConverter.flattenTypes(rel.rel, true));
final RelRoot rel3 = rel2.withRel(RelDecorrelator.decorrelateQuery(rel2.rel));
return rel3;
}
use of org.apache.calcite.plan.volcano.VolcanoPlanner in project hazelcast by hazelcast.
the class OptimizerContext method create.
public static OptimizerContext create(HazelcastSchema rootSchema, List<List<String>> schemaPaths, List<Object> arguments, int memberCount, IMapResolver iMapResolver) {
DistributionTraitDef distributionTraitDef = new DistributionTraitDef(memberCount);
Prepare.CatalogReader catalogReader = createCatalogReader(rootSchema, schemaPaths);
HazelcastSqlValidator validator = new HazelcastSqlValidator(catalogReader, arguments, iMapResolver);
VolcanoPlanner volcanoPlanner = createPlanner(distributionTraitDef);
HazelcastRelOptCluster cluster = createCluster(volcanoPlanner, distributionTraitDef);
QueryParser parser = new QueryParser(validator);
QueryConverter converter = new QueryConverter(validator, catalogReader, cluster);
QueryPlanner planner = new QueryPlanner(volcanoPlanner);
return new OptimizerContext(cluster, parser, converter, planner);
}
use of org.apache.calcite.plan.volcano.VolcanoPlanner in project hazelcast by hazelcast.
the class OptimizerContext method createPlanner.
private static VolcanoPlanner createPlanner(DistributionTraitDef distributionTraitDef) {
VolcanoPlanner planner = new VolcanoPlanner(CostFactory.INSTANCE, Contexts.of(CONNECTION_CONFIG));
planner.clearRelTraitDefs();
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
planner.addRelTraitDef(RelCollationTraitDef.INSTANCE);
planner.addRelTraitDef(distributionTraitDef);
return planner;
}
Aggregations