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

org.vertexium.cypher.executionPlan.MapLiteralExecutionStep Maven / Gradle / Ivy

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

import org.vertexium.cypher.VertexiumCypherQueryContext;
import org.vertexium.cypher.VertexiumCypherResult;

import java.util.HashMap;
import java.util.Map;

public class MapLiteralExecutionStep extends ExecutionStepWithChildren implements ExecutionStepWithResultName {
    private final String resultName;
    private final String[] keys;

    public MapLiteralExecutionStep(String resultName, ExecutionStepWithResultName[] entries) {
        super(entries);
        this.resultName = resultName;
        this.keys = new String[entries.length];
        for (int i = 0; i < entries.length; i++) {
            this.keys[i] = entries[i].getResultName();
        }
    }

    @Override
    public String getResultName() {
        return resultName;
    }

    @Override
    public VertexiumCypherResult execute(VertexiumCypherQueryContext ctx, VertexiumCypherResult source) {
        source = super.execute(ctx, source);
        return source.peek(row -> {
            Map map = new HashMap<>();
            for (String key : this.keys) {
                map.put(key, row.get(key));
            }
            row.popScope(keys.length);
            row.pushScope(getResultName(), map);
        });
    }

    @Override
    public String toString() {
        return String.format("%s {resultName='%s'}", super.toString(), resultName);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy