private void addRefColsQueried( CubeQueryContext cubeql, TrackQueriedColumns tqc, DenormalizationContext denormCtx) { for (Map.Entry<String, Set<String>> entry : tqc.getTblAliasToColumns().entrySet()) { // skip default alias if (entry.getKey() == CubeQueryContext.DEFAULT_TABLE) { continue; } // skip join chain aliases if (cubeql.getJoinchains().keySet().contains(entry.getKey().toLowerCase())) { continue; } AbstractCubeTable tbl = cubeql.getCubeTableForAlias(entry.getKey()); Set<String> columns = entry.getValue(); for (String column : columns) { CubeColumn col; if (tbl instanceof CubeInterface) { col = ((CubeInterface) tbl).getColumnByName(column); } else { col = ((Dimension) tbl).getColumnByName(column); } if (col instanceof ReferencedDimAttribute) { // considering all referenced dimensions to be denormalized columns denormCtx.addReferencedCol( column, new ReferencedQueriedColumn((ReferencedDimAttribute) col, tbl)); } } } }
static void extractTabAliasForCol(CubeQueryContext cubeql, TrackQueriedColumns tqc) throws LensException { Map<String, String> colToTableAlias = cubeql.getColToTableAlias(); Set<String> columns = tqc.getTblAliasToColumns().get(CubeQueryContext.DEFAULT_TABLE); if (columns == null) { return; } for (String col : columns) { boolean inCube = false; if (cubeql.getCube() != null) { Set<String> cols = cubeql.getCube().getAllFieldNames(); if (cols.contains(col.toLowerCase())) { String cubeAlias = cubeql.getAliasForTableName(cubeql.getCube().getName()); colToTableAlias.put(col.toLowerCase(), cubeAlias); tqc.addColumnsQueried(cubeAlias, col.toLowerCase()); inCube = true; } } for (Dimension dim : cubeql.getDimensions()) { if (dim.getAllFieldNames().contains(col.toLowerCase())) { if (!inCube) { String prevDim = colToTableAlias.get(col.toLowerCase()); if (prevDim != null && !prevDim.equals(dim.getName())) { throw new LensException( LensCubeErrorCode.AMBIGOUS_DIM_COLUMN.getLensErrorInfo(), col, prevDim, dim.getName()); } String dimAlias = cubeql.getAliasForTableName(dim.getName()); colToTableAlias.put(col.toLowerCase(), dimAlias); tqc.addColumnsQueried(dimAlias, col.toLowerCase()); } else { // throw error because column is in both cube and dimension table throw new LensException( LensCubeErrorCode.AMBIGOUS_CUBE_COLUMN.getLensErrorInfo(), col, cubeql.getCube().getName(), dim.getName()); } } } if (colToTableAlias.get(col.toLowerCase()) == null) { throw new LensException(LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo(), col); } } }