private void resolveColumnsAndReplaceAlias(CubeQueryContext cubeql, Set<ExprSpecContext> exprs) throws SemanticException { Set<ExprSpecContext> nestedExpressions = new LinkedHashSet<ExprSpecContext>(); for (ExprSpecContext esc : exprs) { for (Map.Entry<String, Set<String>> entry : esc.getTblAliasToColumns().entrySet()) { if (entry.getKey().equals(CubeQueryContext.DEFAULT_TABLE)) { continue; } AbstractBaseTable baseTable = (AbstractBaseTable) cubeql.getCubeTableForAlias(entry.getKey()); Set<String> exprCols = new HashSet<String>(); for (String col : entry.getValue()) { // col is an expression if (baseTable.getExpressionNames().contains(col)) { exprCols.add(col); } } // get all combinations of expression replaced with inner exprs AST. addAllNestedExpressions(cubeql, esc, baseTable, nestedExpressions, exprCols); } } for (ExprSpecContext esc : nestedExpressions) { esc.resolveColumns(cubeql); esc.replaceAliasInAST(cubeql); for (String table : esc.getTblAliasToColumns().keySet()) { try { if (!CubeQueryContext.DEFAULT_TABLE.equalsIgnoreCase(table) && !srcAlias.equals(table)) { cubeql.addOptionalDimTable( table, null, false, null, false, esc.getTblAliasToColumns().get(table).toArray(new String[0])); esc.exprDims.add((Dimension) cubeql.getCubeTableForAlias(table)); } } catch (HiveException e) { throw new SemanticException(e); } } } exprs.addAll(nestedExpressions); }
private void resolveColumnsAndAlias(CubeQueryContext cubeql) throws SemanticException { for (ExprSpecContext esc : allExprs) { esc.resolveColumns(cubeql); esc.replaceAliasInAST(cubeql); for (String table : esc.getTblAliasToColumns().keySet()) { try { if (!CubeQueryContext.DEFAULT_TABLE.equalsIgnoreCase(table) && !srcAlias.equals(table)) { cubeql.addOptionalDimTable( table, null, false, null, false, esc.getTblAliasToColumns().get(table).toArray(new String[0])); esc.exprDims.add((Dimension) cubeql.getCubeTableForAlias(table)); } } catch (HiveException e) { throw new SemanticException(e); } } } resolveColumnsAndReplaceAlias(cubeql, allExprs); }