Class RelRule<C extends RelRule.Config>
- 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
,ArrowRules.ArrowFilterRule
,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
,MeasureRules.AggregateMeasure2Rule
,MeasureRules.AggregateMeasureRule
,MeasureRules.FilterSortMeasureRule
,MeasureRules.ProjectMeasureRule
,MeasureRules.ProjectSortMeasureRule
,MinusToDistinctRule
,MultiJoinOptimizeBushyRule
,PigToSqlAggregateRule
,ProjectAggregateMergeRule
,ProjectCalcMergeRule
,ProjectCorrelateTransposeRule
,ProjectFilterTransposeRule
,ProjectJoinJoinRemoveRule
,ProjectJoinRemoveRule
,ProjectJoinTransposeRule
,ProjectMergeRule
,ProjectMultiJoinMergeRule
,ProjectOverSumToSum0Rule
,ProjectRemoveRule
,ProjectSetOpTransposeRule
,ProjectTableScanRule
,ProjectToCalcRule
,ProjectToWindowRule
,ProjectWindowTransposeRule
,PruneEmptyRules.PruneEmptyRule
,ReduceDecimalsRule
,ReduceExpressionsRule
,RelDecorrelator.AdjustProjectForCountAggregateRule
,RelDecorrelator.RemoveCorrelationForScalarAggregateRule
,RelDecorrelator.RemoveCorrelationForScalarProjectRule
,RelDecorrelator.RemoveSingleAggregateRule
,SampleToFilterRule
,SemiJoinFilterTransposeRule
,SemiJoinJoinTransposeRule
,SemiJoinProjectTransposeRule
,SemiJoinRemoveRule
,SemiJoinRule
,SingleValuesOptimizationRules.PruneSingleValueRule
,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
,UnionToValuesRule
,ValuesReduceRule
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();
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Rule configuration.static interface
Indicates that an operand is complete.static interface
RelRule.MatchHandler<R extends RelOptRule>
Callback interface that helps you avoid creating sub-classes ofRelRule
that differ only in implementations ofRelOptRule.onMatch(RelOptRuleCall)
method.static interface
Callback to create an operand.static interface
RelRule.OperandDetailBuilder<R extends RelNode>
Add details about an operand, such as its inputs.static interface
Function that creates an operand.Nested classes/interfaces inherited from class org.apache.calcite.plan.RelOptRule
RelOptRule.ConverterRelOptRuleOperand
-
Field Summary
Fields inherited from class org.apache.calcite.plan.RelOptRule
description, operands, relBuilderFactory
-
Constructor Summary
-
Method Summary
Methods inherited from class org.apache.calcite.plan.RelOptRule
any, convert, convert, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, onMatch, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered
-
Field Details
-
config
-
-
Constructor Details
-
RelRule
Creates a RelRule.
-