Search in sources :

Example 1 with DefaultExecutionNodeContext

use of org.finos.legend.engine.plan.execution.nodes.helpers.platform.DefaultExecutionNodeContext in project legend-engine by finos.

the class ExecutionNodeExecutor method visit.

@Override
public Result visit(PureExpressionPlatformExecutionNode pureExpressionPlatformExecutionNode) {
    if (!(pureExpressionPlatformExecutionNode.implementation instanceof JavaPlatformImplementation)) {
        throw new RuntimeException("Only Java implementations are currently supported, found: " + pureExpressionPlatformExecutionNode.implementation);
    }
    JavaPlatformImplementation javaPlatformImpl = (JavaPlatformImplementation) pureExpressionPlatformExecutionNode.implementation;
    String executionClassName = JavaHelper.getExecutionClassFullName(javaPlatformImpl);
    Class<?> clazz = ExecutionNodeJavaPlatformHelper.getClassToExecute(pureExpressionPlatformExecutionNode, executionClassName, this.executionState, this.profiles);
    if (Arrays.asList(clazz.getInterfaces()).contains(IPlatformPureExpressionExecutionNodeSerializeSpecifics.class)) {
        try {
            org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics nodeSpecifics = (org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics) clazz.newInstance();
            Result childResult = pureExpressionPlatformExecutionNode.executionNodes().getFirst().accept(new ExecutionNodeExecutor(profiles, executionState));
            IExecutionNodeContext context = new DefaultExecutionNodeContext(this.executionState, childResult);
            AppliedFunction f = (AppliedFunction) pureExpressionPlatformExecutionNode.pure;
            SerializationConfig config = f.parameters.size() == 3 ? (SerializationConfig) f.parameters.get(2) : null;
            return ExecutionNodeSerializerHelper.executeSerialize(nodeSpecifics, config, childResult, context);
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    if (Arrays.asList(clazz.getInterfaces()).contains(IPlatformPureExpressionExecutionNodeGraphFetchUnionSpecifics.class)) {
        StreamingObjectResult<?> streamResult1 = (StreamingObjectResult) pureExpressionPlatformExecutionNode.executionNodes.get(0).accept(new ExecutionNodeExecutor(this.profiles, this.executionState));
        StreamingObjectResult<?> streamResult2 = (StreamingObjectResult) pureExpressionPlatformExecutionNode.executionNodes.get(1).accept(new ExecutionNodeExecutor(this.profiles, this.executionState));
        Result childResult = new Result("success") {

            @Override
            public <T> T accept(ResultVisitor<T> resultVisitor) {
                throw new RuntimeException("Not implemented");
            }

            @Override
            public void close() {
                streamResult1.close();
                streamResult2.close();
            }
        };
        return new StreamingObjectResult<>(Stream.concat(streamResult1.getObjectStream(), streamResult2.getObjectStream()), streamResult1.getResultBuilder(), childResult);
    }
    if (Arrays.asList(clazz.getInterfaces()).contains(IPlatformPureExpressionExecutionNodeGraphFetchMergeSpecifics.class)) {
        StreamingObjectResult<?> streamResult = (StreamingObjectResult) pureExpressionPlatformExecutionNode.executionNodes.get(0).accept(new ExecutionNodeExecutor(this.profiles, this.executionState));
        return streamResult;
    } else {
        return ExecutionNodeJavaPlatformHelper.executeJavaImplementation(pureExpressionPlatformExecutionNode, DefaultExecutionNodeContext.factory(), this.profiles, this.executionState);
    }
}
Also used : ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) GraphFetchResult(org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) Result(org.finos.legend.engine.plan.execution.result.Result) MultiResult(org.finos.legend.engine.plan.execution.result.MultiResult) IPlatformPureExpressionExecutionNodeSerializeSpecifics(org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation) SerializationConfig(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.SerializationConfig) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) IPlatformPureExpressionExecutionNodeSerializeSpecifics(org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics) IExecutionNodeContext(org.finos.legend.engine.plan.dependencies.store.shared.IExecutionNodeContext) DefaultExecutionNodeContext(org.finos.legend.engine.plan.execution.nodes.helpers.platform.DefaultExecutionNodeContext) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) ResultVisitor(org.finos.legend.engine.plan.execution.result.ResultVisitor)

Example 2 with DefaultExecutionNodeContext

use of org.finos.legend.engine.plan.execution.nodes.helpers.platform.DefaultExecutionNodeContext in project legend-engine by finos.

the class JsonExecutionExtension method executeSerialize.

private Result executeSerialize(JsonSerializeExecutionNode node, MutableList<CommonProfile> profiles, ExecutionState executionState) {
    try {
        if (!(node.implementation instanceof JavaPlatformImplementation)) {
            throw new RuntimeException("Only Java implementations are currently supported, found: " + node.implementation);
        }
        JavaPlatformImplementation javaPlatformImpl = (JavaPlatformImplementation) node.implementation;
        String executionClassName = JavaHelper.getExecutionClassFullName(javaPlatformImpl);
        Class<?> clazz = ExecutionNodeJavaPlatformHelper.getClassToExecute(node, executionClassName, executionState, profiles);
        org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics nodeSpecifics = (org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics) clazz.newInstance();
        Result childResult = node.executionNodes().getFirst().accept(new ExecutionNodeExecutor(profiles, executionState));
        IExecutionNodeContext context = new DefaultExecutionNodeContext(executionState, childResult);
        return ExecutionNodeSerializerHelper.executeSerialize(nodeSpecifics, null, childResult, context);
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
Also used : ExecutionNodeExecutor(org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor) IExecutionNodeContext(org.finos.legend.engine.plan.dependencies.store.shared.IExecutionNodeContext) DefaultExecutionNodeContext(org.finos.legend.engine.plan.execution.nodes.helpers.platform.DefaultExecutionNodeContext) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) Result(org.finos.legend.engine.plan.execution.result.Result) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation)

Aggregations

IExecutionNodeContext (org.finos.legend.engine.plan.dependencies.store.shared.IExecutionNodeContext)2 DefaultExecutionNodeContext (org.finos.legend.engine.plan.execution.nodes.helpers.platform.DefaultExecutionNodeContext)2 Result (org.finos.legend.engine.plan.execution.result.Result)2 StreamingObjectResult (org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult)2 JavaPlatformImplementation (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation)2 IPlatformPureExpressionExecutionNodeSerializeSpecifics (org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics)1 ExecutionNodeExecutor (org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor)1 ConstantResult (org.finos.legend.engine.plan.execution.result.ConstantResult)1 ErrorResult (org.finos.legend.engine.plan.execution.result.ErrorResult)1 MultiResult (org.finos.legend.engine.plan.execution.result.MultiResult)1 ResultVisitor (org.finos.legend.engine.plan.execution.result.ResultVisitor)1 GraphFetchResult (org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult)1 AppliedFunction (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction)1 SerializationConfig (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.SerializationConfig)1