use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.
the class RocksDBSessionTest method testScanByAll.
@Test
public void testScanByAll() throws RocksDBException {
put("person:1gname", "James");
put("person:2gname", "Lisa");
Map<String, String> results = new HashMap<>();
Session session = this.rocks.session();
Iterator<BackendColumn> iter = session.scan(TABLE);
while (iter.hasNext()) {
BackendColumn col = iter.next();
results.put(getString(col.name), getString(col.value));
}
Assert.assertEquals(2, results.size());
// add some keys then scan again
put("person:3gname", "Tom");
put("person:4gname", "Mike");
results = new HashMap<>();
iter = session.scan(TABLE);
while (iter.hasNext()) {
BackendColumn col = iter.next();
results.put(getString(col.name), getString(col.value));
}
Assert.assertEquals(4, results.size());
// delete some keys then scan again
this.rocks.session().delete(TABLE, getBytes("person:2gname"));
this.rocks.session().commit();
BaseUnitTest.runWithThreads(1, () -> {
this.rocks.session().delete(TABLE, getBytes("person:3gname"));
this.rocks.session().commit();
this.rocks.close();
});
results = new HashMap<>();
iter = session.scan(TABLE);
while (iter.hasNext()) {
BackendColumn col = iter.next();
results.put(getString(col.name), getString(col.value));
}
Assert.assertEquals(2, results.size());
// delete some keys by prefix then scan again
this.rocks.session().deletePrefix(TABLE, getBytes("person:1"));
this.rocks.session().commit();
results = new HashMap<>();
iter = session.scan(TABLE);
while (iter.hasNext()) {
BackendColumn col = iter.next();
results.put(getString(col.name), getString(col.value));
}
Assert.assertEquals(1, results.size());
}
use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.
the class RocksDBSessionTest method testScanByPrefix.
@Test
public void testScanByPrefix() throws RocksDBException {
put("person:1gname", "James");
put("person:1gage", "19");
put("person:1gcity", "Beijing");
put("person:2gname", "Lisa");
put("person:2gage", "20");
put("person:2gcity", "Beijing");
Map<String, String> results = new HashMap<>();
Session session = this.rocks.session();
Iterator<BackendColumn> iter = session.scan(TABLE, getBytes("person:1"));
while (iter.hasNext()) {
BackendColumn col = iter.next();
results.put(getString(col.name), getString(col.value));
}
Assert.assertEquals(3, results.size());
Assert.assertEquals("James", results.get("person:1gname"));
Assert.assertEquals("19", results.get("person:1gage"));
Assert.assertEquals("Beijing", results.get("person:1gcity"));
Assert.assertEquals("Lisa", get("person:2gname"));
}
use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.
the class RocksDBSessionTest method testScanByRange.
@Test
public void testScanByRange() throws RocksDBException {
put("person:1gname", "James");
put("person:1gage", "19");
put("person:1gcity", "Beijing");
put("person:2gname", "Lisa");
put("person:2gage", "20");
put("person:2gcity", "Beijing");
put("person:3gname", "Hebe");
put("person:3gage", "21");
put("person:3gcity", "Taipei");
Map<String, String> results = new HashMap<>();
Session session = this.rocks.session();
Iterator<BackendColumn> iter = session.scan(TABLE, getBytes("person:1"), getBytes("person:3"));
while (iter.hasNext()) {
BackendColumn col = iter.next();
results.put(getString(col.name), getString(col.value));
}
Assert.assertEquals(6, results.size());
Assert.assertEquals("James", results.get("person:1gname"));
Assert.assertEquals("19", results.get("person:1gage"));
Assert.assertEquals("Beijing", results.get("person:1gcity"));
Assert.assertEquals("Lisa", results.get("person:2gname"));
Assert.assertEquals("20", results.get("person:2gage"));
Assert.assertEquals("Beijing", results.get("person:2gcity"));
Assert.assertEquals("Hebe", get("person:3gname"));
}
use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.
the class RocksDBSessionTest method testScanByRangeWithSignedBytes.
@Test
public void testScanByRangeWithSignedBytes() throws RocksDBException {
Session session = this.rocks.session();
byte[] key11 = new byte[] { 1, 1 };
byte[] value11 = getBytes("value-1-1");
session.put(TABLE, key11, value11);
byte[] key12 = new byte[] { 1, 2 };
byte[] value12 = getBytes("value-1-2");
session.put(TABLE, key12, value12);
byte[] key13 = new byte[] { 1, -3 };
byte[] value13 = getBytes("value-1-3");
session.put(TABLE, key13, value13);
byte[] key21 = new byte[] { 2, 1 };
byte[] value21 = getBytes("value-2-1");
session.put(TABLE, key21, value21);
this.commit();
Iterator<BackendColumn> iter;
iter = session.scan(TABLE, new byte[] { 1, -1 }, new byte[] { 1, 3 });
Assert.assertFalse(iter.hasNext());
iter = session.scan(TABLE, new byte[] { 1, 1 }, new byte[] { 1, -1 });
Map<ByteBuffer, byte[]> results = new HashMap<>();
while (iter.hasNext()) {
BackendColumn col = iter.next();
results.put(ByteBuffer.wrap(col.name), col.value);
}
Assert.assertEquals(3, results.size());
Assert.assertArrayEquals(value11, results.get(ByteBuffer.wrap(key11)));
Assert.assertArrayEquals(value12, results.get(ByteBuffer.wrap(key12)));
Assert.assertArrayEquals(value13, results.get(ByteBuffer.wrap(key13)));
Assert.assertArrayEquals(value21, session.get(TABLE, key21));
}
use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.
the class BinaryBackendEntryTest method testColumns.
@Test
public void testColumns() {
BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
BackendColumn col = BackendColumn.of(new byte[] { 1, 2 }, new byte[] { 3, 4 });
entry.columns(ImmutableList.of(col));
Assert.assertEquals(1, entry.columnsSize());
Assert.assertEquals(ImmutableList.of(col), entry.columns());
entry.columns(ImmutableList.of(col, col));
Assert.assertEquals(3, entry.columnsSize());
Assert.assertEquals(ImmutableList.of(col, col, col), entry.columns());
}
Aggregations