use of ai.grakn.graql.internal.analytics.CountVertexProgram in project grakn by graknlabs.
the class TinkerComputeQueryRunner method run.
public ComputeJob<Long> run(CountQuery query) {
return runCompute(query, tinkerComputeQuery -> {
if (!tinkerComputeQuery.selectedTypesHaveInstance()) {
LOG.debug("Count = 0");
return 0L;
}
Set<LabelId> typeLabelIds = convertLabelsToIds(tinkerComputeQuery.subLabels());
Map<Integer, Long> count;
Set<LabelId> rolePlayerLabelIds = tinkerComputeQuery.getRolePlayerLabelIds();
rolePlayerLabelIds.addAll(typeLabelIds);
ComputerResult result = tinkerComputeQuery.compute(new CountVertexProgram(), new CountMapReduceWithAttribute(), rolePlayerLabelIds, false);
count = result.memory().get(CountMapReduceWithAttribute.class.getName());
long finalCount = count.keySet().stream().filter(id -> typeLabelIds.contains(LabelId.of(id))).mapToLong(count::get).sum();
if (count.containsKey(GraknMapReduce.RESERVED_TYPE_LABEL_KEY)) {
finalCount += count.get(GraknMapReduce.RESERVED_TYPE_LABEL_KEY);
}
LOG.debug("Count = " + finalCount);
return finalCount;
});
}
Aggregations