final Collection<AbstractExpression> exps = PlanNodeUtil.getExpressionsForPlanNode(node);
// If this is the root node, then include the output columns + also
// include output columns if its a projection or limit node
if (is_root || node instanceof ProjectionPlanNode | node instanceof LimitPlanNode) {
for (Integer col_guid : node.getOutputColumnGUIDs()) {
PlanColumn col = state.plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null) {
exps.add(col.getExpression());
// root_column_expressions.addAll(ExpressionUtil.getExpressions(col.getExpression(),
// TupleValueExpression.class));
}
} // FOR
}
// PlanNode specific extractions
// ---------------------------------------------------
// AGGREGATE
// ---------------------------------------------------
if (node instanceof AggregatePlanNode) {
AggregatePlanNode agg_node = (AggregatePlanNode) node;
for (Integer col_guid : agg_node.getAggregateColumnGuids()) {
PlanColumn col = state.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 = state.plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null)
exps.add(col.getExpression());
} // FOR
// ---------------------------------------------------
// ORDER BY
// ---------------------------------------------------
} else if (node instanceof OrderByPlanNode) {
OrderByPlanNode orby_node = (OrderByPlanNode) node;
for (Integer col_guid : orby_node.getSortColumnGuids()) {
PlanColumn col = state.plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null)
exps.add(col.getExpression());
} // FOR
}
if (debug.val)
LOG.debug("Extracted " + exps.size() + " expressions from " + node);
// Now go through our expressions and extract out the columns that are
// referenced
StringBuilder sb = new StringBuilder();
for (AbstractExpression exp : exps) {
for (Column catalog_col : ExpressionUtil.getReferencedColumns(state.catalog_db, exp)) {
if (trace.val)
sb.append(String.format("\n%s => %s", node, catalog_col.fullName()));
state.addTableColumn(catalog_col);
state.addPlanNodeColumn(node, catalog_col);
} // FOR
} // FOR
if (trace.val && sb.length() > 0)
LOG.trace("Extracted Column References:" + sb);
// Populate our map from Column objects to PlanColumn GUIDs
for (Integer col_guid : node.getOutputColumnGUIDs()) {
PlanColumn col = state.plannerContext.get(col_guid);
assert (col != null) : "Invalid PlanColumn #" + col_guid;
if (col.getExpression() != null) {
Collection<Column> catalog_cols = ExpressionUtil.getReferencedColumns(state.catalog_db, col.getExpression());
// If there is more than one column, then it's some sort of
// compound expression
// So we don't want to include in our mapping
if (catalog_cols.size() == 1) {
state.addColumnMapping(CollectionUtil.first(catalog_cols), col_guid);