Search in sources :

Example 31 with ConditionQuery

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Path(jakarta.ws.rs.Path) Compress(com.baidu.hugegraph.api.filter.CompressInterceptor.Compress) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 32 with ConditionQuery

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);
}
Also used : ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 33 with ConditionQuery

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;
    });
}
Also used : MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 34 with ConditionQuery

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;
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Example 35 with ConditionQuery

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);
    }
}
Also used : ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeType(com.baidu.hugegraph.type.HugeType)

Aggregations

ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)59 Id (com.baidu.hugegraph.backend.id.Id)19 Test (org.junit.Test)19 Condition (com.baidu.hugegraph.backend.query.Condition)17 HugeGraph (com.baidu.hugegraph.HugeGraph)13 ArrayList (java.util.ArrayList)12 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)10 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)10 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)8 Collection (java.util.Collection)8 Query (com.baidu.hugegraph.backend.query.Query)7 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)7 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)7 Map (java.util.Map)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)7 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)6 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)5 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)5 HugeType (com.baidu.hugegraph.type.HugeType)5 ImmutableMap (com.google.common.collect.ImmutableMap)5