org.vertexium.cypher.functions.aggregate.CountFunction Maven / Gradle / Ivy
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);
}
};
}
}