Search in sources :

Example 1 with AggregateSpecification

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSpecification 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;
}
Also used : GroupByFunction(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.GroupByFunction) Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl) AggregateFunction(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateFunction) AggregateSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSpecification)

Example 2 with AggregateSpecification

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSpecification in project legend-pure by finos.

the class AggregationAwareProcessor method processAggregateSpecification.

private void processAggregateSpecification(AggregateSpecification aggregateSpecification, InstanceSetImplementation setImplementation, ClassInstance _class, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
    int i = 0;
    for (GroupByFunctionSpecification groupByFunctionSpecification : aggregateSpecification._groupByFunctions()) {
        state.pushVariableContext();
        VariableExpression thisParam = VariableExpressionInstance.createPersistent(repository, aggregateSpecification.getSourceInformation(), (GenericType) Type.wrapGenericType(_class, processorSupport), (Multiplicity) processorSupport.package_getByUserPath(M3Paths.PureOne), "this");
        FunctionType functionType = (FunctionType) ImportStub.withImportStubByPass(groupByFunctionSpecification._groupByFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
        functionType._parameters(((ImmutableList<VariableExpression>) Lists.immutable.withAll(functionType._parameters())).newWithAll(Lists.immutable.with(thisParam)));
        matcher.fullMatch(groupByFunctionSpecification._groupByFn(), state);
        ValueSpecification groupByFnExpressionSequence = groupByFunctionSpecification._groupByFn()._expressionSequence().toList().getFirst();
        this.addAggregateSpecificationUsageContext(groupByFnExpressionSequence, setImplementation, i, processorSupport);
        i++;
        state.popVariableContext();
    }
    for (AggregationFunctionSpecification aggregationFunctionSpecification : aggregateSpecification._aggregateValues()) {
        state.pushVariableContext();
        VariableExpression thisParam = VariableExpressionInstance.createPersistent(repository, aggregateSpecification.getSourceInformation(), (GenericType) Type.wrapGenericType(_class, processorSupport), (Multiplicity) processorSupport.package_getByUserPath(M3Paths.PureOne), "this");
        FunctionType mapFnType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._mapFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
        mapFnType._parameters(((ImmutableList<VariableExpression>) Lists.immutable.withAll(mapFnType._parameters())).newWithAll(Lists.immutable.with(thisParam)));
        matcher.fullMatch(aggregationFunctionSpecification._mapFn(), state);
        ValueSpecification mapFnExpressionSequence = aggregationFunctionSpecification._mapFn()._expressionSequence().toList().getFirst();
        this.addAggregateSpecificationUsageContext(mapFnExpressionSequence, setImplementation, i, processorSupport);
        i++;
        state.popVariableContext();
        state.pushVariableContext();
        VariableExpression mappedParam = VariableExpressionInstance.createPersistent(repository, aggregateSpecification.getSourceInformation(), mapFnType._returnType(), (Multiplicity) processorSupport.package_getByUserPath(M3Paths.ZeroMany), "mapped");
        FunctionType aggregateFnType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._aggregateFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
        aggregateFnType._parameters(((ImmutableList<VariableExpression>) Lists.immutable.withAll(aggregateFnType._parameters())).newWithAll(Lists.immutable.with(mappedParam)));
        matcher.fullMatch(aggregationFunctionSpecification._aggregateFn(), state);
        ValueSpecification aggregateFnExpressionSequence = aggregationFunctionSpecification._aggregateFn()._expressionSequence().toList().getFirst();
        this.addAggregateSpecificationUsageContext(aggregateFnExpressionSequence, setImplementation, i, processorSupport);
        i++;
        state.popVariableContext();
    }
}
Also used : FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) GroupByFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.GroupByFunctionSpecification) AggregationFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationFunctionSpecification)

Aggregations

AggregateFunction (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateFunction)1 GroupByFunction (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.GroupByFunction)1 Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl (org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl)1 AggregateSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSpecification)1 AggregationFunctionSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationFunctionSpecification)1 GroupByFunctionSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.GroupByFunctionSpecification)1 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)1 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)1 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)1