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);
}
}
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;
}
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());
}
}
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() : "") + ")";
}
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;
}
Aggregations