Skip to content

Commit

Permalink
[CALCITE-4200] ExceptionInInitializerError when initializing DruidRules
Browse files Browse the repository at this point in the history
Refactor DruidRules to conform with the RelRule API guidelines to
resolve the initialization error and homogenize the code.

Create Config.DEFAULT in Druid specific configurations and use that for
instantiating the rules.

Use Config.DEFAULT instead of RelRule.config to create rule extensions
for Druid to cut out dependency in CoreRules holder class.
  • Loading branch information
zabetak committed Sep 9, 2020
1 parent 60aa74f commit 7404445
Showing 1 changed file with 56 additions and 47 deletions.
103 changes: 56 additions & 47 deletions druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.calcite.rel.logical.LogicalFilter;
import org.apache.calcite.rel.rules.AggregateExtractProjectRule;
import org.apache.calcite.rel.rules.AggregateFilterTransposeRule;
import org.apache.calcite.rel.rules.CoreRules;
import org.apache.calcite.rel.rules.FilterAggregateTransposeRule;
import org.apache.calcite.rel.rules.FilterProjectTransposeRule;
import org.apache.calcite.rel.rules.ProjectFilterTransposeRule;
Expand Down Expand Up @@ -70,8 +69,6 @@
import java.util.List;
import java.util.Set;

import static org.apache.calcite.plan.RelRule.Config.EMPTY;

/**
* Rules and relational operators for {@link DruidQuery}.
*/
Expand All @@ -80,37 +77,13 @@ private DruidRules() {}

protected static final Logger LOGGER = CalciteTrace.getPlannerTracer();

public static final DruidFilterRule FILTER = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Filter.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidFilterRule.Config.class)
.toRule();
public static final DruidProjectRule PROJECT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Project.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidProjectRule.Config.class)
.toRule();
public static final DruidAggregateRule AGGREGATE = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Aggregate.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidAggregateRule.Config.class)
.toRule();
public static final DruidAggregateProjectRule AGGREGATE_PROJECT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Aggregate.class).oneInput(b1 ->
b1.operand(Project.class).oneInput(b2 ->
b2.operand(DruidQuery.class).noInputs())))
.as(DruidAggregateProjectRule.Config.class)
.toRule();
public static final DruidSortRule SORT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Sort.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidSortRule.Config.class)
public static final DruidFilterRule FILTER = DruidFilterRule.Config.DEFAULT.toRule();
public static final DruidProjectRule PROJECT = DruidProjectRule.Config.DEFAULT.toRule();
public static final DruidAggregateRule AGGREGATE = DruidAggregateRule.Config.DEFAULT.toRule();
public static final DruidAggregateProjectRule AGGREGATE_PROJECT =
DruidAggregateProjectRule.Config.DEFAULT
.toRule();
public static final DruidSortRule SORT = DruidSortRule.Config.DEFAULT.toRule();

/** Rule to push an {@link org.apache.calcite.rel.core.Sort} through a
* {@link org.apache.calcite.rel.core.Project}. Useful to transform
Expand All @@ -132,7 +105,7 @@ private DruidRules() {}
* past a {@link org.apache.calcite.rel.core.Project}
* when {@code Project} is on top of a {@link DruidQuery}. */
public static final FilterProjectTransposeRule FILTER_PROJECT_TRANSPOSE =
CoreRules.FILTER_PROJECT_TRANSPOSE.config
FilterProjectTransposeRule.Config.DEFAULT
.withOperandFor(Filter.class, Project.class, DruidQuery.class)
.withCopyFilter(true)
.withCopyProject(true)
Expand All @@ -142,40 +115,33 @@ private DruidRules() {}
* past a {@link org.apache.calcite.rel.core.Filter}
* when {@code Filter} is on top of a {@link DruidQuery}. */
public static final AggregateFilterTransposeRule AGGREGATE_FILTER_TRANSPOSE =
CoreRules.AGGREGATE_FILTER_TRANSPOSE.config
AggregateFilterTransposeRule.Config.DEFAULT
.withOperandFor(Aggregate.class, Filter.class, DruidQuery.class)
.toRule();

