Search in sources :

Example 81 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class JdbcKeyValueService method getAllTableNames.

private Set<TableReference> getAllTableNames(DSLContext ctx) {
    Result<? extends Record> records = ctx.select(TABLE_NAME).from(METADATA_TABLE).fetch();
    Set<TableReference> tableRefs = Sets.newHashSetWithExpectedSize(records.size());
    for (Record record : records) {
        tableRefs.add(TableReference.createUnsafe(record.getValue(TABLE_NAME)));
    }
    return tableRefs;
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Record(org.jooq.Record)

Example 82 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AtlasDbServiceImplTest method shouldTruncateNamespacedTables.

@Test
public void shouldTruncateNamespacedTables() throws Exception {
    atlasDbService.truncateTable("ns.table");
    TableReference tableToTruncate = TableReference.createFromFullyQualifiedName("ns.table");
    verify(kvs, atLeastOnce()).truncateTable(tableToTruncate);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Example 83 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method truncateShouldBeIdempotent.

@Test
public void truncateShouldBeIdempotent() {
    TableReference fooBar = TableReference.createUnsafe("foo.bar");
    keyValueService.createTable(fooBar, AtlasDbConstants.GENERIC_TABLE_METADATA);
    keyValueService.truncateTable(fooBar);
    keyValueService.truncateTable(fooBar);
    keyValueService.dropTable(fooBar);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Example 84 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method doTestGetRangePaging.

private void doTestGetRangePaging(int numColumnsInMetadata, int batchSizeHint, boolean reverse) {
    TableReference tableRef = createTableWithNamedColumns(numColumnsInMetadata);
    Map<Cell, byte[]> values = new HashMap<Cell, byte[]>();
    values.put(Cell.create(PtBytes.toBytes("00"), PtBytes.toBytes("c1")), PtBytes.toBytes("a"));
    values.put(Cell.create(PtBytes.toBytes("00"), PtBytes.toBytes("c2")), PtBytes.toBytes("b"));
    values.put(Cell.create(PtBytes.toBytes("01"), RangeRequests.getFirstRowName()), PtBytes.toBytes("c"));
    values.put(Cell.create(PtBytes.toBytes("02"), PtBytes.toBytes("c1")), PtBytes.toBytes("d"));
    values.put(Cell.create(PtBytes.toBytes("02"), PtBytes.toBytes("c2")), PtBytes.toBytes("e"));
    values.put(Cell.create(PtBytes.toBytes("03"), PtBytes.toBytes("c1")), PtBytes.toBytes("f"));
    values.put(Cell.create(PtBytes.toBytes("04"), PtBytes.toBytes("c1")), PtBytes.toBytes("g"));
    values.put(Cell.create(PtBytes.toBytes("04"), RangeRequests.getLastRowName()), PtBytes.toBytes("h"));
    values.put(Cell.create(PtBytes.toBytes("05"), PtBytes.toBytes("c1")), PtBytes.toBytes("i"));
    values.put(Cell.create(RangeRequests.getLastRowName(), PtBytes.toBytes("c1")), PtBytes.toBytes("j"));
    keyValueService.put(tableRef, values, TEST_TIMESTAMP);
    RangeRequest request = RangeRequest.builder(reverse).batchHint(batchSizeHint).build();
    try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(tableRef, request, Long.MAX_VALUE)) {
        List<RowResult<Value>> results = ImmutableList.copyOf(iter);
        List<RowResult<Value>> expected = ImmutableList.of(RowResult.create(PtBytes.toBytes("00"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("a"), TEST_TIMESTAMP)).put(PtBytes.toBytes("c2"), Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("01"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(RangeRequests.getFirstRowName(), Value.create(PtBytes.toBytes("c"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("02"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("d"), TEST_TIMESTAMP)).put(PtBytes.toBytes("c2"), Value.create(PtBytes.toBytes("e"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("03"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("f"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("04"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("g"), TEST_TIMESTAMP)).put(RangeRequests.getLastRowName(), Value.create(PtBytes.toBytes("h"), TEST_TIMESTAMP)).build()), RowResult.create(PtBytes.toBytes("05"), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("i"), TEST_TIMESTAMP)).build()), RowResult.create(RangeRequests.getLastRowName(), ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("j"), TEST_TIMESTAMP)).build()));
        assertEquals(reverse ? Lists.reverse(expected) : expected, results);
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) HashMap(java.util.HashMap) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 85 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method testGetAllTableNames.

@Test
public void testGetAllTableNames() {
    final TableReference anotherTable = TableReference.createWithEmptyNamespace("AnotherTable");
    assertEquals(1, keyValueService.getAllTableNames().size());
    assertEquals(TEST_TABLE, keyValueService.getAllTableNames().iterator().next());
    keyValueService.createTable(anotherTable, AtlasDbConstants.GENERIC_TABLE_METADATA);
    assertEquals(2, keyValueService.getAllTableNames().size());
    assertTrue(keyValueService.getAllTableNames().contains(anotherTable));
    assertTrue(keyValueService.getAllTableNames().contains(TEST_TABLE));
    keyValueService.dropTable(anotherTable);
    assertEquals(1, keyValueService.getAllTableNames().size());
    assertEquals(TEST_TABLE, keyValueService.getAllTableNames().iterator().next());
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Aggregations

TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)112 Cell (com.palantir.atlasdb.keyvalue.api.Cell)41 Test (org.junit.Test)41 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)13 Multimap (com.google.common.collect.Multimap)13 Entry (java.util.Map.Entry)13 Set (java.util.Set)13 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)12 Value (com.palantir.atlasdb.keyvalue.api.Value)12 Collection (java.util.Collection)12 List (java.util.List)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)11 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)11 SortedMap (java.util.SortedMap)11 Lists (com.google.common.collect.Lists)10 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)10 Sets (com.google.common.collect.Sets)9 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)9