Class RelRule<C extends RelRule.Config>

java.lang.Object
org.apache.calcite.plan.RelOptRule
org.apache.calcite.plan.RelRule<C>
Type Parameters:
C - Configuration type
Direct Known Subclasses:
AbstractConverter.ExpandConversionRule, AbstractJoinExtractFilterRule, AggregateCaseToFilterRule, AggregateExpandDistinctAggregatesRule, AggregateExpandWithinDistinctRule, AggregateExtractProjectRule, AggregateFilterTransposeRule, AggregateJoinJoinRemoveRule, AggregateJoinRemoveRule, AggregateJoinTransposeRule, AggregateMergeRule, AggregateProjectConstantToDummyJoinRule, AggregateProjectMergeRule, AggregateProjectPullUpConstantsRule, AggregateReduceFunctionsRule, AggregateRemoveRule, AggregateStarTableRule, AggregateUnionAggregateRule, AggregateUnionTransposeRule, AggregateValuesRule, Bindables.BindableTableScanRule, CalcMergeRule, CalcRemoveRule, CalcSplitRule, CassandraRules.CassandraFilterRule, CassandraRules.CassandraLimitRule, CassandraRules.CassandraSortRule, CoerceInputsRule, CommonRelSubExprRule, ConverterRule, CsvProjectTableScanRule, CsvProjectTableScanRule, DateRangeRules.FilterDateRangeRule, DruidRules.DruidAggregateProjectRule, DruidRules.DruidAggregateRule, DruidRules.DruidFilterRule, DruidRules.DruidHavingFilterRule, DruidRules.DruidPostAggregationProjectRule, DruidRules.DruidProjectRule, DruidRules.DruidSortRule, EnumerableBatchNestedLoopJoinRule, EnumerableFilterToCalcRule, EnumerableLimitRule, EnumerableLimitSortRule, EnumerableMergeUnionRule, ExchangeRemoveConstantKeysRule, FilterAggregateTransposeRule, FilterCalcMergeRule, FilterCorrelateRule, FilterFlattenCorrelatedConditionRule, FilterJoinRule, FilterMergeRule, FilterMultiJoinMergeRule, FilterProjectTransposeRule, FilterRemoveIsNotDistinctFromRule, FilterSampleTransposeRule, FilterSetOpTransposeRule, FilterTableFunctionTransposeRule, FilterTableScanRule, FilterToCalcRule, FilterWindowTransposeRule, GeodeRules.GeodeFilterRule, GeodeRules.GeodeSortLimitRule, InnodbRules.InnodbFilterRule, InnodbRules.InnodbSortFilterRule, InnodbRules.InnodbSortTableScanRule, IntersectToDistinctRule, JoinAddRedundantSemiJoinRule, JoinAssociateRule, JoinCommuteRule, JoinDeriveIsNotNullFilterRule, JoinProjectTransposeRule, JoinPushExpressionsRule, JoinPushThroughJoinRule, JoinPushTransitivePredicatesRule, JoinToCorrelateRule, JoinToMultiJoinRule, JoinUnionTransposeRule, LoptOptimizeJoinRule, MatchRule, MaterializedViewFilterScanRule, MaterializedViewRule, MinusToDistinctRule, MultiJoinOptimizeBushyRule, PigToSqlAggregateRule, ProjectAggregateMergeRule, ProjectCalcMergeRule, ProjectCorrelateTransposeRule, ProjectFilterTransposeRule, ProjectJoinJoinRemoveRule, ProjectJoinRemoveRule, ProjectJoinTransposeRule, ProjectMergeRule, ProjectMultiJoinMergeRule, ProjectRemoveRule, ProjectSetOpTransposeRule, ProjectTableScanRule, ProjectToCalcRule, ProjectToWindowRule, ProjectWindowTransposeRule, PruneEmptyRules.PruneEmptyRule, ReduceDecimalsRule, ReduceExpressionsRule, RelDecorrelator.AdjustProjectForCountAggregateRule, RelDecorrelator.RemoveCorrelationForScalarAggregateRule, RelDecorrelator.RemoveCorrelationForScalarProjectRule, RelDecorrelator.RemoveSingleAggregateRule, SampleToFilterRule, SemiJoinFilterTransposeRule, SemiJoinJoinTransposeRule, SemiJoinProjectTransposeRule, SemiJoinRemoveRule, SemiJoinRule, SortJoinCopyRule, SortJoinTransposeRule, SortMergeRule, SortProjectTransposeRule, SortRemoveConstantKeysRule, SortRemoveRedundantRule, SortRemoveRule, SortUnionTransposeRule, SpatialRules.FilterHilbertRule, SplunkPushDownRule, StreamRules.DeltaAggregateTransposeRule, StreamRules.DeltaFilterTransposeRule, StreamRules.DeltaJoinTransposeRule, StreamRules.DeltaProjectTransposeRule, StreamRules.DeltaSortTransposeRule, StreamRules.DeltaTableScanRule, StreamRules.DeltaTableScanToEmptyRule, StreamRules.DeltaUnionTransposeRule, SubQueryRemoveRule, TableScanRule, TraitMatchingRule, UnionEliminatorRule, UnionMergeRule, UnionPullUpConstantsRule, UnionToDistinctRule, ValuesReduceRule

