예제 #1
0
 private IncrementalIndex.SortedDimLookup getDimLookup() {
   if (dimLookup == null) {
     final IncrementalIndex.DimDim dimDim = dimensionDesc.getValues();
     if (hasNullValueDimensions.contains(dimensionDesc.getName()) && !dimDim.contains(null)) {
       dimDim.add(null);
     }
     dimLookup = dimDim.sort();
   }
   return dimLookup;
 }
예제 #2
0
  public IncrementalIndexAdapter(
      Interval dataInterval, IncrementalIndex<?> index, BitmapFactory bitmapFactory) {
    this.dataInterval = dataInterval;
    this.index = index;

    /* Sometimes it's hard to tell whether one dimension contains a null value or not.
     * If one dimension had show a null or empty value explicitly, then yes, it contains
     * null value. But if one dimension's values are all non-null, it still early to say
     * this dimension does not contain null value. Consider a two row case, first row had
     * "dimA=1" and "dimB=2", the second row only had "dimA=3". To dimB, its value are "2" and
     * never showed a null or empty value. But when we combines these two rows, dimB is null
     * in row 2. So we should iterate all rows to determine whether one dimension contains
     * a null value.
     */
    this.hasNullValueDimensions = Sets.newHashSet();

    final List<IncrementalIndex.DimensionDesc> dimensions = index.getDimensions();

    indexers = Maps.newHashMapWithExpectedSize(dimensions.size());
    for (IncrementalIndex.DimensionDesc dimension : dimensions) {
      indexers.put(dimension.getName(), new DimensionIndexer(dimension));
    }

    int rowNum = 0;
    for (IncrementalIndex.TimeAndDims timeAndDims : index.getFacts().keySet()) {
      final int[][] dims = timeAndDims.getDims();

      for (IncrementalIndex.DimensionDesc dimension : dimensions) {
        final int dimIndex = dimension.getIndex();
        DimensionIndexer indexer = indexers.get(dimension.getName());
        if (dimIndex >= dims.length || dims[dimIndex] == null) {
          hasNullValueDimensions.add(dimension.getName());
          continue;
        }
        final IncrementalIndex.DimDim values = dimension.getValues();
        if (hasNullValue(values, dims[dimIndex])) {
          hasNullValueDimensions.add(dimension.getName());
        }

        final MutableBitmap[] bitmapIndexes = indexer.invertedIndexes;

        for (Comparable dimIdxComparable : dims[dimIndex]) {
          Integer dimIdx = (Integer) dimIdxComparable;
          if (bitmapIndexes[dimIdx] == null) {
            bitmapIndexes[dimIdx] = bitmapFactory.makeEmptyMutableBitmap();
          }
          try {
            bitmapIndexes[dimIdx].add(rowNum);
          } catch (Exception e) {
            log.info(e.toString());
          }
        }
      }

      ++rowNum;
    }
  }
예제 #3
0
 private IncrementalIndex.DimDim getDimValues() {
   return dimensionDesc.getValues();
 }
예제 #4
0
 public DimensionIndexer(IncrementalIndex.DimensionDesc dimensionDesc) {
   this.dimensionDesc = dimensionDesc;
   this.invertedIndexes = new MutableBitmap[dimensionDesc.getValues().size() + 1];
 }