Search in sources :

Example 1 with AppliedFunction

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction 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 AppliedFunction

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction in project legend-engine by finos.

the class ValueSpecificationBuilder method visit.

@Override
public ValueSpecification visit(AppliedFunction appliedFunction) {
    processingContext.push("Applying " + appliedFunction.function);
    if (appliedFunction.function.equals("letFunction")) {
        MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> vs = ListIterate.collect(appliedFunction.parameters, expression -> expression.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)));
        String letName = ((CString) appliedFunction.parameters.get(0)).values.get(0);
        org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification ve = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("")._name(letName);
        ve._genericType(vs.get(1)._genericType());
        ve._multiplicity(vs.get(1)._multiplicity());
        processingContext.addInferredVariables(letName, ve);
    }
    org.eclipse.collections.api.tuple.Pair<SimpleFunctionExpression, List<ValueSpecification>> func = this.context.buildFunctionExpression(appliedFunction.function, appliedFunction.fControl, appliedFunction.parameters, openVariables, appliedFunction.sourceInformation, processingContext);
    processingContext.pop();
    Assert.assertTrue(func != null, () -> "Can't find a match for function '" + appliedFunction.function + "(?)'", appliedFunction.sourceInformation, EngineErrorType.COMPILATION);
    Assert.assertTrue(func.getOne() != null, () -> "Can't find a match for function '" + appliedFunction.function + "(" + (func.getTwo() == null ? "?" : LazyIterate.collect(func.getTwo(), v -> (v._genericType() == null ? "?" : v._genericType()._rawType()._name()) + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(v._multiplicity())).makeString(",")) + ")'", appliedFunction.sourceInformation, EngineErrorType.COMPILATION);
    ValueSpecification result = func.getOne();
    result.setSourceInformation(SourceInformationHelper.toM3SourceInformation(appliedFunction.sourceInformation));
    return result;
}
Also used : ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) PureList(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PureList) FastList(org.eclipse.collections.impl.list.mutable.FastList) Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl)

Example 3 with AppliedFunction

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction in project legend-engine by finos.

the class Handlers method aggInference.

public static void aggInference(Object obj, GenericType gt, int mapOffset, int aggOffset, CompileContext cc, MutableList<String> ov, ProcessingContext pc) {
    Lambda aggFirstLambda = null;
    Lambda aggSecondLambda = null;
    if (obj instanceof AppliedFunction) {
        aggFirstLambda = ((Lambda) ((AppliedFunction) obj).parameters.get(mapOffset));
        aggSecondLambda = ((Lambda) ((AppliedFunction) obj).parameters.get(aggOffset));
    } else if (obj instanceof AggregateValue) {
        aggFirstLambda = ((AggregateValue) obj).mapFn;
        aggSecondLambda = ((AggregateValue) obj).aggregateFn;
    } else if (obj instanceof TDSAggregateValue) {
        aggFirstLambda = ((TDSAggregateValue) obj).mapFn;
        aggSecondLambda = ((TDSAggregateValue) obj).aggregateFn;
    }
    if (aggFirstLambda != null && aggSecondLambda != null) {
        updateSimpleLambda(aggFirstLambda, gt, new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity(1, 1));
        ValueSpecification processLambda = aggFirstLambda.accept(new ValueSpecificationBuilder(cc, ov, pc));
        updateSimpleLambda(aggSecondLambda, funcReturnType(processLambda, cc.pureModel), new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity());
    }
}
Also used : TDSAggregateValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.TDSAggregateValue) AggregateValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.AggregateValue) TDSAggregateValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.TDSAggregateValue) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) ValueSpecificationBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder)

Example 4 with AppliedFunction

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction in project legend-engine by finos.

the class HelperValueSpecificationGrammarComposer method renderFunction.

