* @param node
* @param exps
* @return
*/
public static Collection<AbstractExpression> getExpressionsForPlanNode(AbstractPlanNode node, Set<AbstractExpression> exps, PlanNodeType... exclude) {
final PlannerContext plannerContext = PlannerContext.singleton();
final PlanNodeType node_type = node.getPlanNodeType();
for (PlanNodeType e : exclude) {
if (node_type == e)
return (exps);
} // FOR
switch (node_type) {
// ---------------------------------------------------
// SCANS
// ---------------------------------------------------
case INDEXSCAN: {
IndexScanPlanNode idx_node = (IndexScanPlanNode) node;
if (idx_node.getEndExpression() != null)
exps.add(idx_node.getEndExpression());
for (AbstractExpression exp : idx_node.getSearchKeyExpressions()) {
if (exp != null)
exps.add(exp);
} // FOR
// Fall through down into SEQSCAN....
}
case SEQSCAN: {
AbstractScanPlanNode scan_node = (AbstractScanPlanNode) node;
if (scan_node.getPredicate() != null)
exps.add(scan_node.getPredicate());
break;
}
// ---------------------------------------------------
// JOINS
// ---------------------------------------------------
case NESTLOOP:
case NESTLOOPINDEX: {
AbstractJoinPlanNode cast_node = (AbstractJoinPlanNode) node;
if (cast_node.getPredicate() != null)
exps.add(cast_node.getPredicate());
// We always need to look at the inline scan nodes for joins
for (AbstractPlanNode inline_node : cast_node.getInlinePlanNodes().values()) {
if (inline_node instanceof AbstractScanPlanNode) {
PlanNodeUtil.getExpressionsForPlanNode(inline_node, exps);
}
} // FOR
break;
}
// ---------------------------------------------------
// PROJECTION
// ---------------------------------------------------
case MATERIALIZE:
case PROJECTION: {
for (Integer col_guid : node.getOutputColumnGUIDs()) {
PlanColumn col = plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null)
exps.add(col.getExpression());
} // FOR
break;
}
// ---------------------------------------------------
// AGGREGATE
// ---------------------------------------------------
case AGGREGATE:
case HASHAGGREGATE: {
AggregatePlanNode agg_node = (AggregatePlanNode) node;
for (Integer col_guid : agg_node.getAggregateColumnGuids()) {
PlanColumn col = plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null)
exps.add(col.getExpression());
} // FOR
for (Integer col_guid : agg_node.getGroupByColumnGuids()) {
PlanColumn col = plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null)
exps.add(col.getExpression());
} // FOR
break;
}
// ---------------------------------------------------
// ORDERBY
// ---------------------------------------------------
case ORDERBY: {
OrderByPlanNode orby_node = (OrderByPlanNode) node;
for (Integer col_guid : orby_node.getSortColumnGuids()) {
PlanColumn col = plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null)
exps.add(col.getExpression());
} // FOR
break;