throws AlgebricksException {
// TODO Fix EliminateSubplanForSinglePathsRule to check for variables used after the subplan.
// TODO Add back to the rewrite rule list once fixed.
// Do not process empty or nested tuple source.
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE
|| op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
return false;
}
// Set cardinality in the context. Must update each time the rule is run.
VXQueryOptimizationContext vxqueryContext = (VXQueryOptimizationContext) context;
Cardinality cardinalityVariable = CardinalityRuleToolbox.getProducerCardinality(opRef.getValue(), vxqueryContext);
// Track variables created
// Track variables used
if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN && cardinalityVariable == Cardinality.ONE) {
SubplanOperator subplan = (SubplanOperator) op;
AbstractLogicalOperator subplanOp = (AbstractLogicalOperator) subplan.getNestedPlans().get(0).getRoots()
.get(0).getValue();
if (subplanOp.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
return false;
}
// Change plan to remove the subplan.
opRef.setValue(subplanOp);
// Make inline the arguments for the subplan.
AbstractLogicalOperator subplanEnd = findLastSubplanOperator(subplanOp);
subplanEnd.getInputs().get(0).setValue(subplan.getInputs().get(0).getValue());
}
// Now with the new operator, update the variable mappings.
cardinalityVariable = CardinalityRuleToolbox.updateCardinalityVariable(op, cardinalityVariable, vxqueryContext);