@Test public void testSimpleScan() throws Exception { int max = 100; List<Collection<Field<?>>> expected = writeSimpleStructuredRows(max, ""); List<Collection<Field<?>>> actual = scanSimpleStructuredRows( Range.create(Collections.singleton(Fields.intField(KEY, 5)), Range.Bound.INCLUSIVE, Collections.singleton(Fields.intField(KEY, 15)), Range.Bound.EXCLUSIVE), max); Assert.assertEquals(expected.subList(5, 15), actual); actual = scanSimpleStructuredRows( Range.create(Collections.singleton(Fields.intField(KEY, 5)), Range.Bound.EXCLUSIVE, Collections.singleton(Fields.intField(KEY, 15)), Range.Bound.INCLUSIVE), max); Assert.assertEquals(expected.subList(6, 16), actual); actual = scanSimpleStructuredRows( Range.singleton(Collections.singleton(Fields.intField(KEY, 46))), max); Assert.assertEquals(expected.subList(46, 47), actual); // TODO: test invalid range // TODO: test begin only range // TODO: test end only range }
@Test public void testMultipleKeyScan() throws Exception { int max = 10; // Write rows and read them, the rows will have keys (0, 0L), (2, 2L), ..., (9, 9L) List<Collection<Field<?>>> expected = writeSimpleStructuredRows(max, ""); List<Collection<Field<?>>> actual = readSimpleStructuredRows(max); Assert.assertEquals(expected, actual); // scan from (1, 8L) inclusive to (3, 3L) inclusive, should return (2, 2L) and (3, 3L) actual = scanSimpleStructuredRows( Range.create(ImmutableList.of(Fields.intField(KEY, 1), Fields.longField(KEY2, 8L)), Range.Bound.INCLUSIVE, ImmutableList.of(Fields.intField(KEY, 3), Fields.longField(KEY2, 3L)), Range.Bound.INCLUSIVE), max); Assert.assertEquals(expected.subList(2, 4), actual); // scan from (1, 8L) inclusive to (3, 3L) exclusive, should only return (2, 2L) actual = scanSimpleStructuredRows( Range.create(ImmutableList.of(Fields.intField(KEY, 1), Fields.longField(KEY2, 8L)), Range.Bound.INCLUSIVE, ImmutableList.of(Fields.intField(KEY, 3), Fields.longField(KEY2, 3L)), Range.Bound.EXCLUSIVE), max); Assert.assertEquals(expected.subList(2, 3), actual); }
getTransactionRunner().run(context -> { StructuredTable table = context.getTable(SIMPLE_TABLE); Range range = Range.create(Arrays.asList(Fields.intField(KEY, 6), Fields.longField(KEY2, 6L)), Range.Bound.INCLUSIVE, Arrays.asList(Fields.intField(KEY, 8), Fields.longField(KEY2, 8L)), getTransactionRunner().run(context -> { StructuredTable table = context.getTable(SIMPLE_TABLE); Range range = Range.create(Collections.singletonList(Fields.intField(KEY, 2)), Range.Bound.INCLUSIVE, Collections.singletonList(Fields.intField(KEY, 5)), Range.Bound.EXCLUSIVE); table.deleteAll(range); Range range = Range.create(Collections.singletonList(Fields.intField(KEY, max + 1)), Range.Bound.INCLUSIVE, Collections.singletonList(Fields.intField(KEY, max + 5)), Range.Bound.EXCLUSIVE); table.deleteAll(range);