Package com.metamx.collections.bitmap

Examples of com.metamx.collections.bitmap.BitmapFactory


  private RTree roaringtree;

  @Before
  public void setUp() throws Exception
  {
    BitmapFactory bf = new ConciseBitmapFactory();
    tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf );
    BitmapFactory rbf = new RoaringBitmapFactory();
    roaringtree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, rbf), rbf );

  }
View Full Code Here


          VSizeIndexedInts singleValCol = null;
          VSizeIndexed multiValCol = VSizeIndexed.readFromByteBuffer(dimBuffer.asReadOnlyBuffer());
          GenericIndexed<ImmutableBitmap> bitmaps = bitmapIndexes.get(dimension);
          ImmutableRTree spatialIndex = spatialIndexes.get(dimension);

          final BitmapFactory bitmapFactory = bitmapSerdeFactory.getBitmapFactory();
          boolean onlyOneValue = true;
          MutableBitmap nullsSet = null;
          for (int i = 0; i < multiValCol.size(); ++i) {
            VSizeIndexedInts rowValue = multiValCol.get(i);
            if (!onlyOneValue) {
              break;
            }
            if (rowValue.size() > 1) {
              onlyOneValue = false;
            }
            if (rowValue.size() == 0) {
              if (nullsSet == null) {
                nullsSet = bitmapFactory.makeEmptyMutableBitmap();
              }
              nullsSet.add(i);
            }
          }

          if (onlyOneValue) {
            log.info("Dimension[%s] is single value, converting...", dimension);
            final boolean bumpedDictionary;
            if (nullsSet != null) {
              log.info("Dimension[%s] has null rows.", dimension);
              final ImmutableBitmap theNullSet = bitmapFactory.makeImmutableBitmap(nullsSet);

              if (dictionary.get(0) != null) {
                log.info("Dimension[%s] has no null value in the dictionary, expanding...", dimension);
                bumpedDictionary = true;
                final List<String> nullList = Lists.newArrayList();
                nullList.add(null);

                dictionary = GenericIndexed.fromIterable(
                    Iterables.concat(nullList, dictionary),
                    GenericIndexed.stringStrategy
                );

                bitmaps = GenericIndexed.fromIterable(
                    Iterables.concat(Arrays.asList(theNullSet), bitmaps),
                    bitmapSerdeFactory.getObjectStrategy()
                );
              } else {
                bumpedDictionary = false;
                bitmaps = GenericIndexed.fromIterable(
                    Iterables.concat(
                        Arrays.asList(
                            bitmapFactory
                                .union(Arrays.asList(theNullSet, bitmaps.get(0)))
                        ),
                        Iterables.skip(bitmaps, 1)
                    ),
                    bitmapSerdeFactory.getObjectStrategy()
View Full Code Here

      boolean isSpatialDim = columnCapabilities.get(dimension).hasSpatialIndexes();
      ByteBufferWriter<ImmutableRTree> spatialWriter = null;
      RTree tree = null;
      IOPeon spatialIoPeon = new TmpFileIOPeon();
      if (isSpatialDim) {
        BitmapFactory bitmapFactory = bitmapSerdeFactory.getBitmapFactory();
        spatialWriter = new ByteBufferWriter<ImmutableRTree>(
            spatialIoPeon, dimension, new IndexedRTree.ImmutableRTreeObjectStrategy(bitmapFactory)
        );
        spatialWriter.open();
        tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bitmapFactory), bitmapFactory);
View Full Code Here

    ColumnDictionaryEntryStore adder = hasMultipleValues
                                       ? new MultiValColumnDictionaryEntryStore()
                                       : new SingleValColumnDictionaryEntryStore();

    final BitmapFactory bitmapFactory = bitmapSerdeFactory.getBitmapFactory();
    MutableBitmap nullSet = null;
    int rowCount = 0;

    for (Rowboat theRow : theRows) {
      if (dimIndex > theRow.getDims().length) {
        if (nullSet == null) {
          nullSet = bitmapFactory.makeEmptyMutableBitmap();
        }
        nullSet.add(rowCount);
        adder.add(null);
      } else {
        int[] dimVals = theRow.getDims()[dimIndex];
        if (dimVals == null || dimVals.length == 0) {
          if (nullSet == null) {
            nullSet = bitmapFactory.makeEmptyMutableBitmap();
          }
          nullSet.add(rowCount);
        }
        adder.add(dimVals);
      }
      rowCount++;
    }

    final Iterable<String> dimensionValues = dimensionValuesLookup.get(dimension);
    GenericIndexed<String> dictionary = GenericIndexed.fromIterable(
        dimensionValues,
        GenericIndexed.stringStrategy
    );
    boolean bumpDictionary = false;

    if (hasMultipleValues) {
      final List<List<Integer>> vals = ((MultiValColumnDictionaryEntryStore) adder).get();
      if (nullSet != null) {
        log.info("Dimension[%s] has null rows.", dimension);

        if (Iterables.getFirst(dimensionValues, "") != null) {
          bumpDictionary = true;
          log.info("Dimension[%s] has no null value in the dictionary, expanding...", dimension);

          final List<String> nullList = Lists.newArrayList();
          nullList.add(null);

          dictionary = GenericIndexed.fromIterable(
              Iterables.concat(nullList, dimensionValues),
              GenericIndexed.stringStrategy
          );

          final int dictionarySize = dictionary.size();
          multiValCol = VSizeIndexed.fromIterable(
              FunctionalIterable
                  .create(vals)
                  .transform(
                      new Function<List<Integer>, VSizeIndexedInts>()
                      {
                        @Override
                        public VSizeIndexedInts apply(final List<Integer> input)
                        {
                          if (input == null) {
                            return VSizeIndexedInts.fromList(
                                new AbstractList<Integer>()
                                {
                                  @Override
                                  public Integer get(int index)
                                  {
                                    return 0;
                                  }

                                  @Override
                                  public int size()
                                  {
                                    return 1;
                                  }
                                }, dictionarySize
                            );
                          }
                          return VSizeIndexedInts.fromList(
                              new AbstractList<Integer>()
                              {
                                @Override
                                public Integer get(int index)
                                {
                                  Integer val = input.get(index);
                                  if (val == null) {
                                    return 0;
                                  }
                                  return val + 1;
                                }

                                @Override
                                public int size()
                                {
                                  return input.size();
                                }
                              },
                              dictionarySize
                          );
                        }
                      }
                  )
          );
        } else {
          final int dictionarySize = dictionary.size();
          multiValCol = VSizeIndexed.fromIterable(
              FunctionalIterable
                  .create(vals)
                  .transform(
                      new Function<List<Integer>, VSizeIndexedInts>()
                      {
                        @Override
                        public VSizeIndexedInts apply(List<Integer> input)
                        {
                          if (input == null) {
                            return VSizeIndexedInts.fromList(
                                new AbstractList<Integer>()
                                {
                                  @Override
                                  public Integer get(int index)
                                  {
                                    return 0;
                                  }

                                  @Override
                                  public int size()
                                  {
                                    return 1;
                                  }
                                }, dictionarySize
                            );
                          }
                          return VSizeIndexedInts.fromList(
                              input,
                              dictionarySize
                          );
                        }
                      }
                  )
          );
        }
      } else {
        final int dictionarySize = dictionary.size();
        multiValCol = VSizeIndexed.fromIterable(
            FunctionalIterable
                .create(vals)
                .transform(
                    new Function<List<Integer>, VSizeIndexedInts>()
                    {
                      @Override
                      public VSizeIndexedInts apply(List<Integer> input)
                      {
                        return VSizeIndexedInts.fromList(
                            input,
                            dictionarySize
                        );
                      }
                    }
                )
        );
      }
    } else {
      final List<Integer> vals = ((SingleValColumnDictionaryEntryStore) adder).get();

      if (nullSet != null) {
        log.info("Dimension[%s] has null rows.", dimension);

        if (Iterables.getFirst(dimensionValues, "") != null) {
          bumpDictionary = true;
          log.info("Dimension[%s] has no null value in the dictionary, expanding...", dimension);

          final List<String> nullList = Lists.newArrayList();
          nullList.add(null);

          dictionary = GenericIndexed.fromIterable(
              Iterables.concat(nullList, dimensionValues),
              GenericIndexed.stringStrategy
          );
          singleValCol = VSizeIndexedInts.fromList(
              new AbstractList<Integer>()
              {
                @Override
                public Integer get(int index)
                {
                  Integer val = vals.get(index);
                  if (val == null) {
                    return 0;
                  }
                  return val + 1;
                }

                @Override
                public int size()
                {
                  return vals.size();
                }
              }, dictionary.size()
          );
        } else {
          singleValCol = VSizeIndexedInts.fromList(
              new AbstractList<Integer>()
              {
                @Override
                public Integer get(int index)
                {
                  Integer val = vals.get(index);
                  if (val == null) {
                    return 0;
                  }
                  return val;
                }

                @Override
                public int size()
                {
                  return vals.size();
                }
              }, dictionary.size()
          );
        }
      } else {
        singleValCol = VSizeIndexedInts.fromList(vals, dictionary.size());
      }
    }

    // Make bitmap indexes
    List<MutableBitmap> mutableBitmaps = Lists.newArrayList();
    for (String dimVal : dimensionValues) {
      List<Iterable<Integer>> convertedInverteds = Lists.newArrayListWithCapacity(adapters.size());
      for (int j = 0; j < adapters.size(); ++j) {
        convertedInverteds.add(
            new ConvertingIndexedInts(
                adapters.get(j).getBitmapIndex(dimension, dimVal), rowNumConversions.get(j)
            )
        );
      }

      MutableBitmap bitset = bitmapSerdeFactory.getBitmapFactory().makeEmptyMutableBitmap();
      for (Integer row : CombiningIterable.createSplatted(
          convertedInverteds,
          Ordering.<Integer>natural().nullsFirst()
      )) {
        if (row != INVALID_ROW) {
          bitset.add(row);
        }
      }

      mutableBitmaps.add(bitset);
    }

    GenericIndexed<ImmutableBitmap> bitmaps;

    if (nullSet != null) {
      final ImmutableBitmap theNullSet = bitmapFactory.makeImmutableBitmap(nullSet);
      if (bumpDictionary) {
        bitmaps = GenericIndexed.fromIterable(
            Iterables.concat(
                Arrays.asList(theNullSet),
                Iterables.transform(
                    mutableBitmaps,
                    new Function<MutableBitmap, ImmutableBitmap>()
                    {
                      @Override
                      public ImmutableBitmap apply(MutableBitmap input)
                      {
                        return bitmapFactory.makeImmutableBitmap(input);
                      }
                    }
                )
            ),
            bitmapSerdeFactory.getObjectStrategy()
        );
      } else {
        Iterable<ImmutableBitmap> immutableBitmaps = Iterables.transform(
            mutableBitmaps,
            new Function<MutableBitmap, ImmutableBitmap>()
            {
              @Override
              public ImmutableBitmap apply(MutableBitmap input)
              {
                return bitmapFactory.makeImmutableBitmap(input);
              }
            }
        );

        bitmaps = GenericIndexed.fromIterable(
            Iterables.concat(
                Arrays.asList(
                    theNullSet.union(Iterables.getFirst(immutableBitmaps, null))
                ),
                Iterables.skip(immutableBitmaps, 1)
            ),
            bitmapSerdeFactory.getObjectStrategy()
        );
      }
    } else {
      bitmaps = GenericIndexed.fromIterable(
          Iterables.transform(
              mutableBitmaps,
              new Function<MutableBitmap, ImmutableBitmap>()
              {
                @Override
                public ImmutableBitmap apply(MutableBitmap input)
                {
                  return bitmapFactory.makeImmutableBitmap(input);
                }
              }
          ),
          bitmapSerdeFactory.getObjectStrategy()
      );
View Full Code Here

        dimsToSearch = index.getAvailableDimensions();
      } else {
        dimsToSearch = dimensions;
      }

      BitmapFactory bitmapFactory = index.getBitmapFactoryForDimensions();

      final ImmutableBitmap baseFilter;
      if (filter == null) {
        baseFilter = bitmapFactory.complement(bitmapFactory.makeEmptyImmutableBitmap(), index.getNumRows());
      } else {
        ColumnSelectorBitmapIndexSelector selector = new ColumnSelectorBitmapIndexSelector(bitmapFactory, index);
        baseFilter = filter.getBitmapIndex(selector);
      }

      for (String dimension : dimsToSearch) {
        final Column column = index.getColumn(dimension.toLowerCase());
        if (column == null) {
          continue;
        }

        final BitmapIndex bitmapIndex = column.getBitmapIndex();
        if (bitmapIndex != null) {
          for (int i = 0; i < bitmapIndex.getCardinality(); ++i) {
            String dimVal = Strings.nullToEmpty(bitmapIndex.getValue(i));
            if (searchQuerySpec.accept(dimVal) &&
                bitmapFactory.intersection(Arrays.asList(baseFilter, bitmapIndex.getBitmap(i))).size() > 0) {
              retVal.add(new SearchHit(dimension, dimVal));
              if (retVal.size() >= limit) {
                return makeReturnResult(limit, retVal);
              }
            }
View Full Code Here

TOP

Related Classes of com.metamx.collections.bitmap.BitmapFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.