Search in sources :

Example 21 with BackendEntry

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

the class HbaseStore method mutate.

private void mutate(Session session, BackendAction item) {
    BackendEntry entry = item.entry();
    HbaseTable table = this.table(entry.type());
    switch(item.action()) {
        case INSERT:
            table.insert(session, entry);
            break;
        case DELETE:
            table.delete(session, entry);
            break;
        case APPEND:
            table.append(session, entry);
            break;
        case ELIMINATE:
            table.eliminate(session, entry);
            break;
        default:
            throw new AssertionError(String.format("Unsupported mutate action: %s", item.action()));
    }
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry)

Example 22 with BackendEntry

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

the class MysqlEntryIterator method fetch.

@Override
protected final boolean fetch() {
    assert this.current == null;
    if (this.next != null) {
        this.current = this.next;
        this.next = null;
    }
    try {
        while (this.results.next()) {
            MysqlBackendEntry entry = this.row2Entry(this.results.resultSet());
            this.lastest = entry;
            BackendEntry merged = this.merger.apply(this.current, entry);
            if (this.current == null) {
                // The first time to read
                this.current = merged;
            } else if (merged == this.current) {
                // Does the next entry belongs to the current entry
                assert merged != null;
            } else {
                // New entry
                assert this.next == null;
                this.next = merged;
                break;
            }
            // When limit exceed, stop fetching
            if (this.reachLimit(this.fetched() - 1)) {
                this.exceedLimit = true;
                // Need remove last one because fetched limit + 1 records
                this.removeLastRecord();
                this.results.close();
                break;
            }
        }
    } catch (SQLException e) {
        throw new BackendException("Fetch next error", e);
    }
    return this.current != null;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) SQLException(java.sql.SQLException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 23 with BackendEntry

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

the class StoreDumper method dump.

public void dump(HugeType table, long offset, long limit) {
    BackendStore store = this.backendStore(table);
    Query query = new Query(table);
    Iterator<BackendEntry> rs = store.query(query);
    for (long i = 0; i < offset && rs.hasNext(); i++) {
        rs.next();
    }
    LOG.info("Dump table {} (offset {} limit {}):", table, offset, limit);
    for (long i = 0; i < limit && rs.hasNext(); i++) {
        BackendEntry entry = rs.next();
        LOG.info("{}", entry);
    }
    CloseableIterator.closeIterator(rs);
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Query(com.baidu.hugegraph.backend.query.Query) BackendStore(com.baidu.hugegraph.backend.store.BackendStore)

Example 24 with BackendEntry

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

the class BinaryScatterSerializerTest method parse.

private static BackendEntry parse(BackendEntry originEntry) {
    byte[] bytes = originEntry.id().asBytes();
    BackendEntry parsedEntry = new BinaryBackendEntry(originEntry.type(), bytes);
    parsedEntry.columns(originEntry.columns());
    return parsedEntry;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)

Example 25 with BackendEntry

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

the class BinaryScatterSerializerTest method testVertex.

@Test
public void testVertex() {
    HugeConfig config = FakeObjects.newConfig();
    BinaryScatterSerializer ser = new BinaryScatterSerializer(config);
    HugeEdge edge = new FakeObjects().newEdge(123, 456);
    BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
    HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
    Assert.assertEquals(edge.sourceVertex(), vertex1);
    assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
    BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
    HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
    Assert.assertEquals(edge.targetVertex(), vertex2);
    assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
    Whitebox.setInternalState(vertex2, "removed", true);
    Assert.assertTrue(vertex2.removed());
    BackendEntry entry3 = ser.writeVertex(vertex2);
    Assert.assertEquals(0, entry3.columnsSize());
    Assert.assertNull(ser.readVertex(edge.graph(), null));
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BinaryScatterSerializer(com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)54 Test (org.junit.Test)27 TextBackendEntry (com.baidu.hugegraph.backend.serializer.TextBackendEntry)26 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)26 BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)21 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)7 Id (com.baidu.hugegraph.backend.id.Id)6 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)6 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 Query (com.baidu.hugegraph.backend.query.Query)4 BinarySerializer (com.baidu.hugegraph.backend.serializer.BinarySerializer)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)4 ArrayList (java.util.ArrayList)4 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)3 LockUtil (com.baidu.hugegraph.util.LockUtil)3 BackendException (com.baidu.hugegraph.backend.BackendException)2 Condition (com.baidu.hugegraph.backend.query.Condition)2