Search in sources :

Example 1 with CountVertexProgram

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;
    });
}
Also used : CountVertexProgram(ai.grakn.graql.internal.analytics.CountVertexProgram) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) LabelId(ai.grakn.concept.LabelId) CountMapReduceWithAttribute(ai.grakn.graql.internal.analytics.CountMapReduceWithAttribute)

Aggregations

LabelId (ai.grakn.concept.LabelId)1 CountMapReduceWithAttribute (ai.grakn.graql.internal.analytics.CountMapReduceWithAttribute)1 CountVertexProgram (ai.grakn.graql.internal.analytics.CountVertexProgram)1 ComputerResult (org.apache.tinkerpop.gremlin.process.computer.ComputerResult)1