// Replace TVE for display columns
if (m_projectSchema == null) {
m_projectSchema = new NodeSchema();
for (ParsedColInfo col : m_displayColumns) {
AbstractExpression expr = col.expression;
if (hasComplexAgg()) {
expr = col.expression.replaceWithTVE(aggTableIndexMap, indexToColumnMap);
}
SchemaColumn schema_col = new SchemaColumn(col.tableName, col.tableAlias, col.columnName, col.alias, expr);
m_projectSchema.addColumn(schema_col);
}
}
// Replace TVE for order by columns
for (ParsedColInfo orderCol : m_orderColumns) {
AbstractExpression expr = orderCol.expression.replaceWithTVE(aggTableIndexMap, indexToColumnMap);
if (hasComplexAgg()) {
orderCol.expression = expr;
} else {
// This if case checking is to rule out cases like: select PKEY + A_INT from O1 order by PKEY + A_INT,
// This case later needs a projection node on top of sort node to make it work.
// Assuming the restrictions: Order by columns are (1) columns from table
// (2) tag from display columns (3) actual expressions from display columns
// Currently, we do not allow order by complex expressions that are not in display columns
// If there is a complexGroupby at his point, it means that Display columns contain all the order by columns.
// In that way, this plan does not require another projection node on top of sort node.
if (orderCol.expression.hasAnySubexpressionOfClass(AggregateExpression.class) ||
hasComplexGroupby()) {
orderCol.expression = expr;
}
}
}
// Replace TVE for group by columns
m_groupByExpressions = new HashMap<String, AbstractExpression>();
for (ParsedColInfo groupbyCol: m_groupByColumns) {
assert(aggTableIndexMap.get(groupbyCol.expression) != null);
assert(m_groupByExpressions.get(groupbyCol.alias) == null);
AbstractExpression expr = groupbyCol.expression.replaceWithTVE(aggTableIndexMap, indexToColumnMap);
m_groupByExpressions.put(groupbyCol.alias,expr);
}
if (m_having != null) {
m_having = m_having.replaceWithTVE(aggTableIndexMap, indexToColumnMap);