Search in sources :

Example 1 with DegreeStatisticsVertexProgram

use of ai.grakn.graql.internal.analytics.DegreeStatisticsVertexProgram in project grakn by graknlabs.

the class TinkerComputeQueryRunner method execWithMapReduce.

private <T, S, Q extends StatisticsQuery<?>> TinkerComputeJob<Optional<S>> execWithMapReduce(Q query, MapReduceFactory<T> mapReduceFactory, Function<T, S> operator) {
    return runStatistics(query, tinkerComputeQuery -> {
        AttributeType.DataType<?> dataType = tinkerComputeQuery.getDataTypeOfSelectedResourceTypes();
        if (!tinkerComputeQuery.selectedResourceTypesHaveInstance()) {
            return Optional.empty();
        }
        Set<LabelId> allSubLabelIds = convertLabelsToIds(tinkerComputeQuery.getCombinedSubTypes());
        Set<LabelId> statisticsResourceLabelIds = convertLabelsToIds(tinkerComputeQuery.statisticsResourceLabels());
        GraknMapReduce<T> mapReduce = mapReduceFactory.get(statisticsResourceLabelIds, dataType, DegreeVertexProgram.DEGREE);
        ComputerResult result = tinkerComputeQuery.compute(new DegreeStatisticsVertexProgram(statisticsResourceLabelIds), mapReduce, allSubLabelIds);
        Map<Serializable, T> map = result.memory().get(mapReduce.getClass().getName());
        LOG.debug("Result = " + map.get(MapReduce.NullObject.instance()));
        return Optional.of(operator.apply(map.get(MapReduce.NullObject.instance())));
    });
}
Also used : Serializable(java.io.Serializable) AttributeType(ai.grakn.concept.AttributeType) ComputerResult(org.apache.tinkerpop.gremlin.process.computer.ComputerResult) DegreeStatisticsVertexProgram(ai.grakn.graql.internal.analytics.DegreeStatisticsVertexProgram) LabelId(ai.grakn.concept.LabelId)

Aggregations

AttributeType (ai.grakn.concept.AttributeType)1 LabelId (ai.grakn.concept.LabelId)1 DegreeStatisticsVertexProgram (ai.grakn.graql.internal.analytics.DegreeStatisticsVertexProgram)1 Serializable (java.io.Serializable)1 ComputerResult (org.apache.tinkerpop.gremlin.process.computer.ComputerResult)1