public static long result(BitmapAggregator agg) { BitmapCounter finalState = agg.getState(); return finalState == null ? 0 : finalState.getCount(); } }
@Override public ByteBuffer getFinalResult(ByteBuffer in) { ByteBuffer out = ByteBuffer.allocate(RESULT_SIZE); try { BitmapCounter counter = factory.newBitmap(in); out.putInt(IS_RESULT_FLAG); out.putLong(counter.getCount()); } catch (IOException e) { throw new RuntimeException(e); } out.flip(); return out; } }
@Override public int compare(Object o1, Object o2) { if (o1 == null && o2 == null) return 0; if (o1 == null) // null is bigger to align with CubeCodeSystem return 1; if (o2 == null) // null is bigger to align with CubeCodeSystem return -1; // for the 'having clause', we only concern numbers and BigDecimal // we try to cache the o2, which should be a constant according to CompareTupleFilter.evaluate() double n1; if (o1 instanceof Number) { n1 = ((Number) o1).doubleValue(); } else if (o1 instanceof HLLCounter) { n1 = ((HLLCounter) o1).getCountEstimate(); } else if (o1 instanceof BitmapCounter) { n1 = ((BitmapCounter) o1).getCount(); } else if (o1 instanceof PercentileCounter) { n1 = ((PercentileCounter) o1).getResultEstimate(); } else { throw new RuntimeException("Unknown datatype: value=" + o1 + ", class=" + o1.getClass()); } double n2 = (o2Cache == o2) ? n2Cache : Double.parseDouble((String) o2); if (o2Cache == null) { o2Cache = o2; n2Cache = n2; } return Double.compare(n1, n2); }
public long result() { if (keyList == null || keyList.isEmpty()) { return 0; } // if any specified key not in map, the intersection must be 0 for (Object key : keyList) { if (!map.containsKey(key)) { return 0; } } BitmapCounter counter = null; for (Object key : keyList) { BitmapCounter c = map.get(key); if (counter == null) { counter = factory.newBitmap(); counter.orWith(c); } else { counter.andWith(c); } } return counter != null ? counter.getCount() : 0; } }
@Test public void testEstimateBitmapMemSize() { BitmapAggregator[] bitmapAggrs = new BitmapAggregator[bitmaps.length]; for (int i = 0; i < bitmapAggrs.length; i++) { bitmapAggrs[i] = new BitmapAggregator(); bitmapAggrs[i].aggregate(bitmaps[i]); } System.out.printf(Locale.ROOT, "%-15s %-10s %-10s\n", "cardinality", "estimate", "actual"); for (BitmapAggregator aggr : bitmapAggrs) { System.out.printf(Locale.ROOT, "%-15d %-10d %-10d\n", aggr.getState().getCount(), aggr.getMemBytesEstimate(), meter.measureDeep(aggr)); } }
@Test public void testBitmapCounter() { BitmapCounter counter = factory.newBitmap(10, 20, 30, 1000); assertEquals(4, counter.getCount()); assertTrue(counter.getMemBytes() > 0); BitmapCounter counter2 = factory.newBitmap(); assertEquals(0, counter2.getCount()); counter2.add(10); counter2.add(30); counter2.add(40); counter2.add(2000); assertEquals(4, counter2.getCount()); counter2.orWith(counter); assertEquals(4, counter.getCount()); assertEquals(6, counter2.getCount()); // in-place change int i = 0; int[] values = new int[(int) counter2.getCount()]; for (int value : counter2) { values[i++] = value; } assertArrayEquals(new int[]{10, 20, 30, 40, 1000, 2000}, values); counter2.clear(); assertEquals(0, counter2.getCount()); }
@Test public void testAggregator() { BitmapAggregator aggregator = new BitmapAggregator(); assertNull(null, aggregator.getState()); aggregator.aggregate(factory.newBitmap(10, 20, 30, 40)); assertEquals(4, aggregator.getState().getCount()); aggregator.aggregate(factory.newBitmap(25, 30, 35, 40, 45)); assertEquals(7, aggregator.getState().getCount()); aggregator.reset(); assertNull(aggregator.getState()); }
public static long result(BitmapCounter counter) { return counter == null ? 0L : counter.getCount(); } }
public static long result(BitmapAggregator agg) { BitmapCounter finalState = agg.getState(); return finalState == null ? 0 : finalState.getCount(); } }
@Override public ByteBuffer getFinalResult(ByteBuffer in) { ByteBuffer out = ByteBuffer.allocate(RESULT_SIZE); try { BitmapCounter counter = factory.newBitmap(in); out.putInt(IS_RESULT_FLAG); out.putLong(counter.getCount()); } catch (IOException e) { throw new RuntimeException(e); } out.flip(); return out; } }
@Override public int compare(Object o1, Object o2) { if (o1 == null && o2 == null) return 0; if (o1 == null) // null is bigger to align with CubeCodeSystem return 1; if (o2 == null) // null is bigger to align with CubeCodeSystem return -1; // for the 'having clause', we only concern numbers and BigDecimal // we try to cache the o2, which should be a constant according to CompareTupleFilter.evaluate() double n1; if (o1 instanceof Number) { n1 = ((Number) o1).doubleValue(); } else if (o1 instanceof HLLCounter) { n1 = ((HLLCounter) o1).getCountEstimate(); } else if (o1 instanceof BitmapCounter) { n1 = ((BitmapCounter) o1).getCount(); } else if (o1 instanceof PercentileCounter) { n1 = ((PercentileCounter) o1).getResultEstimate(); } else { throw new RuntimeException("Unknown datatype: value=" + o1 + ", class=" + o1.getClass()); } double n2 = (o2Cache == o2) ? n2Cache : Double.parseDouble((String) o2); if (o2Cache == null) { o2Cache = o2; n2Cache = n2; } return Double.compare(n1, n2); }
public long result() { if (keyList == null || keyList.isEmpty()) { return 0; } // if any specified key not in map, the intersection must be 0 for (Object key : keyList) { if (!map.containsKey(key)) { return 0; } } BitmapCounter counter = null; for (Object key : keyList) { BitmapCounter c = map.get(key); if (counter == null) { counter = factory.newBitmap(); counter.orWith(c); } else { counter.andWith(c); } } return counter != null ? counter.getCount() : 0; } }