Search in sources :

Example 6 with Query

use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.

the class HugeTraverser method edgesOfVertex.

private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep, boolean mustAllSK) {
    Id[] edgeLabels = edgeStep.edgeLabels();
    Query query = GraphTransaction.constructEdgesQuery(source, edgeStep.direction(), edgeLabels);
    ConditionQuery filter = null;
    if (mustAllSK) {
        this.fillFilterBySortKeys(query, edgeLabels, edgeStep.properties());
    } else {
        filter = (ConditionQuery) query.copy();
        this.fillFilterByProperties(filter, edgeStep.properties());
    }
    query.capacity(Query.NO_CAPACITY);
    if (edgeStep.limit() != NO_LIMIT) {
        query.limit(edgeStep.limit());
    }
    Iterator<Edge> edges = this.graph().edges(query);
    if (filter != null) {
        ConditionQuery finalFilter = filter;
        edges = new FilterIterator<>(edges, (e) -> {
            return finalFilter.test((HugeEdge) e);
        });
    }
    return edgeStep.skipSuperNodeIfNeeded(edges);
}
Also used : QueryResults(com.baidu.hugegraph.backend.query.QueryResults) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) CollectionUtil(com.baidu.hugegraph.util.CollectionUtil) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) FilterIterator(com.baidu.hugegraph.iterator.FilterIterator) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) HugeGraph(com.baidu.hugegraph.HugeGraph) Map(java.util.Map) Query(com.baidu.hugegraph.backend.query.Query) CollectionFactory(com.baidu.hugegraph.util.collection.CollectionFactory) E(com.baidu.hugegraph.util.E) CoreOptions(com.baidu.hugegraph.config.CoreOptions) Edge(org.apache.tinkerpop.gremlin.structure.Edge) MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) CollectionType(com.baidu.hugegraph.type.define.CollectionType) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) ExtendableIterator(com.baidu.hugegraph.iterator.ExtendableIterator) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) EdgeStep(com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InsertionOrderUtil(com.baidu.hugegraph.util.InsertionOrderUtil) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) LimitIterator(com.baidu.hugegraph.iterator.LimitIterator) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched) Objects(java.util.Objects) MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) HugeException(com.baidu.hugegraph.HugeException) List(java.util.List) Log(com.baidu.hugegraph.util.Log) Directions(com.baidu.hugegraph.type.define.Directions) Aggregate(com.baidu.hugegraph.backend.query.Aggregate) Id(com.baidu.hugegraph.backend.id.Id) TraversalUtil(com.baidu.hugegraph.traversal.optimize.TraversalUtil) Collections(java.util.Collections) HugeType(com.baidu.hugegraph.type.HugeType) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 7 with Query

use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.

the class HugeGraphStep method makeQuery.

private Query makeQuery(HugeGraph graph, HugeType type) {
    Query query = null;
    if (this.hasContainers.isEmpty()) {
        // Query all
        query = new Query(type);
    } else {
        ConditionQuery q = new ConditionQuery(type);
        query = TraversalUtil.fillConditionQuery(q, this.hasContainers, graph);
    }
    query = this.injectQueryInfo(query);
    return query;
}
Also used : ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery)

Example 8 with Query

use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.

the class HugeGraphStep method verticesCount.

private long verticesCount() {
    if (!this.hasIds()) {
        HugeGraph graph = TraversalUtil.getGraph(this);
        Query query = this.makeQuery(graph, HugeType.VERTEX);
        return graph.queryNumber(query).longValue();
    }
    return IteratorUtils.count(this.vertices());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Query(com.baidu.hugegraph.backend.query.Query)

Example 9 with Query

use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.

the class HugeGraphStep method vertices.

private Iterator<E> vertices() {
    LOG.debug("HugeGraphStep.vertices(): {}", this);
    HugeGraph graph = TraversalUtil.getGraph(this);
    // g.V().hasId(EMPTY_LIST) will set ids to null
    if (this.ids == null) {
        return QueryResults.emptyIterator();
    }
    if (this.hasIds()) {
        return TraversalUtil.filterResult(this.hasContainers, graph.vertices(this.ids));
    }
    Query query = this.makeQuery(graph, HugeType.VERTEX);
    @SuppressWarnings("unchecked") Iterator<E> result = (Iterator<E>) graph.vertices(query);
    return result;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Query(com.baidu.hugegraph.backend.query.Query) Iterator(java.util.Iterator)

Example 10 with Query

use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.

the class HugeVariables method queryAllVariableVertices.

private Iterator<Vertex> queryAllVariableVertices() {
    GraphTransaction tx = this.params.graphTransaction();
    Query query = this.createVariableQuery(null);
    Iterator<Vertex> vertices = tx.queryVertices(query);
    return vertices;
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction)

Aggregations

Query (com.baidu.hugegraph.backend.query.Query)31 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)24 Id (com.baidu.hugegraph.backend.id.Id)11 HugeGraph (com.baidu.hugegraph.HugeGraph)9 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)9 HugeType (com.baidu.hugegraph.type.HugeType)7 Iterator (java.util.Iterator)7 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)6 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)5 Edge (org.apache.tinkerpop.gremlin.structure.Edge)5 Test (org.junit.Test)5 HugeException (com.baidu.hugegraph.HugeException)4 BackendException (com.baidu.hugegraph.backend.BackendException)4 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)4 ArrayList (java.util.ArrayList)4 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)3 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)3