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