C - Configuration typepublic abstract class RelRule<C extends RelRule.Config> extends RelOptRule
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();
| Modifier and Type | Class and Description |
|---|---|
static interface |
RelRule.Config
Rule configuration.
|
static interface |
RelRule.Done
Indicates that an operand is complete.
|
static interface |
RelRule.MatchHandler<R extends RelOptRule>
Callback interface that helps you avoid creating sub-classes of
RelRule that differ only in implementations of
RelOptRule.onMatch(RelOptRuleCall) method. |
static interface |
RelRule.OperandBuilder
Callback to create an operand.
|
static interface |
RelRule.OperandDetailBuilder<R extends RelNode>
Add details about an operand, such as its inputs.
|
static interface |
RelRule.OperandTransform
Function that creates an operand.
|
RelOptRule.ConverterRelOptRuleOperand| Modifier and Type | Field and Description |
|---|---|
C |
config |
description, operands, relBuilderFactory| Modifier | Constructor and Description |
|---|---|
protected |
RelRule(C config)
Creates a RelRule.
|
any, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, onMatch, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unorderedpublic final C extends RelRule.Config config
protected RelRule(C config)
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.