Search in sources :

Example 1 with GroupByFunctionSpecification

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

the class HelperMappingBuilder method processGroupByFunction.

private static GroupByFunctionSpecification processGroupByFunction(GroupByFunction groupByFunction, CompileContext context, MutableList<String> openVariables, ProcessingContext processingContext) {
    GroupByFunctionSpecification gb = new Root_meta_pure_mapping_aggregationAware_GroupByFunctionSpecification_Impl("");
    gb._groupByFn((LambdaFunction) ((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) groupByFunction.groupByFn.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)))._values().getFirst());
    return gb;
}
Also used : GroupByFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.GroupByFunctionSpecification) Root_meta_pure_mapping_aggregationAware_GroupByFunctionSpecification_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_GroupByFunctionSpecification_Impl)

Example 2 with GroupByFunctionSpecification

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.GroupByFunctionSpecification 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)

Example 3 with GroupByFunctionSpecification

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

the class AggregationAwareUnbind method run.

@Override
public void run(AggregationAwareSetImplementation instance, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    Shared.cleanImportStub(instance._classCoreInstance(), processorSupport);
    Shared.cleanImportStub(instance._parentCoreInstance(), processorSupport);
    for (AggregateSetImplementationContainer container : instance._aggregateSetImplementations()) {
        SetImplementation setImplementation = container._setImplementation();
        Shared.cleanImportStub(setImplementation._classCoreInstance(), processorSupport);
        Shared.cleanImportStub(setImplementation._parentCoreInstance(), processorSupport);
        for (GroupByFunctionSpecification groupByFunctionSpecification : container._aggregateSpecification()._groupByFunctions()) {
            matcher.fullMatch(groupByFunctionSpecification._groupByFn(), state);
            FunctionType functionType = (FunctionType) ImportStub.withImportStubByPass(groupByFunctionSpecification._groupByFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
            functionType._parametersRemove();
            functionType._functionRemove();
        }
        for (AggregationFunctionSpecification aggregationFunctionSpecification : container._aggregateSpecification()._aggregateValues()) {
            matcher.fullMatch(aggregationFunctionSpecification._mapFn(), state);
            matcher.fullMatch(aggregationFunctionSpecification._aggregateFn(), state);
            FunctionType functionType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._mapFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
            functionType._parametersRemove();
            functionType._functionRemove();
            functionType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._aggregateFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
            functionType._parametersRemove();
            functionType._functionRemove();
        }
        matcher.fullMatch(setImplementation, state);
        ((InstanceSetImplementation) setImplementation)._aggregateSpecificationRemove();
    }
    Shared.cleanImportStub(instance._mainSetImplementation()._classCoreInstance(), processorSupport);
    Shared.cleanImportStub(instance._mainSetImplementation()._parentCoreInstance(), processorSupport);
    matcher.fullMatch(instance._mainSetImplementation(), state);
    instance._propertyMappingsRemove();
}
Also used : ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) InstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) AggregateSetImplementationContainer(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSetImplementationContainer) GroupByFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.GroupByFunctionSpecification) AggregationFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationFunctionSpecification) AggregationAwareSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationAwareSetImplementation) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation) InstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation)

Example 4 with GroupByFunctionSpecification

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

the class AggregationAwareGraphBuilder method parseAggregateSpecification.

