// it explicit. Since the RuleMatcher doesn't handle trees properly,
// we cheat and say that we match any node. Then we'll do the actual
// test in the transformers check method.
rulePlan = new RulePlan();
RuleOperator anyLogicalOperator = new RuleOperator(LogicalOperator.class, RuleOperator.NodeType.ANY_NODE,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(anyLogicalOperator);
mRules.add(new Rule<LogicalOperator, LogicalPlan>(rulePlan,
new ImplicitSplitInserter(plan), "ImplicitSplitInserter"));
// this one is ordered to be before other optimizations since later
// optimizations may move the LOFilter that is looks for just after a
// LOLoad
rulePlan = new RulePlan();
RuleOperator loLoad = new RuleOperator(LOLoad.class,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(loLoad);
mRules.add(new Rule<LogicalOperator, LogicalPlan>(rulePlan,
new PartitionFilterOptimizer(plan), "LoadPartitionFilterOptimizer"));
// Add type casting to plans where the schema has been declared (by
// user, data, or data catalog).
rulePlan = new RulePlan();
loLoad = new RuleOperator(LOLoad.class,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(loLoad);
mRules.add(new Rule<LogicalOperator, LogicalPlan>(rulePlan,
new TypeCastInserter(plan, LOLoad.class.getName()), "LoadTypeCastInserter"));
// Add type casting to plans where the schema has been declared by
// user in a statement with stream operator.
rulePlan = new RulePlan();
RuleOperator loStream= new RuleOperator(LOStream.class,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(loStream);
mRules.add(new Rule<LogicalOperator, LogicalPlan>(rulePlan, new TypeCastInserter(plan,
LOStream.class.getName()), "StreamTypeCastInserter"));
if(!turnAllRulesOff) {
// Push up limit wherever possible.
rulePlan = new RulePlan();
RuleOperator loLimit = new RuleOperator(LOLimit.class,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(loLimit);
Rule<LogicalOperator, LogicalPlan> rule = new Rule<LogicalOperator, LogicalPlan>(rulePlan,
new OpLimitOptimizer(plan, mode), "LimitOptimizer");
checkAndAddRule(rule);
// Push filters up wherever possible
rulePlan = new RulePlan();
RuleOperator loFilter = new RuleOperator(LOFilter.class,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(loFilter);
rule = new Rule<LogicalOperator, LogicalPlan>(rulePlan,
new PushUpFilter(plan), "PushUpFilter");
checkAndAddRule(rule);
// Push foreach with flatten down wherever possible
rulePlan = new RulePlan();
RuleOperator loForeach = new RuleOperator(LOForEach.class,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(loForeach);
rule = new Rule<LogicalOperator, LogicalPlan>(rulePlan,
new PushDownForeachFlatten(plan), "PushDownForeachFlatten");
checkAndAddRule(rule);
// Prune column up wherever possible
rulePlan = new RulePlan();
RuleOperator rulePruneColumnsOperator = new RuleOperator(RelationalOperator.class, RuleOperator.NodeType.ANY_NODE,
new OperatorKey(SCOPE, nodeIdGen.getNextNodeId(SCOPE)));
rulePlan.add(rulePruneColumnsOperator);
pruneRule = new Rule<LogicalOperator, LogicalPlan>(rulePlan,
new PruneColumns(plan), "PruneColumns", Rule.WalkerAlgo.ReverseDependencyOrderWalker);
}