Search in sources :

Example 11 with IdQuery

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

the class SchemaIndexTransaction method queryByName.

@Watched(prefix = "index")
private QueryResults<BackendEntry> queryByName(ConditionQuery query) {
    if (!this.needIndexForName()) {
        return super.query(query);
    }
    IndexLabel il = IndexLabel.label(query.resultType());
    String name = (String) query.condition(HugeKeys.NAME);
    E.checkState(name != null, "The name in condition can't be null " + "when querying schema by name");
    ConditionQuery indexQuery;
    indexQuery = new ConditionQuery(HugeType.SECONDARY_INDEX, query);
    indexQuery.eq(HugeKeys.FIELD_VALUES, name);
    indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id());
    IdQuery idQuery = new IdQuery(query.resultType(), query);
    Iterator<BackendEntry> entries = super.query(indexQuery).iterator();
    try {
        while (entries.hasNext()) {
            HugeIndex index = this.serializer.readIndex(graph(), indexQuery, entries.next());
            idQuery.query(index.elementIds());
            Query.checkForceCapacity(idQuery.idsSize());
        }
    } finally {
        CloseableIterator.closeIterator(entries);
    }
    if (idQuery.ids().isEmpty()) {
        return QueryResults.empty();
    }
    assert idQuery.idsSize() == 1 : idQuery.ids();
    if (idQuery.idsSize() > 1) {
        LOG.warn("Multiple ids are found with same name '{}': {}", name, idQuery.ids());
    }
    return super.query(idQuery);
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

IdQuery (com.baidu.hugegraph.backend.query.IdQuery)11 Id (com.baidu.hugegraph.backend.id.Id)7 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)5 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)4 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 Query (com.baidu.hugegraph.backend.query.Query)3 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)3 HugeException (com.baidu.hugegraph.HugeException)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 BatchMapperIterator (com.baidu.hugegraph.iterator.BatchMapperIterator)2 ExtendableIterator (com.baidu.hugegraph.iterator.ExtendableIterator)2 FlatMapperIterator (com.baidu.hugegraph.iterator.FlatMapperIterator)2 MapperIterator (com.baidu.hugegraph.iterator.MapperIterator)2 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)2 HugeType (com.baidu.hugegraph.type.HugeType)2 HashMap (java.util.HashMap)2 QueryId (com.baidu.hugegraph.backend.cache.CachedBackendStore.QueryId)1 Condition (com.baidu.hugegraph.backend.query.Condition)1 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)1 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)1