/** * Partitions the given {@link RowsColumnRangeBatchRequest} into multiple, preserving the ordering of rows. Each * partitioned {@link RowsColumnRangeBatchRequest} will have exactly {@code partitionSize} rows in total, except * possibly for the last one, which may have fewer rows (but not more). No row will be split across partitions. */ public static List<RowsColumnRangeBatchRequest> partition(RowsColumnRangeBatchRequest batch, int partitionSize) { if (getAllRowsInOrder(batch).size() <= partitionSize) { return ImmutableList.of(batch); } List<List<byte[]>> partitionedRows = Lists.partition(getAllRowsInOrder(batch), partitionSize); List<RowsColumnRangeBatchRequest> partitions = new ArrayList<>(partitionedRows.size()); partitions.add(getFirstRequestInPartition(batch, partitionedRows.get(0))); for (int partitionNumber = 1; partitionNumber < partitionedRows.size() - 1; partitionNumber++) { RowsColumnRangeBatchRequest partition = ImmutableRowsColumnRangeBatchRequest.builder() .columnRangeSelection(batch.getColumnRangeSelection()) .rowsToLoadFully(partitionedRows.get(partitionNumber)) .build(); partitions.add(partition); } partitions.add(getLastRequestInPartition(batch, Iterables.getLast(partitionedRows))); return partitions; }
/** * Partitions the given {@link RowsColumnRangeBatchRequest} into multiple, preserving the ordering of rows. Each * partitioned {@link RowsColumnRangeBatchRequest} will have exactly {@code partitionSize} rows in total, except * possibly for the last one, which may have fewer rows (but not more). No row will be split across partitions. */ public static List<RowsColumnRangeBatchRequest> partition(RowsColumnRangeBatchRequest batch, int partitionSize) { if (getAllRowsInOrder(batch).size() <= partitionSize) { return ImmutableList.of(batch); } List<List<byte[]>> partitionedRows = Lists.partition(getAllRowsInOrder(batch), partitionSize); List<RowsColumnRangeBatchRequest> partitions = new ArrayList<>(partitionedRows.size()); partitions.add(getFirstRequestInPartition(batch, partitionedRows.get(0))); for (int partitionNumber = 1; partitionNumber < partitionedRows.size() - 1; partitionNumber++) { RowsColumnRangeBatchRequest partition = ImmutableRowsColumnRangeBatchRequest.builder() .columnRangeSelection(batch.getColumnRangeSelection()) .rowsToLoadFully(partitionedRows.get(partitionNumber)) .build(); partitions.add(partition); } partitions.add(getLastRequestInPartition(batch, Iterables.getLast(partitionedRows))); return partitions; }