Пример #1
0
  /**
   * For the new segment, we need to create dictionaries for it, too. For those dictionaries on fact
   * table, create it by merging underlying dictionaries For those dictionaries on lookup table,
   * just copy it from any one of the merging segments, it's guaranteed to be consistent(checked in
   * CubeSegmentValidator)
   *
   * @param cube
   * @param newSeg
   * @throws IOException
   */
  private void makeDictForNewSegment(
      KylinConfig conf, CubeInstance cube, CubeSegment newSeg, List<CubeSegment> mergingSegments)
      throws IOException {
    HashSet<TblColRef> colsNeedMeringDict = new HashSet<TblColRef>();
    HashSet<TblColRef> colsNeedCopyDict = new HashSet<TblColRef>();
    DictionaryManager dictMgr = DictionaryManager.getInstance(conf);

    CubeDesc cubeDesc = cube.getDescriptor();

    for (TblColRef col : cubeDesc.getAllColumnsNeedDictionary()) {
      String dictTable = dictMgr.decideSourceData(cubeDesc.getModel(), true, col).getTable();
      if (cubeDesc.getFactTable().equalsIgnoreCase(dictTable)) {
        colsNeedMeringDict.add(col);
      } else {
        colsNeedCopyDict.add(col);
      }
    }

    for (TblColRef col : colsNeedMeringDict) {
      logger.info("Merging fact table dictionary on : " + col);
      List<DictionaryInfo> dictInfos = new ArrayList<DictionaryInfo>();
      for (CubeSegment segment : mergingSegments) {
        logger.info("Including fact table dictionary of segment : " + segment);
        if (segment.getDictResPath(col) != null) {
          DictionaryInfo dictInfo = dictMgr.getDictionaryInfo(segment.getDictResPath(col));
          if (dictInfo != null) {
            dictInfos.add(dictInfo);
          } else {
            logger.warn("Failed to load DictionaryInfo from " + segment.getDictResPath(col));
          }
        }
      }
      mergeDictionaries(dictMgr, newSeg, dictInfos, col);
    }

    for (TblColRef col : colsNeedCopyDict) {
      String path = mergingSegments.get(0).getDictResPath(col);
      newSeg.putDictResPath(col, path);
    }
  }