Search in sources :

Example 1 with IdHolderList

use of com.baidu.hugegraph.backend.page.IdHolderList in project incubator-hugegraph by apache.

the class GraphIndexTransaction method doSearchIndex.

@Watched(prefix = "index")
private IdHolderList doSearchIndex(ConditionQuery query, MatchedIndex index) {
    query = this.constructSearchQuery(query, index);
    // Sorted by matched count
    IdHolderList holders = new SortByCountIdHolderList(query.paging());
    List<ConditionQuery> flatten = ConditionQueryFlatten.flatten(query);
    for (ConditionQuery q : flatten) {
        if (!q.noLimit() && flatten.size() > 1) {
            // Increase limit for union operation
            increaseLimit(q);
        }
        IndexQueries queries = index.constructIndexQueries(q);
        assert !query.paging() || queries.size() <= 1;
        IdHolder holder = this.doSingleOrJointIndex(queries);
        // NOTE: ids will be merged into one IdHolder if not in paging
        holders.add(holder);
    }
    return holders;
}
Also used : SortByCountIdHolderList(com.baidu.hugegraph.backend.page.SortByCountIdHolderList) SortByCountIdHolderList(com.baidu.hugegraph.backend.page.SortByCountIdHolderList) IdHolderList(com.baidu.hugegraph.backend.page.IdHolderList) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) IdHolder(com.baidu.hugegraph.backend.page.IdHolder) FixedIdHolder(com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder) PagingIdHolder(com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder) BatchIdHolder(com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 2 with IdHolderList

use of com.baidu.hugegraph.backend.page.IdHolderList in project incubator-hugegraph by apache.

the class GraphIndexTransaction method queryByUserprop.

@Watched(prefix = "index")
private IdHolderList queryByUserprop(ConditionQuery query) {
    // related index labels
    if (!this.graph().readMode().showOlap()) {
        for (Id pkId : query.userpropKeys()) {
            PropertyKey propertyKey = this.graph().propertyKey(pkId);
            if (propertyKey.olap()) {
                throw new NotAllowException("Not allowed to query by olap property key '%s'" + " when graph-read-mode is '%s'", propertyKey, this.graph().readMode());
            }
        }
    }
    Set<MatchedIndex> indexes = this.collectMatchedIndexes(query);
    if (indexes.isEmpty()) {
        Id label = query.condition(HugeKeys.LABEL);
        throw noIndexException(this.graph(), query, label);
    }
    // Value type of Condition not matched
    boolean paging = query.paging();
    if (!validQueryConditionValues(this.graph(), query)) {
        return IdHolderList.empty(paging);
    }
    // Do index query
    IdHolderList holders = new IdHolderList(paging);
    for (MatchedIndex index : indexes) {
        for (IndexLabel il : index.indexLabels()) {
            validateIndexLabel(il);
        }
        if (paging && index.indexLabels().size() > 1) {
            throw new NotSupportException("joint index query in paging");
        }
        if (index.containsSearchIndex()) {
            // Do search-index query
            holders.addAll(this.doSearchIndex(query, index));
        } else {
            // Do secondary-index, range-index or shard-index query
            IndexQueries queries = index.constructIndexQueries(query);
            assert !paging || queries.size() <= 1;
            IdHolder holder = this.doSingleOrJointIndex(queries);
            holders.add(holder);
        }
    /*
             * NOTE: need to skip the offset if offset > 0, but can't handle
             * it here because the query may a sub-query after flatten,
             * so the offset will be handle in QueryList.IndexQuery
             *
             * TODO: finish early here if records exceeds required limit with
             *       FixedIdHolder.
             */
    }
    return holders;
}
Also used : SortByCountIdHolderList(com.baidu.hugegraph.backend.page.SortByCountIdHolderList) IdHolderList(com.baidu.hugegraph.backend.page.IdHolderList) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IdHolder(com.baidu.hugegraph.backend.page.IdHolder) FixedIdHolder(com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder) PagingIdHolder(com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder) BatchIdHolder(com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder) Id(com.baidu.hugegraph.backend.id.Id) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) NotAllowException(com.baidu.hugegraph.exception.NotAllowException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 3 with IdHolderList

use of com.baidu.hugegraph.backend.page.IdHolderList in project incubator-hugegraph by apache.

the class GraphIndexTransaction method queryByLabel.

@Watched(prefix = "index")
private IdHolderList queryByLabel(ConditionQuery query) {
    HugeType queryType = query.resultType();
    IndexLabel il = IndexLabel.label(queryType);
    validateIndexLabel(il);
    Id label = query.condition(HugeKeys.LABEL);
    assert label != null;
    HugeType indexType;
    SchemaLabel schemaLabel;
    if (queryType.isVertex()) {
        indexType = HugeType.VERTEX_LABEL_INDEX;
        schemaLabel = this.graph().vertexLabel(label);
    } else if (queryType.isEdge()) {
        indexType = HugeType.EDGE_LABEL_INDEX;
        schemaLabel = this.graph().edgeLabel(label);
    } else {
        throw new HugeException("Can't query %s by label", queryType);
    }
    if (!this.store().features().supportsQueryByLabel() && !schemaLabel.enableLabelIndex()) {
        throw new NoIndexException("Don't accept query by label '%s', " + "label index is disabled", schemaLabel);
    }
    ConditionQuery indexQuery = new ConditionQuery(indexType, query);
    indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id());
    indexQuery.eq(HugeKeys.FIELD_VALUES, label);
    /*
         * We can avoid redundant element ids if set limit, but if there are
         * label index overridden by other vertices with different label,
         * query with limit like g.V().hasLabel('xx').limit(10) may lose some
         * results, so can't set limit here. But in this case, the following
         * query results may be still different:
         *   g.V().hasLabel('xx').count()  // label index count
         *   g.V().hasLabel('xx').limit(-1).count()  // actual vertices count
         * It’s a similar situation for the offset, like:
         *   g.V().hasLabel('xx').range(26, 27)
         *   g.V().hasLabel('xx').range(27, 28)
         * we just reset limit here, but don't reset offset due to performance
         * optimization with index+offset query, see Query.skipOffsetIfNeeded().
         * NOTE: if set offset the backend itself will skip the offset
         */
    indexQuery.copyBasic(query);
    indexQuery.limit(Query.NO_LIMIT);
    IdHolder idHolder = this.doIndexQuery(il, indexQuery);
    IdHolderList holders = new IdHolderList(query.paging());
    holders.add(idHolder);
    return holders;
}
Also used : NoIndexException(com.baidu.hugegraph.exception.NoIndexException) SortByCountIdHolderList(com.baidu.hugegraph.backend.page.SortByCountIdHolderList) IdHolderList(com.baidu.hugegraph.backend.page.IdHolderList) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IdHolder(com.baidu.hugegraph.backend.page.IdHolder) FixedIdHolder(com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder) PagingIdHolder(com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder) BatchIdHolder(com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType) HugeException(com.baidu.hugegraph.HugeException) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

IdHolder (com.baidu.hugegraph.backend.page.IdHolder)3 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)3 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)3 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)3 IdHolderList (com.baidu.hugegraph.backend.page.IdHolderList)3 SortByCountIdHolderList (com.baidu.hugegraph.backend.page.SortByCountIdHolderList)3 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)3 Id (com.baidu.hugegraph.backend.id.Id)2 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)2 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)2 HugeException (com.baidu.hugegraph.HugeException)1 NoIndexException (com.baidu.hugegraph.exception.NoIndexException)1 NotAllowException (com.baidu.hugegraph.exception.NotAllowException)1 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)1 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)1 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)1 HugeType (com.baidu.hugegraph.type.HugeType)1