private void pickColumnsForTable(String tbl) throws LensException {
   if (tableToRefCols.containsKey(tbl)) {
     for (ReferencedQueriedColumn refered : tableToRefCols.get(tbl)) {
       Iterator<ChainRefCol> iter = refered.chainRefCols.iterator();
       while (iter.hasNext()) {
         // remove unreachable references
         ChainRefCol reference = iter.next();
         if (!cubeql
             .getAutoJoinCtx()
             .isReachableDim(
                 (Dimension) cubeql.getCubeTableForAlias(reference.getChainName()),
                 reference.getChainName())) {
           iter.remove();
         }
       }
       if (refered.chainRefCols.isEmpty()) {
         throw new LensException(
             LensCubeErrorCode.NO_REF_COL_AVAILABLE.getLensErrorInfo(), refered.col.getName());
       }
       PickedReference picked =
           new PickedReference(
               refered.chainRefCols.iterator().next(),
               cubeql.getAliasForTableName(refered.srcTable.getName()),
               tbl);
       addPickedReference(refered.col.getName(), picked);
       pickedRefs.add(picked);
     }
   }
 }
 // When candidate table does not have the field, this method checks
 // if the field can be reached through reference,
 // if yes adds the ref usage and returns to true, if not returns false.
 boolean addRefUsage(CandidateTable table, String col, String srcTbl) throws LensException {
   // available as referenced col
   if (referencedCols.containsKey(col)) {
     for (ReferencedQueriedColumn refer : referencedCols.get(col)) {
       if (refer.srcTable.getName().equalsIgnoreCase(srcTbl)) {
         // check if reference source column is available in src table?
         // should not be required here. Join resolution will figure out if
         // there is no path
         // to the source table
         log.info("Adding denormalized column for column:{} for table:{}", col, table);
         Set<ReferencedQueriedColumn> refCols = tableToRefCols.get(table.getName());
         if (refCols == null) {
           refCols = new HashSet<>();
           tableToRefCols.put(table.getName(), refCols);
         }
         refCols.add(refer);
         // Add to optional tables
         for (ChainRefCol refCol : refer.col.getChainRefColumns()) {
           cubeql.addOptionalDimTable(
               refCol.getChainName(),
               table,
               false,
               refer.col.getName(),
               true,
               refCol.getRefColumn());
         }
         return true;
       }
     }
   }
   return false;
 }