use of com.baidu.hugegraph.backend.query.ConditionQuery.OptimizedType in project incubator-hugegraph by apache.
the class GraphTransaction method queryNumber.
@Override
public Number queryNumber(Query query) {
E.checkArgument(!this.hasUpdate(), "It's not allowed to query number when " + "there are uncommitted records.");
if (!(query instanceof ConditionQuery)) {
return super.queryNumber(query);
}
Aggregate aggregate = query.aggregateNotNull();
QueryList<Number> queries = this.optimizeQueries(query, q -> {
boolean indexQuery = q.getClass() == IdQuery.class;
OptimizedType optimized = ((ConditionQuery) query).optimized();
Number result;
if (!indexQuery) {
result = super.queryNumber(q);
} else {
E.checkArgument(aggregate.func() == AggregateFunc.COUNT, "The %s operator on index is not supported now", aggregate.func().string());
if (this.optimizeAggrByIndex && optimized == OptimizedType.INDEX) {
// The ids size means results count (assume no left index)
result = q.idsSize();
} else {
assert optimized == OptimizedType.INDEX_FILTER || optimized == OptimizedType.INDEX;
assert q.resultType().isVertex() || q.resultType().isEdge();
result = IteratorUtils.count(q.resultType().isVertex() ? this.queryVertices(q) : this.queryEdges(q));
}
}
return new QueryResults<>(IteratorUtils.of(result), q);
});
QueryResults<Number> results = queries.empty() ? QueryResults.empty() : queries.fetch(this.pageSize);
return aggregate.reduce(results.iterator());
}
Aggregations