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;
}
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);
}
}
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;
}
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();
}
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;
}
Aggregations