private String getStorageStringWithAlias(
     CandidateFact fact, Map<Dimension, CandidateDim> dimsToQuery, String alias) {
   if (cubeTbls.get(alias) instanceof CubeInterface) {
     return fact.getStorageString(alias);
   } else {
     return dimsToQuery.get(cubeTbls.get(alias)).getStorageString(alias);
   }
 }
  private void getQLString(
      QBJoinTree joinTree,
      StringBuilder builder,
      CandidateFact fact,
      Map<Dimension, CandidateDim> dimsToQuery)
      throws LensException {
    List<String> joiningTables = new ArrayList<>();
    if (joinTree.getBaseSrc()[0] == null) {
      if (joinTree.getJoinSrc() != null) {
        getQLString(joinTree.getJoinSrc(), builder, fact, dimsToQuery);
      }
    } else { // (joinTree.getBaseSrc()[0] != null){
      String alias = joinTree.getBaseSrc()[0].toLowerCase();
      builder.append(getStorageStringWithAlias(fact, dimsToQuery, alias));
      joiningTables.add(alias);
    }
    if (joinTree.getJoinCond() != null) {
      builder.append(JoinUtils.getJoinTypeStr(joinTree.getJoinCond()[0].getJoinType()));
      builder.append(" JOIN ");
    }
    if (joinTree.getBaseSrc()[1] == null) {
      if (joinTree.getJoinSrc() != null) {
        getQLString(joinTree.getJoinSrc(), builder, fact, dimsToQuery);
      }
    } else { // (joinTree.getBaseSrc()[1] != null){
      String alias = joinTree.getBaseSrc()[1].toLowerCase();
      builder.append(getStorageStringWithAlias(fact, dimsToQuery, alias));
      joiningTables.add(alias);
    }

    String joinCond = joinConds.get(joinTree);
    if (joinCond != null) {
      builder.append(" ON ");
      builder.append(joinCond);
      // joining tables will contain all tables involved in joins.
      // we need to push storage filters for Dimensions into join conditions, thus the following
      // code
      // takes care of the same.
      for (String joiningTable : joiningTables) {
        if (cubeTbls.get(joiningTable) instanceof Dimension) {
          DimOnlyHQLContext.appendWhereClause(
              builder, getWhereClauseWithAlias(dimsToQuery, joiningTable), true);
          dimsToQuery.get(cubeTbls.get(joiningTable)).setWhereClauseAdded(joiningTable);
        }
      }
    } else {
      throw new LensException(LensCubeErrorCode.NO_JOIN_CONDITION_AVAILABLE.getLensErrorInfo());
    }
  }
 private void addOptionalDimTable(
     String alias,
     CandidateTable candidate,
     boolean isRequiredInJoin,
     String cubeCol,
     boolean isRef,
     String tableAlias,
     String... cols)
     throws LensException {
   alias = alias.toLowerCase();
   if (!addQueriedTable(alias, true)) {
     throw new LensException(LensCubeErrorCode.QUERIED_TABLE_NOT_FOUND.getLensErrorInfo(), alias);
   }
   Dimension dim = (Dimension) cubeTbls.get(alias);
   Aliased<Dimension> aliasedDim = Aliased.create(dim, alias);
   OptionalDimCtx optDim = optionalDimensionMap.get(aliasedDim);
   if (optDim == null) {
     optDim = new OptionalDimCtx();
     optionalDimensionMap.put(aliasedDim, optDim);
   }
   if (cols != null && candidate != null) {
     for (String col : cols) {
       optDim.colQueried.add(col);
     }
     optDim.requiredForCandidates.add(candidate);
   }
   if (cubeCol != null) {
     if (isRef) {
       updateRefColDim(cubeCol, aliasedDim);
     } else {
       updateExprColDim(tableAlias, cubeCol, aliasedDim);
     }
   }
   if (!optDim.isRequiredInJoinChain) {
     optDim.isRequiredInJoinChain = isRequiredInJoin;
   }
   if (log.isDebugEnabled()) {
     log.debug(
         "Adding optional dimension:{} optDim:{} {} isRef:{}",
         aliasedDim,
         optDim,
         (cubeCol == null ? "" : " for column:" + cubeCol),
         isRef);
   }
 }
 String getQBFromString(CandidateFact fact, Map<Dimension, CandidateDim> dimsToQuery)
     throws LensException {
   String fromString;
   if (getJoinAST() == null) {
     if (cube != null) {
       if (dimensions.size() > 0) {
         throw new LensException(LensCubeErrorCode.NO_JOIN_CONDITION_AVAILABLE.getLensErrorInfo());
       }
       fromString = fact.getStorageString(getAliasForTableName(cube.getName()));
     } else {
       if (dimensions.size() != 1) {
         throw new LensException(LensCubeErrorCode.NO_JOIN_CONDITION_AVAILABLE.getLensErrorInfo());
       }
       Dimension dim = dimensions.iterator().next();
       fromString = dimsToQuery.get(dim).getStorageString(getAliasForTableName(dim.getName()));
     }
   } else {
     StringBuilder builder = new StringBuilder();
     getQLString(qb.getQbJoinTree(), builder, fact, dimsToQuery);
     fromString = builder.toString();
   }
   return fromString;
 }
 private String getWhereClauseWithAlias(Map<Dimension, CandidateDim> dimsToQuery, String alias) {
   return StorageUtil.getWhereClause(dimsToQuery.get(cubeTbls.get(alias)), alias);
 }
 public AbstractCubeTable getCubeTableForAlias(String alias) {
   return cubeTbls.get(alias);
 }
 public String getAlias(String expr) {
   return exprToAlias.get(expr);
 }