@Test public void partition() { LinePartitioner partitioner = new LinePartitioner(10000000); List<SegmentPartition> segmentPartitions = partitioner.partition(segmentList); assertEquals(2, segmentPartitions.size()); assertTrue(segmentPartitions.get(0).getSegments().size() >= 5); assertTrue(segmentPartitions.get(0).getCardinality() <= 10000000); assertTrue(segmentPartitions.get(1).getSegments().size() >= 2 && segmentPartitions.get(1).getSegments().size() <= 4); assertTrue(segmentPartitions.get(1).getCardinality() >= 8000000 && segmentPartitions.get(1).getCardinality() <= 10000000); return; }
@Override public List<SegmentPartition> partition(List<SegmentKey> segmentKeys) { segmentKeys.sort(Comparator.comparingInt(key -> SegmentUtils.newSegment(key).getAllShowIndex().getCardinality())); int count = 0; List<SegmentKey> list = new ArrayList<>(); List<SegmentPartition> partitions = new ArrayList<>(); for (SegmentKey segmentKey : segmentKeys) { Segment segment = SegmentUtils.newSegment(segmentKey); count += segment.getAllShowIndex().getCardinality(); if (count >= capacity) { partitions.add(new SegmentPartition(list)); list = new ArrayList<>(); list.add(segmentKey); count = segment.getAllShowIndex().getCardinality(); } else { list.add(segmentKey); } } if (!list.isEmpty()) { partitions.add(new SegmentPartition(list)); } Iterator<SegmentPartition> iterator = partitions.iterator(); while (iterator.hasNext()) { SegmentPartition next = iterator.next(); if (next.getSegmentKeys().size() < 5 && next.getCardinality() < capacity * 4 / 5) { iterator.remove(); } } return partitions; }
LinePartitioner implements Partitioner { @Override public List<SegmentPartition> partition(List<SegmentKey> segmentKeys) { segmentKeys.sort(Comparator.comparingInt(key -> SegmentUtils.newSegment(key).getAllShowIndex().getCardinality())); int count = 0; List<SegmentKey> list = new ArrayList<>(); List<SegmentPartition> partitions = new ArrayList<>(); for (SegmentKey segmentKey : segmentKeys) { Segment segment = SegmentUtils.newSegment(segmentKey); count += segment.getAllShowIndex().getCardinality(); if (count >= capacity) { partitions.add(new SegmentPartition(list)); list = new ArrayList<>(); list.add(segmentKey); count = segment.getAllShowIndex().getCardinality(); } else { list.add(segmentKey); } } if (!list.isEmpty()) { partitions.add(new SegmentPartition(list)); } Iterator<SegmentPartition> iterator = partitions.iterator(); while (iterator.hasNext()) { SegmentPartition next = iterator.next(); if (next.getSegmentKeys().size() < 5 && next.getCardinality() < capacity * 4 / 5) { iterator.remove(); } } return partitions; } }
LinePartitioner implements Partitioner { @Override public List<SegmentPartition> partition(List<SegmentKey> segmentKeys) { segmentKeys.sort(Comparator.comparingInt(key -> SegmentUtils.newSegment(key).getAllShowIndex().getCardinality())); int count = 0; List<SegmentKey> list = new ArrayList<>(); List<SegmentPartition> partitions = new ArrayList<>(); for (SegmentKey segmentKey : segmentKeys) { Segment segment = SegmentUtils.newSegment(segmentKey); count += segment.getAllShowIndex().getCardinality(); if (count >= capacity) { partitions.add(new SegmentPartition(list)); list = new ArrayList<>(); list.add(segmentKey); count = segment.getAllShowIndex().getCardinality(); } else { list.add(segmentKey); } } if (!list.isEmpty()) { partitions.add(new SegmentPartition(list)); } Iterator<SegmentPartition> iterator = partitions.iterator(); while (iterator.hasNext()) { SegmentPartition next = iterator.next(); if (next.getSegmentKeys().size() < 5 && next.getCardinality() < capacity * 4 / 5) { iterator.remove(); } } return partitions; } LinePartitioner(int capacity); }
LinePartitioner implements Partitioner { @Override public List<SegmentPartition> partition(List<SegmentKey> segmentKeys) { segmentKeys.sort(Comparator.comparingInt(key -> SegmentUtils.newSegment(key).getAllShowIndex().getCardinality())); int count = 0; List<SegmentKey> list = new ArrayList<>(); List<SegmentPartition> partitions = new ArrayList<>(); for (SegmentKey segmentKey : segmentKeys) { Segment segment = SegmentUtils.newSegment(segmentKey); count += segment.getAllShowIndex().getCardinality(); if (count >= capacity) { partitions.add(new SegmentPartition(list)); list = new ArrayList<>(); list.add(segmentKey); count = segment.getAllShowIndex().getCardinality(); } else { list.add(segmentKey); } } if (!list.isEmpty()) { partitions.add(new SegmentPartition(list)); } Iterator<SegmentPartition> iterator = partitions.iterator(); while (iterator.hasNext()) { SegmentPartition next = iterator.next(); if (next.getSegmentKeys().size() < 5 && next.getCardinality() < capacity * 4 / 5) { iterator.remove(); } } return partitions; } LinePartitioner(int capacity); @Override List<SegmentPartition> partition(List<SegmentKey> segmentKeys); }
LinePartitioner implements Partitioner { @Override public List<SegmentPartition> partition(List<SegmentKey> segmentKeys) { segmentKeys.sort(Comparator.comparingInt(key -> SegmentUtils.newSegment(key).getAllShowIndex().getCardinality())); int count = 0; List<SegmentKey> list = new ArrayList<>(); List<SegmentPartition> partitions = new ArrayList<>(); for (SegmentKey segmentKey : segmentKeys) { Segment segment = SegmentUtils.newSegment(segmentKey); count += segment.getAllShowIndex().getCardinality(); if (count >= capacity) { partitions.add(new SegmentPartition(list)); list = new ArrayList<>(); list.add(segmentKey); count = segment.getAllShowIndex().getCardinality(); } else { list.add(segmentKey); } } if (!list.isEmpty()) { partitions.add(new SegmentPartition(list)); } Iterator<SegmentPartition> iterator = partitions.iterator(); while (iterator.hasNext()) { SegmentPartition next = iterator.next(); if (next.getSegmentKeys().size() < 5 && next.getCardinality() < capacity * 4 / 5) { iterator.remove(); } } return partitions; } LinePartitioner(int capacity); @Override List<SegmentPartition> partition(List<SegmentKey> segmentKeys);  }