public static String renderFunction(AppliedFunction appliedFunction, DEPRECATED_PureGrammarComposerCore transformer) {
    List<ValueSpecification> parameters = appliedFunction.parameters;
    String functionName = LazyIterate.collect(FastList.newListWith(appliedFunction.function.split("::")), PureGrammarComposerUtility::convertIdentifier).makeString("::");
    if (parameters.isEmpty()) {
        return renderFunctionName(functionName, transformer) + "()";
    }
    ValueSpecification firstArgument = parameters.get(0);
    List<ValueSpecification> otherArguments = parameters.subList(1, parameters.size());
    // it would be wrong to use `->` syntax, e.g. `$x|x.prop1->col()`
    if (firstArgument instanceof Lambda) {
        return renderFunctionName(functionName, transformer) + "(" + (transformer.isRenderingPretty() ? transformer.returnChar() + DEPRECATED_PureGrammarComposerCore.computeIndentationString(transformer, getTabSize(2)) : "") + ListIterate.collect(parameters, p -> p.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance(transformer).withIndentation(getTabSize(2)).build())).makeString("," + (transformer.isRenderingPretty() ? transformer.returnChar() + DEPRECATED_PureGrammarComposerCore.computeIndentationString(transformer, getTabSize(2)) : " ")) + (transformer.isRenderingPretty() ? transformer.returnChar() + DEPRECATED_PureGrammarComposerCore.computeIndentationString(transformer, getTabSize(1)) : "") + ")";
    }
    if (otherArguments.size() == 0) {
        if (firstArgument instanceof AppliedFunction && SPECIAL_INFIX.get(((AppliedFunction) firstArgument).function) != null) {
            return functionName + "(" + firstArgument.accept(transformer) + ")";
        } else if (isPrimitiveValue(firstArgument)) {
            return renderFunctionName(functionName, transformer) + "(" + firstArgument.accept(transformer) + ")";
        }
        return firstArgument.accept(transformer) + (transformer.isRenderingHTML() ? "<span class='pureGrammar-arrow'>" : "") + "->" + (transformer.isRenderingHTML() ? "</span>" : "") + renderFunctionName(functionName, transformer) + "()";
    }
    if (otherArguments.size() == 1 && isPrimitiveValue(otherArguments.get(0))) {
        return firstArgument.accept(transformer) + (transformer.isRenderingHTML() ? "<span class='pureGrammar-arrow'>" : "") + "->" + (transformer.isRenderingHTML() ? "</span>" : "") + renderFunctionName(functionName, transformer) + "(" + otherArguments.get(0).accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance(transformer).withIndentation(getTabSize(1)).build()) + ")";
    }
    return firstArgument.accept(transformer) + (transformer.isRenderingHTML() ? "<span class='pureGrammar-arrow'>" : "") + "->" + (transformer.isRenderingHTML() ? "</span>" : "") + renderFunctionName(functionName, transformer) + "(" + (transformer.isRenderingPretty() ? transformer.returnChar() + DEPRECATED_PureGrammarComposerCore.computeIndentationString(transformer, getTabSize(1)) : "") + ListIterate.collect(otherArguments, p -> p.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance(transformer).withIndentation(getTabSize(1)).build())).makeString("," + (transformer.isRenderingPretty() ? transformer.returnChar() + DEPRECATED_PureGrammarComposerCore.computeIndentationString(transformer, getTabSize(1)) : " ")) + (transformer.isRenderingPretty() ? transformer.returnChar() + transformer.getIndentationString() : "") + ")";
}
Also used : ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)

Example 5 with AppliedFunction

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction in project legend-engine by finos.

the class DomainParseTreeWalker method letExpression.

private AppliedFunction letExpression(DomainParserGrammar.LetExpressionContext ctx, List<String> typeParametersNames, LambdaContext lambdaContext, boolean addLines, String space) {
    ValueSpecification result = this.combinedExpression(ctx.combinedExpression(), "", typeParametersNames, lambdaContext, space, true, addLines);
    result.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    CString cString = new CString();
    List<String> values = new ArrayList<>();
    values.add(PureGrammarParserUtility.fromIdentifier(ctx.identifier()));
    cString.multiplicity = this.getMultiplicityOneOne();
    cString.values = values;
    AppliedFunction appliedFunction = this.createAppliedFunction(Lists.mutable.of(cString, result), "letFunction");
    appliedFunction.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    return appliedFunction;
}
Also used : ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) ArrayList(java.util.ArrayList) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)

Aggregations

AppliedFunction (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction)14 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)9 CString (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)4 Lambda (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)3 ArrayList (java.util.ArrayList)2 FastList (org.eclipse.collections.impl.list.mutable.FastList)2 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)2 List (java.util.List)1 MutableList (org.eclipse.collections.api.list.MutableList)1 ValueSpecificationBuilder (org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder)1 DomainParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.domain.DomainParserGrammar)1 IPlatformPureExpressionExecutionNodeSerializeSpecifics (org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics)1 IExecutionNodeContext (org.finos.legend.engine.plan.dependencies.store.shared.IExecutionNodeContext)1 DefaultExecutionNodeContext (org.finos.legend.engine.plan.execution.nodes.helpers.platform.DefaultExecutionNodeContext)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 Result (org.finos.legend.engine.plan.execution.result.Result)1 ResultVisitor (org.finos.legend.engine.plan.execution.result.ResultVisitor)1 GraphFetchResult (org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult)1