public final BooleanObjectPair<Pair<String, String>> parseAggregateSpecification(String content, int beginLine, int index) {
    M3AntlrParser parser = new M3AntlrParser();
    M3ProcessorSupport processorSupport = new M3ProcessorSupport(this.context, this.repository);
    String mappingName = this.mappingPath.replace("::", "_");
    String classMappingName = this.classPath.replace("::", "_");
    AntlrContextToM3CoreInstance.LambdaContext lambdaContext = new AntlrContextToM3CoreInstance.LambdaContext(mappingName + '_' + classMappingName + (id == null ? "" : '_' + id) + "_AggregationAware_" + index);
    TemporaryPureAggregateSpecification temporarySpecification = parser.parseAggregateSpecification(content, lambdaContext, this.sourceInformation.getSourceName(), this.sourceInformation.getOffsetLine() + beginLine - 1, this.importId, index, this.repository, processorSupport, this.context);
    MutableList<String> groupByFunctionSpecifications = temporarySpecification.groupByFunctionSpecifications.collect(groupByFunctionSpecification -> "^meta::pure::mapping::aggregationAware::GroupByFunctionSpecification " + groupByFunctionSpecification.sourceInformation.toM4String() + " (" + "groupByFn=^meta::pure::metamodel::function::LambdaFunction " + lambdaContext.getLambdaFunctionUniqueName() + " " + groupByFunctionSpecification.groupByExpression.getSourceInformation().toM4String() + " (" + "classifierGenericType=^meta::pure::metamodel::type::generics::GenericType " + groupByFunctionSpecification.groupByExpression.getSourceInformation().toM4String() + " (rawType=meta::pure::metamodel::function::LambdaFunction, typeArguments=^meta::pure::metamodel::type::generics::GenericType " + groupByFunctionSpecification.groupByExpression.getSourceInformation().toM4String() + " (rawType = ^meta::pure::metamodel::type::FunctionType " + groupByFunctionSpecification.groupByExpression.getSourceInformation().toM4String() + " ()))," + "expressionSequence=" + M3AntlrParser.process(groupByFunctionSpecification.groupByExpression, processorSupport) + "))");
    MutableList<String> aggregationFunctionSpecifications = temporarySpecification.aggregationFunctionSpecifications.collect(aggregationFunctionSpecification -> "^meta::pure::mapping::aggregationAware::AggregationFunctionSpecification " + aggregationFunctionSpecification.sourceInformation.toM4String() + " (" + "mapFn=^meta::pure::metamodel::function::LambdaFunction " + lambdaContext.getLambdaFunctionUniqueName() + " " + aggregationFunctionSpecification.mapExpression.getSourceInformation().toM4String() + " (" + "classifierGenericType=^meta::pure::metamodel::type::generics::GenericType " + aggregationFunctionSpecification.mapExpression.getSourceInformation().toM4String() + " (rawType=meta::pure::metamodel::function::LambdaFunction, typeArguments=^meta::pure::metamodel::type::generics::GenericType " + aggregationFunctionSpecification.mapExpression.getSourceInformation().toM4String() + " (rawType = ^meta::pure::metamodel::type::FunctionType " + aggregationFunctionSpecification.mapExpression.getSourceInformation().toM4String() + " ()))," + "expressionSequence=" + M3AntlrParser.process(aggregationFunctionSpecification.mapExpression, processorSupport) + ")," + "aggregateFn=^meta::pure::metamodel::function::LambdaFunction " + lambdaContext.getLambdaFunctionUniqueName() + " " + aggregationFunctionSpecification.aggregateExpression.getSourceInformation().toM4String() + " (" + "classifierGenericType=^meta::pure::metamodel::type::generics::GenericType " + aggregationFunctionSpecification.aggregateExpression.getSourceInformation().toM4String() + " (rawType=meta::pure::metamodel::function::LambdaFunction, typeArguments=^meta::pure::metamodel::type::generics::GenericType " + aggregationFunctionSpecification.aggregateExpression.getSourceInformation().toM4String() + " (rawType = ^meta::pure::metamodel::type::FunctionType " + aggregationFunctionSpecification.aggregateExpression.getSourceInformation().toM4String() + " ()))," + "expressionSequence=" + M3AntlrParser.process(aggregationFunctionSpecification.aggregateExpression, processorSupport) + "))");
    return PrimitiveTuples.pair(temporarySpecification.canAggregate, Tuples.pair(groupByFunctionSpecifications.makeString(","), aggregationFunctionSpecifications.makeString(",")));
}
Also used : M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) TemporaryPureAggregateSpecification(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.TemporaryPureAggregateSpecification) AntlrContextToM3CoreInstance(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.AntlrContextToM3CoreInstance)

Aggregations

GroupByFunctionSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.GroupByFunctionSpecification)3 AggregationFunctionSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationFunctionSpecification)2 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)2 Root_meta_pure_mapping_aggregationAware_GroupByFunctionSpecification_Impl (org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_GroupByFunctionSpecification_Impl)1 InstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation)1 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)1 AggregateSetImplementationContainer (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSetImplementationContainer)1 AggregationAwareSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationAwareSetImplementation)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 M3ProcessorSupport (org.finos.legend.pure.m3.navigation.M3ProcessorSupport)1 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)1 AntlrContextToM3CoreInstance (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.AntlrContextToM3CoreInstance)1 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)1 TemporaryPureAggregateSpecification (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.TemporaryPureAggregateSpecification)1