org.vertexium.cypher.executionPlan.UnwindClauseExecutionStep Maven / Gradle / Ivy
package org.vertexium.cypher.executionPlan;
import org.vertexium.cypher.CypherResultRow;
import org.vertexium.cypher.SingleRowVertexiumCypherResult;
import org.vertexium.cypher.VertexiumCypherQueryContext;
import org.vertexium.cypher.VertexiumCypherResult;
import org.vertexium.cypher.exceptions.VertexiumCypherNotImplemented;
import java.util.Arrays;
import java.util.stream.Stream;
import static org.vertexium.util.StreamUtils.stream;
public class UnwindClauseExecutionStep extends ExecutionStepWithChildren {
private final String name;
private final String expressionResultName;
public UnwindClauseExecutionStep(String name, ExecutionStepWithResultName expression) {
super(expression);
this.name = name;
this.expressionResultName = expression.getResultName();
}
@Override
public VertexiumCypherResult execute(VertexiumCypherQueryContext ctx, VertexiumCypherResult source) {
if (source == null) {
source = new SingleRowVertexiumCypherResult();
}
source = super.execute(ctx, source);
return source.flatMapCypherResult(this::executeOnRow);
}
@SuppressWarnings("unchecked")
private Stream executeOnRow(CypherResultRow row) {
Object expressionResult = row.get(expressionResultName);
row.popScope();
if (expressionResult instanceof Iterable) {
return executeOnStream(row, stream((Iterable