Ejemplo n.º 1
0
  public static void main(String[] args) throws Exception {
    RoaringBitmap bitmap = new RoaringBitmap();
    CortaraConfiguration conf = new CortaraConfiguration();

    String path = "/tmp/test.format";
    ColumnMetaReader metaReader = new ColumnMetaReader(path, conf);

    RowGroup rowGroup = metaReader.readLastRowGorup();

    byte[] data = rowGroup.getIndexData().getValueBitmap();
    Map<Integer, Integer> distCount = rowGroup.getIndexData().getDistinctCount();
    ByteBuffer buf = ByteBuffer.wrap(data, 0, data.length);
    DataInputByteBuffer bis = new DataInputByteBuffer();
    bis.reset(buf);
    bitmap.deserialize(bis);

    for (int i = 0; i < bitmap.getCardinality(); i++) {
      System.out.println(bitmap.select(i) + ":" + distCount.get(bitmap.select(i)));
    }
  }
 private static final int[] toDocArray(ReaderLocal reader, DocumentsRequest request)
     throws IOException {
   SchemaField schemaField = null;
   Schema schema = request.getConfig().getSchema();
   String field = request.getField();
   if (!StringUtils.isEmpty(field)) {
     schemaField = schema.getField(field);
     if (schemaField == null) throw new IOException("Field not found: " + field);
   } else {
     schemaField = schema.getFieldList().getUniqueField();
     if (schemaField == null) throw new IOException("No unique field");
   }
   int higher = -1;
   RoaringBitmap bitSet = new RoaringBitmap();
   String fieldName = schemaField.getName();
   for (String uniqueKey : request.getUniqueKeyList()) {
     TermDocs termDocs = reader.getTermDocs(new Term(fieldName, uniqueKey));
     if (termDocs != null) {
       while (termDocs.next()) {
         int doc = termDocs.doc();
         if (doc > higher) higher = doc;
         bitSet.add(doc);
       }
     }
     termDocs.close();
   }
   if (request.isReverse()) bitSet.flip(0, higher + 1);
   IntBufferedArrayInterface intBufferArray =
       IntBufferedArrayFactory.INSTANCE.newInstance(bitSet.getCardinality());
   IntIterator iterator = bitSet.getIntIterator();
   while (iterator.hasNext()) {
     int docId = iterator.next();
     if (!reader.isDeletedNoLock(docId)) intBufferArray.add(docId);
   }
   return intBufferArray.getFinalArray();
 }