use of com.baidu.hugegraph.backend.query.Query 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);
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class GraphTransaction method joinTxEdges.
private Iterator<?> joinTxEdges(Query query, Iterator<HugeEdge> edges, Map<Id, HugeVertex> removingVertices) {
assert query.resultType().isEdge();
BiFunction<Query, HugeEdge, HugeEdge> matchTxFunc = (q, e) -> {
assert q.resultType() == HugeType.EDGE;
if (e.expired() && !q.showExpired()) {
// Filter expired edges with TTL
return null;
}
// Filter edges matched conditions
return q.test(e) ? e : q.test(e = e.switchOwner()) ? e : null;
};
edges = this.joinTxRecords(query, edges, matchTxFunc, this.addedEdges, this.removedEdges, this.updatedEdges);
if (removingVertices.isEmpty()) {
return edges;
}
// Filter edges that belong to deleted vertex
return new FilterIterator<HugeEdge>(edges, edge -> {
for (HugeVertex v : removingVertices.values()) {
if (edge.belongToVertex(v)) {
return false;
}
}
return true;
});
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class GraphTransaction method prepareDeletions.
protected void prepareDeletions(Map<Id, HugeVertex> removedVertices, Map<Id, HugeEdge> removedEdges) {
// Remove related edges of each vertex
for (HugeVertex v : removedVertices.values()) {
if (!v.schemaLabel().existsLinkLabel()) {
continue;
}
// Query all edges of the vertex and remove them
Query query = constructEdgesQuery(v.id(), Directions.BOTH);
Iterator<HugeEdge> vedges = this.queryEdgesFromBackend(query);
try {
while (vedges.hasNext()) {
this.checkTxEdgesCapacity();
HugeEdge edge = vedges.next();
// NOTE: will change the input parameter
removedEdges.put(edge.id(), edge);
// Commit first if enabled commit-part mode
if (this.commitPartOfAdjacentEdges > 0 && removedEdges.size() >= this.commitPartOfAdjacentEdges) {
this.commitPartOfEdgeDeletions(removedEdges);
}
}
} finally {
CloseableIterator.closeIterator(vedges);
}
}
// Remove vertices
for (HugeVertex v : removedVertices.values()) {
this.checkAggregateProperty(v);
/*
* If the backend stores vertex together with edges, it's edges
* would be removed after removing vertex. Otherwise, if the
* backend stores vertex which is separated from edges, it's
* edges should be removed manually when removing vertex.
*/
this.doRemove(this.serializer.writeVertex(v.prepareRemoved()));
this.indexTx.updateVertexIndex(v, true);
this.indexTx.updateLabelIndex(v, true);
}
// Remove edges
this.prepareDeletions(removedEdges);
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class AbstractTransaction method query.
@Watched(prefix = "tx")
public QueryResults<BackendEntry> query(Query query) {
LOG.debug("Transaction query: {}", query);
/*
* NOTE: it's dangerous if an IdQuery/ConditionQuery is empty
* check if the query is empty and its class is not the Query itself
*/
if (query.empty() && !query.getClass().equals(Query.class)) {
throw new BackendException("Query without any id or condition");
}
Query squery = this.serializer.writeQuery(query);
// Do rate limit if needed
RateLimiter rateLimiter = this.graph.readRateLimiter();
if (rateLimiter != null && query.resultType().isGraph()) {
double time = rateLimiter.acquire(1);
if (time > 0) {
LOG.debug("Waited for {}s to query", time);
}
BackendEntryIterator.checkInterrupted();
}
this.beforeRead();
try {
this.injectOlapPkIfNeeded(squery);
return new QueryResults<>(this.store.query(squery), query);
} finally {
// TODO: not complete the iteration currently
this.afterRead();
}
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class EdgeCoreTest method testQueryAllWithLimitByQueryEdges.
@Test
public void testQueryAllWithLimitByQueryEdges() {
HugeGraph graph = graph();
init18Edges();
Query query = new Query(HugeType.EDGE);
query.limit(1);
Iterator<Edge> iter = graph.edges(query);
List<Edge> edges = IteratorUtils.list(iter);
Assert.assertEquals(1, edges.size());
}
Aggregations