Search in sources :

Example 6 with VolcanoPlanner

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;
}
Also used : VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) DrillConstExecutor(org.apache.drill.exec.planner.logical.DrillConstExecutor)

Example 7 with VolcanoPlanner

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;
}
Also used : RuleSet(org.apache.calcite.tools.RuleSet) Program(org.apache.calcite.tools.Program) RelNode(org.apache.calcite.rel.RelNode) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) JaninoRelMetadataProvider(org.apache.calcite.rel.metadata.JaninoRelMetadataProvider) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) RelTraitSet(org.apache.calcite.plan.RelTraitSet) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) RelOptRule(org.apache.calcite.plan.RelOptRule)

Example 8 with VolcanoPlanner

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;
}
Also used : SqlToRelConverter(org.apache.calcite.sql2rel.SqlToRelConverter) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) DrillConstExecutor(org.apache.drill.exec.planner.logical.DrillConstExecutor) RelRoot(org.apache.calcite.rel.RelRoot)

Example 9 with VolcanoPlanner

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);
}
Also used : HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) QueryParser(com.hazelcast.jet.sql.impl.parse.QueryParser) QueryConverter(com.hazelcast.jet.sql.impl.parse.QueryConverter) Prepare(org.apache.calcite.prepare.Prepare) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) DistributionTraitDef(com.hazelcast.jet.sql.impl.opt.distribution.DistributionTraitDef)

Example 10 with VolcanoPlanner

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;
}
Also used : VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner)

Aggregations

VolcanoPlanner (org.apache.calcite.plan.volcano.VolcanoPlanner)12 RelNode (org.apache.calcite.rel.RelNode)6 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)5 RelOptMaterialization (org.apache.calcite.plan.RelOptMaterialization)3 RelOptRule (org.apache.calcite.plan.RelOptRule)3 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)3 DrillConstExecutor (org.apache.drill.exec.planner.logical.DrillConstExecutor)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)2 JaninoRelMetadataProvider (org.apache.calcite.rel.metadata.JaninoRelMetadataProvider)2 RexBuilder (org.apache.calcite.rex.RexBuilder)2 SqlToRelConverter (org.apache.calcite.sql2rel.SqlToRelConverter)2 Program (org.apache.calcite.tools.Program)2 RuleSet (org.apache.calcite.tools.RuleSet)2 Stopwatch (com.google.common.base.Stopwatch)1 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 DistributionTraitDef (com.hazelcast.jet.sql.impl.opt.distribution.DistributionTraitDef)1 QueryConverter (com.hazelcast.jet.sql.impl.parse.QueryConverter)1