Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-3916] Implement top-down rule applying and upper bound space pruning #1950

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -58,6 +58,8 @@ public interface CalciteConnectionConfig extends ConnectionConfig {
boolean caseSensitive();
/** @see CalciteConnectionProperty#PARSER_FACTORY */
<T> T parserFactory(Class<T> parserFactoryClass, T defaultParserFactory);
/** @see CalciteConnectionProperty#PARSER_FACTORY */
<T> T plannerFactory(Class<T> plannerFactoryClass, T defaultPlannerFactory);
/** @see CalciteConnectionProperty#SCHEMA_FACTORY */
<T> T schemaFactory(Class<T> schemaFactoryClass, T defaultSchemaFactory);
/** @see CalciteConnectionProperty#SCHEMA_TYPE */
Expand Down
Expand Up @@ -150,6 +150,12 @@ public <T> T parserFactory(Class<T> parserFactoryClass,
.getPlugin(parserFactoryClass, defaultParserFactory);
}

public <T> T plannerFactory(Class<T> plannerFactoryClass,
T defaultPlannerFactory) {
return CalciteConnectionProperty.PLANNER_FACTORY.wrap(properties)
.getPlugin(plannerFactoryClass, defaultPlannerFactory);
}

public <T> T schemaFactory(Class<T> schemaFactoryClass,
T defaultSchemaFactory) {
return CalciteConnectionProperty.SCHEMA_FACTORY.wrap(properties)
Expand Down
Expand Up @@ -105,6 +105,12 @@ public enum CalciteConnectionProperty implements ConnectionProperty {
* {@link org.apache.calcite.sql.parser.SqlParserImplFactory}. */
PARSER_FACTORY("parserFactory", Type.PLUGIN, null, false),

/** Planner factory.
*
* <p>The name of a class that implements
* {@link org.apache.calcite.plan.PlannerFactory}. */
PLANNER_FACTORY("plannerFactory", Type.PLUGIN, null, false),

/** Name of initial schema. */
SCHEMA("schema", Type.STRING, null, false),

Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.calcite.plan;

import org.apache.calcite.plan.volcano.CascadeRelSubset;
import org.apache.calcite.plan.volcano.RelSubset;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.metadata.RelMetadataProvider;
Expand Down Expand Up @@ -105,6 +106,7 @@ protected AbstractRelOptPlanner(RelOptCostFactory costFactory,
// these types, but some operands may use them.
classes.add(RelNode.class);
classes.add(RelSubset.class);
classes.add(CascadeRelSubset.class);

if (RULE_ATTEMPTS_LOGGER.isDebugEnabled()) {
this.ruleAttemptsListener = new RuleAttemptsListener();
Expand Down Expand Up @@ -440,8 +442,8 @@ public Iterable<Class<? extends RelNode>> subClasses(
final Class<? extends RelNode> clazz) {
return Util.filter(classes, c -> {
// RelSubset must be exact type, not subclass
if (c == RelSubset.class) {
return c == clazz;
if (RelSubset.class.isAssignableFrom(c) && clazz == RelNode.class) {
return false;
}
return clazz.isAssignableFrom(c);
});
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/org/apache/calcite/plan/PlannerFactory.java
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.calcite.plan;

/**
* Factory that creates a planner with specific configurations
*/
public interface PlannerFactory {

/**
* creating planners with specific configurations
*/
RelOptPlanner create(RelOptCostFactory costFactory, Context externalContext);
}
Expand Up @@ -47,7 +47,7 @@ public class RelOptRuleOperand {
public int[] solveOrder;
public int ordinalInParent;
public int ordinalInRule;
private final RelTrait trait;
public final RelTrait trait;
private final Class<? extends RelNode> clazz;
private final ImmutableList<RelOptRuleOperand> children;

Expand Down