Search in sources :

Example 16 with BackendEntry

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

the class BinaryEntryIterator method fetch.

@Override
protected final boolean fetch() {
    assert this.current == null;
    if (this.next != null) {
        this.current = this.next;
        this.next = null;
    }
    while (this.results.hasNext()) {
        Elem elem = this.results.next();
        BackendEntry merged = this.merger.apply(this.current, elem);
        E.checkState(merged != null, "Error when merging entry");
        if (this.current == null) {
            // The first time to read
            this.current = merged;
        } else if (merged == this.current) {
            // The next entry belongs to the current entry
            assert this.current != null;
            if (this.sizeOf(this.current) >= INLINE_BATCH_SIZE) {
                break;
            }
        } else {
            // New entry
            assert this.next == null;
            this.next = merged;
            break;
        }
        // When limit exceed, stop fetching
        if (this.reachLimit(this.fetched() - 1)) {
            // Need remove last one because fetched limit + 1 records
            this.removeLastRecord();
            this.results.close();
            break;
        }
    }
    return this.current != null;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry)

Example 17 with BackendEntry

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

the class InMemoryDBTable method insert.

@Override
public void insert(BackendSession session, TextBackendEntry entry) {
    if (!this.store.containsKey(entry.id())) {
        this.store.put(entry.id(), entry);
    } else {
        // Merge columns if the entry exists
        BackendEntry origin = this.store.get(entry.id());
        // TODO: Compatible with BackendEntry
        origin.merge(entry);
    }
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry)

Example 18 with BackendEntry

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

the class InMemoryDBTable method queryByFilter.

protected Map<Id, BackendEntry> queryByFilter(Collection<Condition> conditions, Map<Id, BackendEntry> entries) {
    assert conditions.size() > 0;
    Map<Id, BackendEntry> rs = new HashMap<>();
    LOG.trace("queryByFilter {} size = {}", this.table(), entries.size());
    for (BackendEntry entry : entries.values()) {
        // Query by conditions
        boolean matched = true;
        for (Condition c : conditions) {
            if (!matchCondition(entry, c)) {
                // TODO: deal with others Condition like: and, or...
                matched = false;
                break;
            }
        }
        if (matched) {
            rs.put(entry.id(), entry);
        }
    }
    return rs;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) Condition(com.baidu.hugegraph.backend.query.Condition) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Id(com.baidu.hugegraph.backend.id.Id)

Example 19 with BackendEntry

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

the class InMemoryDBTable method queryByRange.

private Iterator<BackendEntry> queryByRange(ConditionQuery query) {
    E.checkArgument(query.relations().size() == 1, "Invalid scan with multi conditions: %s", query);
    Condition.Relation scan = query.relations().iterator().next();
    Shard shard = (Shard) scan.value();
    int start = Strings.isNullOrEmpty(shard.start()) ? 0 : Long.valueOf(shard.start()).intValue();
    int end = Strings.isNullOrEmpty(shard.end()) ? 0 : Long.valueOf(shard.end()).intValue();
    List<BackendEntry> rs = new ArrayList<>(end - start);
    Iterator<BackendEntry> iterator = this.store.values().iterator();
    int i = 0;
    while (iterator.hasNext() && i++ < end) {
        BackendEntry entry = iterator.next();
        if (i > start) {
            rs.add(entry);
        }
    }
    return rs.iterator();
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) ArrayList(java.util.ArrayList) Shard(com.baidu.hugegraph.backend.store.Shard)

Example 20 with BackendEntry

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

the class InMemoryDBTable method queryNumber.

@Override
public Number queryNumber(BackendSession session, Query query) {
    Aggregate aggregate = query.aggregateNotNull();
    if (aggregate.func() != AggregateFunc.COUNT) {
        throw new NotSupportException(aggregate.toString());
    }
    assert aggregate.func() == AggregateFunc.COUNT;
    Iterator<BackendEntry> results = this.query(session, query);
    long total = 0L;
    while (results.hasNext()) {
        total += this.sizeOfBackendEntry(results.next());
    }
    return total;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) Aggregate(com.baidu.hugegraph.backend.query.Aggregate)

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