public abstract class RelRule<C extends RelRule.Config> extends RelOptRule
Rule that is parameterized via a configuration.

Eventually (before Calcite version 2.0), this class will replace RelOptRule. Constructors of RelOptRule are deprecated, so new rule classes should extend RelRule, not RelOptRule. Next, we will deprecate RelOptRule, so that variables that reference rules will be of type RelRule.

Guidelines for writing rules

1. If your rule is a sub-class of ConverterRule and does not need any extra properties, there's no need to create an interface Config inside your class. In your class, create a constant public static final Config DEFAULT_CONFIG. Goto step 5.

2. If your rule is not a sub-class of ConverterRule, create an inner interface Config extends RelRule.Config and annotate it with @Value.Immutable. Note, if your inner class is two levels deep (e.g. top-level Rule with Config inside), we recommend you annotate the outer class with @Value.Enclosing which will instruct the annotation processor to put your generated value class inside a new Immutable outer class. If your rule is three levels deep, the best thing to do is give your class a unique name to avoid any generated code class name overlaps. Implement toRule using a default method:

@Override default CsvProjectTableScanRule toRule() {
  return new CsvProjectTableScanRule(this);
}

3. For each configuration property, create a pair of methods in your Config interface. For example, for a property foo of type int, create methods foo and withFoo:


 /** Returns foo. */
 int foo();

 /** Sets {@link #foo}. */
 Config withFoo(int x);
 

4. In your Config interface, create a DEFAULT constant that represents the most typical configuration of your rule. This default will leverage the Immutables class generated by the Annotation Processor based on the annotation you provided above. For example, CsvProjectTableScanRule.Config has the following:


 Config DEFAULT = ImmutableCsvProjectTableScanRule.Config.builder()
     .withOperandSupplier(b0 ->
         b0.operand(LogicalProject.class).oneInput(b1 ->
             b1.operand(CsvTableScan.class).noInputs()))
      .build();
 

5. Do not create an INSTANCE constant inside your rule. Instead, create a named instance of your rule, with default configuration, in a holder class. The holder class must not be a sub-class of RelOptRule (otherwise cyclic class-loading issues may arise). Generally it will be called XxxRules, for example CsvRules. The rule instance is named after your rule, and is based on the default config (Config.DEFAULT, or DEFAULT_CONFIG for converter rules):


 /** Rule that matches a {@code Project} on a
  * {@code CsvTableScan} and pushes down projects if possible. */
 public static final CsvProjectTableScanRule PROJECT_SCAN =
     CsvProjectTableScanRule.Config.DEFAULT.toRule();
 
  • Field Details

  • Constructor Details

    • RelRule

      protected RelRule(C config)
      Creates a RelRule.