All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vertexium.cypher.functions.aggregate.CountFunction Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cypher.functions.aggregate;

import org.vertexium.cypher.CypherResultRow;
import org.vertexium.cypher.VertexiumCypherQueryContext;
import org.vertexium.cypher.executionPlan.AggregationFunctionInvocationExecutionStep;
import org.vertexium.cypher.executionPlan.ExecutionStepWithResultName;

import java.util.stream.Stream;

public class CountFunction implements AggregationFunction {
    @Override
    public ExecutionStepWithResultName create(String resultName, boolean distinct, ExecutionStepWithResultName[] argumentsExecutionStep) {
        return new AggregationFunctionInvocationExecutionStep(getClass().getSimpleName(), resultName, distinct, argumentsExecutionStep) {
            @Override
            protected CypherResultRow executeAggregation(VertexiumCypherQueryContext ctx, CypherResultRow group, Stream rows) {
                if (rows == null) {
                    return group.clone()
                        .pushScope(getResultName(), 0L);
                }

                long count = rows
                    .filter(row -> row.arguments[0] != null)
                    .count();
                return group.clone()
                    .pushScope(getResultName(), count);
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy