private void placeTVEsinColumns ( ) { // Build the association between the table column with its index Map < AbstractExpression , Integer > aggTableIndexMap = new HashMap <> ( ) ; Map < Integer , ParsedColInfo > indexToColumnMap = new HashMap <> ( ) ; int index = 0 ; for ( ParsedColInfo col : m_aggResultColumns ) { aggTableIndexMap . put ( col . m_expression , index ) ; if ( col . m_alias == null ) { // hack any unique string col . m_alias = "$$_" + col . m_expression . getExpressionType ( ) . symbol ( ) + "_$$_" + index ; } indexToColumnMap . put ( index , col ) ; index ++ ; } // Replace TVE for group by columns m_groupByExpressions = new HashMap <> ( ) ; for ( ParsedColInfo groupbyCol : m_groupByColumns ) { AbstractExpression expr = groupbyCol . m_expression ; assert ( aggTableIndexMap . get ( expr ) != null ) ; expr = expr . replaceWithTVE ( aggTableIndexMap , indexToColumnMap ) ; m_groupByExpressions . put ( groupbyCol . m_alias , expr ) ; } if ( m_having != null ) { m_having = m_having . replaceWithTVE ( aggTableIndexMap , indexToColumnMap ) ; ExpressionUtil . finalizeValueTypes ( m_having ) ; } // Replace TVE for display columns m_projectSchema = new NodeSchema ( ) ; for ( ParsedColInfo col : m_displayColumns ) { AbstractExpression expr = col . m_expression ; if ( hasComplexAgg ( ) ) { expr = expr . replaceWithTVE ( aggTableIndexMap , indexToColumnMap ) ; } m_projectSchema . addColumn ( col . m_tableName , col . m_tableAlias , col . m_columnName , col . m_alias , expr , col . m_differentiator ) ; } // DISTINCT group by expressions are already TVEs when set placeTVEsForOrderby ( aggTableIndexMap , indexToColumnMap ) ; }
Generate new output Schema and Place TVEs for display columns if needed . Place TVEs for order by columns always .