switch (planNode.getType()) {
case PROJECT:
List<Column> columns = planNode.getPropertyAsList(Property.PROJECT_COLUMNS, Column.class);
for (int i = 0; i != columns.size(); ++i) {
Column column = columns.get(i);
SelectorName replacement = rewrittenSelectors.get(column.selectorName());
if (replacement != null) {
columns.set(i, new Column(replacement, column.getPropertyName(), column.getColumnName()));
}
}
break;
case SELECT:
Constraint constraint = planNode.getProperty(Property.SELECT_CRITERIA, Constraint.class);
Constraint newConstraint = replaceReferencesToRemovedSource(context, constraint, rewrittenSelectors);
if (constraint != newConstraint) {
planNode.setProperty(Property.SELECT_CRITERIA, newConstraint);
}
break;
case SORT:
List<Object> orderBys = planNode.getPropertyAsList(Property.SORT_ORDER_BY, Object.class);
if (orderBys != null && !orderBys.isEmpty()) {
if (orderBys.get(0) instanceof SelectorName) {
for (int i = 0; i != orderBys.size(); ++i) {
SelectorName selectorName = (SelectorName)orderBys.get(i);
SelectorName replacement = rewrittenSelectors.get(selectorName);
if (replacement != null) {
orderBys.set(i, replacement);
}
}
} else {
for (int i = 0; i != orderBys.size(); ++i) {
Ordering ordering = (Ordering)orderBys.get(i);
DynamicOperand operand = ordering.getOperand();
orderBys.set(i, replaceReferencesToRemovedSource(context, operand, rewrittenSelectors));
}
}
}
break;
case JOIN:
// Update the join condition ...
JoinCondition joinCondition = planNode.getProperty(Property.JOIN_CONDITION, JoinCondition.class);
JoinCondition newCondition = replaceReferencesToRemovedSource(context, joinCondition, rewrittenSelectors);
if (joinCondition != newCondition) {
planNode.setProperty(Property.JOIN_CONDITION, newCondition);
}
// Update the join criteria (if there are some) ...
List<Constraint> constraints = planNode.getPropertyAsList(Property.JOIN_CONSTRAINTS, Constraint.class);
if (constraints != null && !constraints.isEmpty()) {
for (int i = 0; i != constraints.size(); ++i) {
Constraint old = constraints.get(i);
Constraint replacement = replaceReferencesToRemovedSource(context, old, rewrittenSelectors);
if (replacement != old) {
constraints.set(i, replacement);
}
}
}
break;
case SOURCE:
// Check the source alias ...
SelectorName sourceAlias = planNode.getProperty(Property.SOURCE_ALIAS, SelectorName.class);
SelectorName replacement = rewrittenSelectors.get(sourceAlias);
if (replacement == null) {
// Try the source name ...
SelectorName sourceName = planNode.getProperty(Property.SOURCE_NAME, SelectorName.class);
replacement = rewrittenSelectors.get(sourceName);
}
if (replacement != null) {
planNode.setProperty(Property.SOURCE_ALIAS, replacement);
planNode.getSelectors().remove(sourceAlias);
planNode.getSelectors().add(replacement);
}
break;
case GROUP:
case SET_OPERATION:
case DUP_REMOVE:
case LIMIT:
case NULL:
case DEPENDENT_QUERY:
case ACCESS:
case INDEX:
// None of these have to be changed ...
break;
}
// Update the selectors referenced by the node ...
Set<SelectorName> selectorsToAdd = null;
for (Iterator<SelectorName> iter = planNode.getSelectors().iterator(); iter.hasNext();) {
SelectorName replacement = rewrittenSelectors.get(iter.next());
if (replacement != null) {
iter.remove();
if (selectorsToAdd == null) selectorsToAdd = new HashSet<SelectorName>();
selectorsToAdd.add(replacement);
}