Search in sources :

Example 1 with Store

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!");
            }
        });
    }
}
Also used : FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with Store

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());
}
Also used : RuntimeTestScriptBuilder(org.finos.legend.pure.m3.RuntimeTestScriptBuilder) Test(org.junit.Test)

Example 3 with Store

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);
    }
}
Also used : Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) MapIterable(org.eclipse.collections.api.map.MapIterable) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 4 with Store

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);
    }
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 5 with Store

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));
}
Also used : RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) TableAlias(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode) RootRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RootRelationalInstanceSetImplementation) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation) EmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation)

Aggregations

Store (org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store)11 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)8 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)8 List (java.util.List)7 ListIterate (org.eclipse.collections.impl.utility.ListIterate)7 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)7 RichIterable (org.eclipse.collections.api.RichIterable)6 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)6 FastList (org.eclipse.collections.impl.list.mutable.FastList)5 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)5 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)5 Test (org.junit.Test)5 org.finos.legend.pure.generated (org.finos.legend.pure.generated)4 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)4 Collections (java.util.Collections)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 MutableList (org.eclipse.collections.api.list.MutableList)3 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)3 ArrayList (java.util.ArrayList)2