Пример #1
0
 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);
     }
   }
 }