Search in sources :

Example 11 with BackendColumn

use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.

the class BinaryBackendEntryTest method testEquals.

@Test
public void testEquals() {
    BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
    BinaryBackendEntry entry2 = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 2, 2 });
    BinaryBackendEntry entry3 = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
    BinaryBackendEntry entry4 = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
    BinaryBackendEntry entry5 = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
    BackendColumn col = BackendColumn.of(new byte[] { 1, 2 }, new byte[] { 3, 4 });
    BackendColumn col2 = BackendColumn.of(new byte[] { 5, 6 }, new byte[] { 7, 8 });
    entry.column(col);
    entry2.column(col2);
    entry3.column(col2);
    entry4.column(col);
    entry4.column(col2);
    entry5.column(col);
    Assert.assertNotEquals(entry, entry2);
    Assert.assertNotEquals(entry, entry3);
    Assert.assertNotEquals(entry, entry4);
    Assert.assertEquals(entry, entry5);
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 12 with BackendColumn

use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.

the class BinaryBackendEntryTest method testMerge.

@Test
public void testMerge() {
    BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
    BinaryBackendEntry entry2 = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 2, 2 });
    BackendColumn col = BackendColumn.of(new byte[] { 1, 2 }, new byte[] { 3, 4 });
    BackendColumn col2 = BackendColumn.of(new byte[] { 5, 6 }, new byte[] { 7, 8 });
    entry.column(col);
    entry2.column(col2);
    Assert.assertEquals(1, entry.columnsSize());
    Assert.assertEquals(ImmutableList.of(col), entry.columns());
    entry.merge(entry2);
    Assert.assertEquals(2, entry.columnsSize());
    Assert.assertEquals(ImmutableList.of(col, col2), entry.columns());
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 13 with BackendColumn

use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.

the class BinaryScatterSerializer method readVertex.

@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry bytesEntry) {
    if (bytesEntry == null) {
        return null;
    }
    BinaryBackendEntry entry = this.convertEntry(bytesEntry);
    // Parse label
    final byte[] VL = this.formatSyspropName(entry.id(), HugeKeys.LABEL);
    BackendColumn vl = entry.column(VL);
    VertexLabel vertexLabel = VertexLabel.NONE;
    if (vl != null) {
        Id labelId = BytesBuffer.wrap(vl.value).readId();
        vertexLabel = graph.vertexLabelOrNone(labelId);
    }
    // Parse id
    Id id = entry.id().origin();
    HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
    // Parse all properties and edges of a Vertex
    for (BackendColumn col : entry.columns()) {
        this.parseColumn(col, vertex);
    }
    return vertex;
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 14 with BackendColumn

use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.

the class StoreSerializer method writeMutation.

public static byte[] writeMutation(BackendMutation mutation) {
    BytesBuffer buffer = BytesBuffer.allocate(MUTATION_SIZE);
    // write mutation size
    buffer.writeVInt(mutation.size());
    for (Iterator<BackendAction> items = mutation.mutation(); items.hasNext(); ) {
        BackendAction item = items.next();
        // write Action
        buffer.write(item.action().code());
        BackendEntry entry = item.entry();
        // write HugeType
        buffer.write(entry.type().code());
        // write id
        buffer.writeBytes(entry.id().asBytes());
        // write subId
        if (entry.subId() != null) {
            buffer.writeId(entry.subId());
        } else {
            buffer.writeId(IdGenerator.ZERO);
        }
        // write ttl
        buffer.writeVLong(entry.ttl());
        // write columns
        buffer.writeVInt(entry.columns().size());
        for (BackendColumn column : entry.columns()) {
            buffer.writeBytes(column.name);
            buffer.writeBytes(column.value);
        }
    }
    return buffer.bytes();
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BackendAction(com.baidu.hugegraph.backend.store.BackendAction) BytesBuffer(com.baidu.hugegraph.backend.serializer.BytesBuffer)

Example 15 with BackendColumn

use of com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn in project incubator-hugegraph by apache.

the class TextBackendEntryTest method testColumns.

@Test
public void testColumns() {
    TextBackendEntry entry = new TextBackendEntry(HugeType.VERTEX, IdGenerator.of(1));
    entry.column(HugeKeys.ID, "1");
    entry.column(HugeKeys.NAME, "tom");
    BackendColumn col1 = BackendColumn.of(new byte[] { 'i', 'd' }, new byte[] { '1' });
    BackendColumn col2 = BackendColumn.of(new byte[] { 'n', 'a', 'm', 'e' }, new byte[] { 't', 'o', 'm' });
    Assert.assertEquals(2, entry.columnsSize());
    Assert.assertEquals(ImmutableList.of(col1, col2), entry.columns());
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

BackendColumn (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)21 Test (org.junit.Test)15 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)11 Session (com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session)9 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)5 HashMap (java.util.HashMap)5 Id (com.baidu.hugegraph.backend.id.Id)4 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)3 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)2 ByteBuffer (java.nio.ByteBuffer)2 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)1 TableBackendEntry (com.baidu.hugegraph.backend.serializer.TableBackendEntry)1 TextBackendEntry (com.baidu.hugegraph.backend.serializer.TextBackendEntry)1 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)1 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)1