Search in sources :

Example 1 with TableSplit

use of io.cdap.cdap.api.dataset.table.TableSplit in project cdap by caskdata.

the class BufferingTable method getSplits.

/**
 * Fallback implementation of getSplits, {@link SplitsUtil#primitiveGetSplits(int, byte[], byte[])}.
 * Ideally should be overridden by subclasses.
 *
 * @param numSplits Desired number of splits. If greater than zero, at most this many splits will be returned.
 *                  If less or equal to zero, any number of splits can be returned.
 * @param start If non-null, the returned splits will only cover keys that are greater or equal.
 * @param stop If non-null, the returned splits will only cover keys that are less.
 * @return list of {@link Split}
 */
@Override
public List<Split> getSplits(int numSplits, byte[] start, byte[] stop) {
    ensureTransactionIsStarted();
    List<KeyRange> keyRanges = SplitsUtil.primitiveGetSplits(numSplits, start, stop);
    return Lists.transform(keyRanges, new Function<KeyRange, Split>() {

        @Nullable
        @Override
        public Split apply(@Nullable KeyRange input) {
            return new TableSplit(input == null ? null : input.getStart(), input == null ? null : input.getStop());
        }
    });
}
Also used : TableSplit(io.cdap.cdap.api.dataset.table.TableSplit) Split(io.cdap.cdap.api.data.batch.Split) TableSplit(io.cdap.cdap.api.dataset.table.TableSplit) Nullable(javax.annotation.Nullable)

Example 2 with TableSplit

use of io.cdap.cdap.api.dataset.table.TableSplit in project cdap by caskdata.

the class SplitsTest method testSerde.

@Test
public void testSerde() throws IOException, ClassNotFoundException {
    List<TableSplit> splits = Arrays.asList(new TableSplit(Bytes.toBytes("0"), Bytes.toBytes("1")), new TableSplit(Bytes.toBytes("1"), Bytes.toBytes("2")));
    List<Split> decoded = Splits.decode(Splits.encode(splits), new ArrayList<Split>(), getClass().getClassLoader());
    Assert.assertEquals(splits, decoded);
}
Also used : TableSplit(io.cdap.cdap.api.dataset.table.TableSplit) TableSplit(io.cdap.cdap.api.dataset.table.TableSplit) Test(org.junit.Test)

Aggregations

TableSplit (io.cdap.cdap.api.dataset.table.TableSplit)2 Split (io.cdap.cdap.api.data.batch.Split)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1