1.继承与单例
public class PushDownFilter extends RelOptRule {
public PushDownFilter(RelOptRuleOperand operand, String description) {
super(operand, "XXXXX:" + description);
}
// operand(LogicalTableScan.class, none())
public static final PushDownFilter XXXXX =
new PushDownFilter(operand(Bindables.BindableTableScan.class, any()), "XXXXX");
2.匹配与替换,注意各种上下文工具类,以下是靠谱的获取方式
@Override
public void onMatch(RelOptRuleCall call) {
Bindables.BindableTableScan bindableTableScan = (Bindables.BindableTableScan) call.rels[0];
RelOptCluster cluster = bindableTableScan.getCluster();//工具类
RelOptTable relOptTable = bindableTableScan.getTable();//包装表
RelOptSchema relOptSchema = bindableTableScan.getTable().getRelOptSchema();//schema信息
RelBuilder builder = call.builder();//关系表达式构建工具
MycatLogicTable logicTable = relOptTable.unwrap(MycatLogicTable.class);
call.transformTo(xxxx);