/** Rule to push an {@link org.apache.calcite.rel.core.Filter}
* past an {@link org.apache.calcite.rel.core.Aggregate}
* when {@code Aggregate} is on top of a {@link DruidQuery}. */
public static final FilterAggregateTransposeRule FILTER_AGGREGATE_TRANSPOSE =
CoreRules.FILTER_AGGREGATE_TRANSPOSE.config
FilterAggregateTransposeRule.Config.DEFAULT
.withOperandFor(Filter.class, Aggregate.class, DruidQuery.class)
.toRule();

public static final DruidPostAggregationProjectRule POST_AGGREGATION_PROJECT =
EMPTY.withOperandSupplier(b0 ->
b0.operand(Project.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidPostAggregationProjectRule.Config.class)
.toRule();
DruidPostAggregationProjectRule.Config.DEFAULT.toRule();

/** Rule to extract a {@link org.apache.calcite.rel.core.Project} from
* {@link org.apache.calcite.rel.core.Aggregate} on top of
* {@link org.apache.calcite.adapter.druid.DruidQuery} based on the fields
* used in the aggregate. */
public static final AggregateExtractProjectRule PROJECT_EXTRACT_RULE =
EMPTY.as(AggregateExtractProjectRule.Config.class)
AggregateExtractProjectRule.Config.DEFAULT
.withOperandFor(Aggregate.class, DruidQuery.class)
.toRule();

public static final DruidHavingFilterRule DRUID_HAVING_FILTER_RULE =
EMPTY.withOperandSupplier(b0 ->
b0.operand(Filter.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidHavingFilterRule.Config.class)
.toRule();
DruidHavingFilterRule.Config.DEFAULT
.toRule();

public static final List<RelOptRule> RULES =
ImmutableList.of(FILTER,
Expand Down Expand Up @@ -307,6 +273,12 @@ private static Triple<List<RexNode>, List<RexNode>, List<RexNode>> splitFilters(

/** Rule configuration. */
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Filter.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidFilterRule.Config.class);

@Override default DruidFilterRule toRule() {
return new DruidFilterRule(this);
}
Expand Down Expand Up @@ -343,6 +315,12 @@ protected DruidHavingFilterRule(Config config) {

/** Rule configuration. */
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Filter.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidHavingFilterRule.Config.class);

@Override default DruidHavingFilterRule toRule() {
return new DruidHavingFilterRule(this);
}
Expand Down Expand Up @@ -435,6 +413,12 @@ private static Pair<List<RexNode>, List<RexNode>> splitProjects(

/** Rule configuration. */
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Project.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidProjectRule.Config.class);

@Override default DruidProjectRule toRule() {
return new DruidProjectRule(this);
}
Expand Down Expand Up @@ -491,6 +475,12 @@ protected DruidPostAggregationProjectRule(Config config) {

/** Rule configuration. */
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Project.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidPostAggregationProjectRule.Config.class);

@Override default DruidPostAggregationProjectRule toRule() {
return new DruidPostAggregationProjectRule(this);
}
Expand Down Expand Up @@ -539,6 +529,12 @@ protected DruidAggregateRule(Config config) {

/** Rule configuration. */
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Aggregate.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidAggregateRule.Config.class);

@Override default DruidAggregateRule toRule() {
return new DruidAggregateRule(this);
}
Expand Down Expand Up @@ -775,6 +771,13 @@ private static List<Integer> getFilterRefs(List<AggregateCall> calls) {

/** Rule configuration. */
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Aggregate.class).oneInput(b1 ->
b1.operand(Project.class).oneInput(b2 ->
b2.operand(DruidQuery.class).noInputs())))
.as(DruidAggregateProjectRule.Config.class);

@Override default DruidAggregateProjectRule toRule() {
return new DruidAggregateProjectRule(this);
}
Expand Down Expand Up @@ -817,6 +820,12 @@ protected DruidSortRule(Config config) {

/** Rule configuration. */
public interface Config extends RelRule.Config {
Config DEFAULT = EMPTY
.withOperandSupplier(b0 ->
b0.operand(Sort.class).oneInput(b1 ->
b1.operand(DruidQuery.class).noInputs()))
.as(DruidSortRule.Config.class);

@Override default DruidSortRule toRule() {
return new DruidSortRule(this);
}
Expand Down

0 comments on commit 7404445

Please sign in to comment.