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

org.vertexium.cypher.functions.aggregate.CollectFunction 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 CollectFunction 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) {
                Object[] value = rows
                    .map(r -> r.arguments[0])
                    .filter(r -> r != null)
                    .toArray(Object[]::new);
                return group.clone()
                    .pushScope(getResultName(), value);
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy