use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class EdgesAPI method scan.
@GET
@Timed
@Path("scan")
@Compress
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String scan(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("page") String page, @QueryParam("page_limit") @DefaultValue(DEFAULT_PAGE_LIMIT) long pageLimit) {
LOG.debug("Graph [{}] query edges by shard(start: {}, end: {}, " + "page: {}) ", graph, start, end, page);
HugeGraph g = graph(manager, graph);
ConditionQuery query = new ConditionQuery(HugeType.EDGE_OUT);
query.scan(start, end);
query.page(page);
if (query.paging()) {
query.limit(pageLimit);
}
Iterator<Edge> edges = g.edges(query);
return manager.serializer(g).writeEdges(edges, query.paging());
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class EntityManager method queryEntity.
private Iterator<Vertex> queryEntity(String label, Map<String, Object> conditions, long limit) {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
VertexLabel vl = this.graph().vertexLabel(label);
query.eq(HugeKeys.LABEL, vl.id());
for (Map.Entry<String, Object> entry : conditions.entrySet()) {
PropertyKey pkey = this.graph().propertyKey(entry.getKey());
query.query(Condition.eq(pkey.id(), entry.getValue()));
}
query.showHidden(true);
if (limit != NO_LIMIT) {
query.limit(limit);
}
return this.tx().queryVertices(query);
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class RelationshipManager method queryRelationship.
private Iterator<Edge> queryRelationship(Id source, Directions direction, String label, Map<String, Object> conditions, long limit) {
ConditionQuery query = new ConditionQuery(HugeType.EDGE);
EdgeLabel el = this.graph().edgeLabel(label);
if (direction == null) {
direction = Directions.OUT;
}
if (source != null) {
query.eq(HugeKeys.OWNER_VERTEX, source);
query.eq(HugeKeys.DIRECTION, direction);
}
if (label != null) {
query.eq(HugeKeys.LABEL, el.id());
}
for (Map.Entry<String, Object> entry : conditions.entrySet()) {
PropertyKey pk = this.graph().propertyKey(entry.getKey());
query.query(Condition.eq(pk.id(), entry.getValue()));
}
query.showHidden(true);
if (limit != NO_LIMIT) {
query.limit(limit);
}
Iterator<Edge> edges = this.tx().queryEdges(query);
if (limit == NO_LIMIT) {
return edges;
}
long[] size = new long[1];
return new MapperIterator<>(edges, edge -> {
if (++size[0] > limit) {
return null;
}
return edge;
});
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class TextSerializer method writeQueryCondition.
@Override
protected Query writeQueryCondition(Query query) {
ConditionQuery result = (ConditionQuery) query;
// No user-prop when serialize
assert result.allSysprop();
for (Condition.Relation r : result.relations()) {
// Serialize key
if (query.resultType().isSchema()) {
r.serialKey(((HugeKeys) r.key()).string());
} else {
r.serialKey(formatSyspropName((HugeKeys) r.key()));
}
if (r.value() instanceof Id) {
// Serialize id value
r.serialValue(writeId((Id) r.value()));
} else {
// Serialize other type value
r.serialValue(JsonUtil.toJson(r.value()));
}
if (r.relation() == Condition.RelationType.CONTAINS_KEY) {
// Serialize has-key
String key = (String) r.serialValue();
r.serialValue(formatPropertyName(key));
}
}
return result;
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class BinarySerializer method writeQueryCondition.
@Override
protected Query writeQueryCondition(Query query) {
HugeType type = query.resultType();
if (!type.isIndex()) {
return query;
}
ConditionQuery cq = (ConditionQuery) query;
if (type.isNumericIndex()) {
// Convert range-index/shard-index query to id range query
return this.writeRangeIndexQuery(cq);
} else {
assert type.isSearchIndex() || type.isSecondaryIndex() || type.isUniqueIndex();
// Convert secondary-index or search-index query to id query
return this.writeStringIndexQuery(cq);
}
}
Aggregations