use of org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store in project legend-pure by finos.
the class TypeInference method storeInferredTypeParametersInFunctionExpression.
public static void storeInferredTypeParametersInFunctionExpression(FunctionExpression functionExpression, ProcessorState state, ProcessorSupport processorSupport, Function<?> foundFunction) throws PureCompilationException {
// Store the inferred params in the FunctionExpression
if (!(foundFunction instanceof QualifiedProperty)) {
TypeInferenceContext typeInferenceContext = state.getTypeInferenceContext();
FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(foundFunction);
functionType._typeParameters().forEach(typeParameter -> {
CoreInstance value = typeInferenceContext.getTypeParameterValue(typeParameter._name());
if (value != null) {
functionExpression._resolvedTypeParametersAdd((GenericType) value);
} else if (typeInferenceContext.getParent() == null) {
StringBuilder builder = new StringBuilder("The type parameter ").append(typeParameter._name()).append(" was not resolved (").append(foundFunction._functionName()).append(" / ");
org.finos.legend.pure.m3.navigation.function.FunctionType.print(builder, functionType, processorSupport).append(")!");
throw new PureCompilationException(functionExpression.getSourceInformation(), builder.toString());
}
});
functionType._multiplicityParameters().forEach(multiplicityParameter -> {
String parameterName = multiplicityParameter._valuesCoreInstance().getFirst().getName();
CoreInstance value = typeInferenceContext.getMultiplicityParameterValue(parameterName);
if (value != null) {
functionExpression._resolvedMultiplicityParametersAdd((Multiplicity) value);
} else {
throw new PureCompilationException(functionExpression.getSourceInformation(), "The multiplicity parameter " + parameterName + " was not resolved!");
}
});
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store in project legend-pure by finos.
the class TestCyclicStoreSubstitutionInMappingHierarchy method testCyclicStoreSubstitutionNotAllowedInMappingHierarchy.
@Test
public void testCyclicStoreSubstitutionNotAllowedInMappingHierarchy() {
String mappingSourceCode = "###Mapping\n" + "\n" + "Mapping test::AMapping\n" + "( \n" + " test::A : Relational\n" + " {\n" + " id : [test::ADatabase]ATable.id\n" + " }\n" + ")\n" + "\n" + "Mapping test::BMapping\n" + "( \n" + " include test::AMapping[test::ADatabase->test::CDatabase]\n" + ")\n" + "\n" + "Mapping test::CMapping\n" + "( \n" + " include test::BMapping[test::CDatabase->test::ADatabase]\n" + " test::C extends [test_A] : Relational\n" + " { \n" + " }\n" + ")\n";
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource(MODEL_SOURCE_ID, MODEL_SOURCE_CODE).createInMemorySource(STORE_SOURCE_ID, STORE_SOURCE_CODE).compile(), new RuntimeTestScriptBuilder().createInMemorySource(MAPPING_SOURCE_ID, mappingSourceCode).compileWithExpectedCompileFailure("Cyclic Store Substitution for store [test::ADatabase] in mapping hierarchy", STORE_SOURCE_ID, 3, 16).deleteSource(MAPPING_SOURCE_ID).compile(), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store in project legend-pure by finos.
the class MappingValidator method validateIncludes.
private static void validateIncludes(Mapping mapping, Matcher matcher, ValidatorState state, ProcessorSupport processorSupport) {
ListIterable<? extends MappingInclude> includes = mapping._includes().toList();
int includeCount = includes.size();
if (includeCount > 0) {
// Validate includes individually
MutableList<MapIterable<Store, Store>> storeSubstitutionMaps = FastList.newList(includeCount);
for (MappingInclude include : includes) {
Mapping owner = (Mapping) ImportStub.withImportStubByPass(include._ownerCoreInstance(), processorSupport);
if (owner != mapping) {
StringBuilder message = new StringBuilder("Corrupt mapping include: owner should be ");
PackageableElement.writeUserPathForPackageableElement(message, mapping);
message.append(", found ");
PackageableElement.writeUserPathForPackageableElement(message, owner);
throw new PureCompilationException(include.getSourceInformation(), message.toString());
}
Mapping includedMapping = (Mapping) ImportStub.withImportStubByPass(include._includedCoreInstance(), processorSupport);
Validator.validate(includedMapping, state, matcher, processorSupport);
MapIterable<Store, Store> includeStoreSubstitutions = validateIncludeStoreSubstitutions(include, processorSupport);
storeSubstitutionMaps.add(includeStoreSubstitutions);
}
if (includeCount > 1) {
MutableMap<Store, Store> mergedStoreSubstitutions = Maps.mutable.empty();
for (MapIterable<Store, Store> subMap : storeSubstitutionMaps) {
for (Pair<Store, Store> pair : subMap.keyValuesView()) {
Store original = pair.getOne();
Store substitute = pair.getTwo();
Store otherSubstitute = mergedStoreSubstitutions.put(original, substitute);
if (otherSubstitute != null && otherSubstitute != substitute) {
StringBuilder message = new StringBuilder("Store substitution error: multiple substitutions for ");
PackageableElement.writeUserPathForPackageableElement(message, original);
throw new PureCompilationException(mapping.getSourceInformation(), message.toString());
}
}
}
}
// Validate includes recursively
validateInclusionHierarchy(mapping, Lists.mutable.<Mapping>empty(), processorSupport);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store in project legend-pure by finos.
the class StoreValidator method validateInclusionHierarchy.
private static void validateInclusionHierarchy(Store store, MutableList<Store> visited) {
ListIterable<? extends Store> includedStores = ListHelper.wrapListIterable(store._includes());
if (includedStores.notEmpty()) {
MutableSet<CoreInstance> includesSet = UnifiedSet.newSet(includedStores.size());
visited.add(store);
for (Store includedStore : includedStores) {
// Validate that a single store is not directly included more than once
if (!includesSet.add(includedStore)) {
StringBuilder message = new StringBuilder();
PackageableElement.writeUserPathForPackageableElement(message, includedStore);
message.append(" is included multiple times in ");
PackageableElement.writeUserPathForPackageableElement(message, store);
throw new PureCompilationException(store.getSourceInformation(), message.toString());
}
// Validate that there are no include loops
if (visited.contains(includedStore)) {
CoreInstance rootStore = visited.getFirst();
StringBuilder message = new StringBuilder("Circular include in ");
PackageableElement.writeUserPathForPackageableElement(message, rootStore);
message.append(": ");
for (Store visitedStore : visited) {
PackageableElement.writeUserPathForPackageableElement(message, visitedStore);
message.append(" -> ");
}
PackageableElement.writeUserPathForPackageableElement(message, includedStore);
throw new PureCompilationException(rootStore.getSourceInformation(), message.toString());
}
// Recurse
validateInclusionHierarchy(includedStore, visited);
}
visited.remove(visited.size() - 1);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store in project legend-pure by finos.
the class RelationalAssociationImplementationProcessor method process.
@Override
public void process(RelationalAssociationImplementation associationMapping, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
Mapping parentMapping = (Mapping) ImportStub.withImportStubByPass(associationMapping._parentCoreInstance(), processorSupport);
MapIterable<String, SetImplementation> classMappingIndex = org.finos.legend.pure.m2.dsl.mapping.Mapping.getClassMappingsByIdIncludeEmbedded(parentMapping, processorSupport);
RichIterable<? extends PropertyMapping> propertyMappings = associationMapping._propertyMappings();
for (PropertyMapping propertyMapping : propertyMappings) {
RelationalPropertyMappingProcessor.processRelationalPropertyMapping(propertyMapping, matcher, state, repository, "", processorSupport, associationMapping, associationMapping);
RichIterable<JoinTreeNode> joinTreeNodes = RelationalPropertyMappingProcessor.collectJoinTreeNodes(propertyMapping);
if (joinTreeNodes.notEmpty()) {
CoreInstance sourceSetImplementation = MappingValidator.validateId(associationMapping, propertyMapping, classMappingIndex, propertyMapping._sourceSetImplementationId(), "source", processorSupport);
TableAlias mainTableAlias = findMainTableAlias(sourceSetImplementation, matcher, state, processorSupport);
RelationalOperationElement mainTable = mainTableAlias != null ? mainTableAlias._relationalElement() : null;
for (JoinTreeNode joinTreeNode : joinTreeNodes) {
RelationalOperationElementProcessor.processAliasForJoinTreeNode(joinTreeNode, mainTable, processorSupport);
}
}
}
associationMapping._stores(associationMapping._propertyMappings().collect(STORE).toSet().without(null));
}
Aggregations