@Override public void rewriteContext(CubeQueryContext cubeql) throws LensException { Map<String, String> colToTableAlias = cubeql.getColToTableAlias(); extractTabAliasForCol(cubeql); findDimAttributesAndMeasures(cubeql); if (colToTableAlias.isEmpty()) { return; } // Rewrite the all the columns in the query with table alias prefixed. // If col1 of table tab1 is accessed, it would be changed as tab1.col1. // If tab1 is already aliased say with t1, col1 is changed as t1.col1 // replace the columns in select, groupby, having, orderby by // prepending the table alias to the col // sample select trees // 1: (TOK_SELECT (TOK_SELEXPR (TOK_TABLE_OR_COL key)) // (TOK_SELEXPR (TOK_FUNCTION count (TOK_TABLE_OR_COL value)))) // 2: (TOK_SELECT (TOK_SELEXPR (. (TOK_TABLE_OR_COL src) key)) // (TOK_SELEXPR (TOK_FUNCTION count (. (TOK_TABLE_OR_COL src) value)))) // 3: (TOK_SELECT (TOK_SELEXPR (. (TOK_TABLE_OR_COL src) key) srckey)))) replaceAliases(cubeql.getSelectAST(), 0, colToTableAlias); replaceAliases(cubeql.getHavingAST(), 0, colToTableAlias); replaceAliases(cubeql.getOrderByAST(), 0, colToTableAlias); replaceAliases(cubeql.getGroupByAST(), 0, colToTableAlias); replaceAliases(cubeql.getWhereAST(), 0, colToTableAlias); replaceAliases(cubeql.getJoinAST(), 0, colToTableAlias); // Update the aggregate expression set AggregateResolver.updateAggregates(cubeql.getSelectAST(), cubeql); AggregateResolver.updateAggregates(cubeql.getHavingAST(), cubeql); // Update alias map as well updateAliasMap(cubeql.getSelectAST(), cubeql); }
public void replaceAliasInAST(CubeQueryContext cubeql) throws SemanticException { AliasReplacer.extractTabAliasForCol(cubeql, this); AliasReplacer.replaceAliases(finalAST, 0, cubeql.getColToTableAlias()); }
private void extractTabAliasForCol(CubeQueryContext cubeql) throws LensException { extractTabAliasForCol(cubeql, cubeql); }