use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda in project legend-sdlc by finos.
the class LegendPureV1TestCase method executeLegend.
protected Result executeLegend(Lambda lambda, String mappingPath, InputStream inputStream) {
LambdaFunction<?> pureLambda = HelperValueSpecificationBuilder.buildLambda(lambda, new CompileContext.Builder(this.pureModel).withElement(mappingPath).build());
Mapping pureMapping = this.pureModel.getMapping(mappingPath);
SingleExecutionPlan executionPlan = PlanGenerator.generateExecutionPlan(pureLambda, pureMapping, this.runtime, null, this.pureModel, null, PlanPlatform.JAVA, null, this.extensions, this.planTransformers);
return this.planExecutor.execute(executionPlan, inputStream);
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda in project legend-engine by finos.
the class AlloyTestServer method buildPlan.
protected SingleExecutionPlan buildPlan(String plan, String timeZone) {
PureModelContextData contextData = PureGrammarParser.newInstance().parseModel(plan);
if (timeZone != null && !timeZone.isEmpty()) {
updateRuntimeWithTimeZone(contextData.getElementsOfType(PackageableRuntime.class).get(0), timeZone);
}
PureModel pureModel = Compiler.compile(contextData, null, null);
Function fetchFunctionExpressions = contextData.getElementsOfType(Function.class).get(0);
return PlanGenerator.generateExecutionPlan(HelperValueSpecificationBuilder.buildLambda(((Lambda) fetchFunctionExpressions.body.get(0)).body, ((Lambda) fetchFunctionExpressions.body.get(0)).parameters, pureModel.getContext()), pureModel.getMapping("test::Map"), pureModel.getRuntime("test::Runtime"), null, pureModel, "vX_X_X", PlanPlatform.JAVA, null, core_relational_relational_router_router_extension.Root_meta_pure_router_extension_defaultRelationalExtensions__RouterExtension_MANY_(pureModel.getExecutionSupport()), LegendPlanTransformers.transformers);
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda in project legend-engine by finos.
the class HelperMappingBuilder method processPurePropertyMappingTransform.
public static LambdaFunction processPurePropertyMappingTransform(PurePropertyMapping ppm, Lambda lambda, PropertyMappingsImplementation owner, org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type inputVarType, CompileContext context, String mappingName) {
List<ValueSpecification> expressions = lambda.body;
VariableExpression lambdaParam = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("")._name("src")._multiplicity(context.pureModel.getMultiplicity("one"))._genericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(inputVarType));
MutableList<VariableExpression> pureParameters = Lists.mutable.with(lambdaParam);
ProcessingContext ctx = new ProcessingContext("Pure M2M Transform Lambda");
ctx.addInferredVariables("src", lambdaParam);
MutableList<String> openVariables = Lists.mutable.empty();
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> valueSpecifications = ListIterate.collect(expressions, p -> p.accept(new ValueSpecificationBuilder(context, openVariables, ctx)));
MutableList<String> cleanedOpenVariables = openVariables.distinct();
cleanedOpenVariables.removeAll(pureParameters.collect(e -> e._name()));
GenericType functionType = context.pureModel.buildFunctionType(pureParameters, valueSpecifications.getLast()._genericType(), valueSpecifications.getLast()._multiplicity());
String propertyName = owner._id() + "." + ppm.property.property;
String mappingPath = Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1_(owner._parent(), context.pureModel.getExecutionSupport()).replace("::", "_");
ctx.flushVariable("src");
return new Root_meta_pure_metamodel_function_LambdaFunction_Impl(propertyName, new SourceInformation(mappingPath, 0, 0, 0, 0), null)._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::metamodel::function::LambdaFunction"))._typeArguments(FastList.newListWith(functionType)))._openVariables(cleanedOpenVariables)._expressionSequence(valueSpecifications);
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda in project legend-engine by finos.
the class HelperMappingBuilder method processAggregateSpecification.
private static AggregateSpecification processAggregateSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateSpecification aggregateSpecification, CompileContext context, MutableList<String> openVariables, String parentClassPath) {
ProcessingContext ctx = new ProcessingContext("Lambda");
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(context, parentClassPath);
ctx.addInferredVariables("this", thisVariable);
AggregateSpecification as = new Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl(" ");
as._canAggregate(aggregateSpecification.canAggregate);
for (GroupByFunction gb : aggregateSpecification.groupByFunctions) {
as._groupByFunctionsAdd(processGroupByFunction(gb, context, openVariables, ctx));
}
for (AggregateFunction af : aggregateSpecification.aggregateValues) {
as._aggregateValuesAdd(processAggregationFunction(af, context, openVariables, ctx));
}
ctx.flushVariable("this");
return as;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda in project legend-engine by finos.
the class Compile method lambdaReturnType.
@POST
@Path("lambdaReturnType")
@ApiOperation(value = "Loads a given model and lambda. Returns the lambda return type")
@Consumes({ MediaType.APPLICATION_JSON, APPLICATION_ZLIB })
@Prometheus(name = "lambda return type")
public Response lambdaReturnType(LambdaReturnTypeInput lambdaReturnTypeInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager<CommonProfile> pm, @Context UriInfo uriInfo) {
MutableList<CommonProfile> profiles = ProfileManagerHelper.extractProfiles(pm);
long start = System.currentTimeMillis();
try {
PureModelContext model = lambdaReturnTypeInput.model;
Lambda lambda = lambdaReturnTypeInput.lambda;
String typeName = modelManager.getLambdaReturnType(lambda, model, model instanceof PureModelContextPointer ? ((PureModelContextPointer) model).serializer.version : null, profiles);
Map<String, String> result = new HashMap<>();
long end = System.currentTimeMillis();
MetricsHandler.observe("lambda return type", start, end);
MetricsHandler.observeRequest(uriInfo != null ? uriInfo.getPath() : null, start, end);
// This is an object in case we want to add more information on the lambda.
result.put("returnType", typeName);
return Response.ok(result, MediaType.APPLICATION_JSON_TYPE).build();
} catch (Exception ex) {
MetricsHandler.observeError("lambda return type");
return handleException(uriInfo, profiles, start, ex);
}
}
Aggregations