Search in sources :

Example 1 with DataType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType in project legend-pure by finos.

the class ClassProjectionProcessor method validateDerivedProperties.

private static void validateDerivedProperties(RootRouteNode projectionSpec, ProcessorSupport processorSupport) {
    // we can only support derived properties which flatten relations to a primitive type. Qualified Properties are not supported.
    for (PropertyRouteNode derivedProperty : projectionSpec._children()) {
        if (derivedProperty instanceof ExistingPropertyRouteNode) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Found complex property '%s', only simple properties are allowed in a class projection.", derivedProperty._propertyName()));
        }
        CoreInstance derivedPropertyType = derivedProperty._type() == null ? null : ImportStub.withImportStubByPass(derivedProperty._type()._rawTypeCoreInstance(), processorSupport);
        if (!(derivedPropertyType instanceof DataType)) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Derived property '%s' should be of PrimitiveType.", derivedProperty._propertyName()));
        }
        ListIterable<? extends ValueSpecification> valueSpecifications = derivedProperty instanceof NewPropertyRouteNode ? ((NewPropertyRouteNode) derivedProperty)._specifications().toList() : Lists.immutable.<ValueSpecification>empty();
        if (valueSpecifications.size() != 1) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), "Invalid projection specification: derived property '" + derivedProperty._propertyName() + "' should have exactly 1 value specification, found " + valueSpecifications.size());
        }
        if (valueSpecifications.getFirst() instanceof FunctionExpression) {
            CoreInstance func = ImportStub.withImportStubByPass(((FunctionExpression) valueSpecifications.getFirst())._funcCoreInstance(), processorSupport);
            if (func != null && !(func instanceof Property) && Automap.getAutoMapExpressionSequence(valueSpecifications.getFirst()) == null) {
                throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Derived property '%s' should be a simple property.", derivedProperty._propertyName()));
            }
        }
    }
}
Also used : NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) PropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with DataType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType in project legend-pure by finos.

the class ViewProcessing method processPrimaryKeys.

private static void processPrimaryKeys(View view, MapIterable<String, DataType> colMappingTypeByName) {
    RichIterable<? extends Column> primaryKeyCols = view._primaryKey();
    view._userDefinedPrimaryKey(primaryKeyCols.notEmpty());
    if (primaryKeyCols.notEmpty()) {
        setColumnTypes(primaryKeyCols, colMappingTypeByName);
        for (Column col : primaryKeyCols) {
            col._owner(view);
        }
    }
}
Also used : Column(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Column) TableAliasColumn(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn)

Example 3 with DataType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType in project legend-pure by finos.

the class ViewProcessing method processView.

private static void processView(SetIterable<Database> dbsInHierarchy, View view, Matcher matcher, ProcessorState processorState, ModelRepository repository, ProcessorSupport processorSupport) {
    DatabaseProcessor.processColumnsForTableOrView(view);
    RichIterable<? extends ColumnMapping> columnMappings = view._columnMappings();
    MutableMap<String, DataType> colMappingTypeByName = Maps.mutable.ofInitialCapacity(columnMappings.size());
    MutableSet<RelationalOperationElement> columnMappingRootTables = Sets.mutable.empty();
    for (ColumnMapping columnMapping : columnMappings) {
        RelationalOperationElement columnMappingRelationalElement = columnMapping._relationalOperationElement();
        String columnMappingColumnName = columnMapping._columnName();
        RelationalOperationElementProcessor.processColumnExpr(columnMappingRelationalElement, view, null, Sets.mutable.empty(), matcher, processorState, repository, processorSupport);
        RelationalOperationElement columnMappingRootTable = findMainTable(dbsInHierarchy, view, processorSupport, columnMappingRelationalElement);
        if (columnMappingRootTable != null) {
            columnMappingRootTables.add(columnMappingRootTable);
        }
        colMappingTypeByName.put(columnMappingColumnName, getColumnType(columnMappingRelationalElement, processorSupport, repository));
    }
    RelationalOperationElement mainTable = identifyMainTable(view, columnMappingRootTables);
    processDynaFunctionAliases(view, mainTable, processorSupport);
    processFilterMapping(view, null, mainTable, matcher, processorState, repository, processorSupport);
    processGroupByMapping(view, matcher, processorState, repository, mainTable, processorSupport);
    processPrimaryKeys(view, colMappingTypeByName);
    setViewColumnsType(view, colMappingTypeByName);
    setViewMainTableAlias(view, mainTable, processorSupport);
}
Also used : RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) DataType(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.DataType) ColumnMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.ColumnMapping)

Example 4 with DataType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType in project legend-pure by finos.

the class AggregationAwareValidator method run.

@Override
public void run(AggregationAwareSetImplementation instance, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ValidatorState validatorState = (ValidatorState) state;
    ProcessorSupport processorSupport = validatorState.getProcessorSupport();
    for (AggregateSetImplementationContainer container : instance._aggregateSetImplementations()) {
        for (AggregationFunctionSpecification aggregationFunctionSpecification : container._aggregateSpecification()._aggregateValues()) {
            FunctionType mapFnType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._mapFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
            Type mapFnReturnType = (Type) ImportStub.withImportStubByPass(mapFnType._returnType()._rawTypeCoreInstance(), processorSupport);
            if (!Instance.instanceOf(mapFnReturnType, M3Paths.DataType, processorSupport)) {
                throw new PureCompilationException(aggregationFunctionSpecification._mapFn().getSourceInformation(), "An aggregate specification's mapFunction return type should be a DataType (primitive type/enumeration)");
            }
            FunctionType aggregateFnType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._aggregateFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
            Type aggregateFnReturnType = (Type) ImportStub.withImportStubByPass(aggregateFnType._returnType()._rawTypeCoreInstance(), processorSupport);
            if (!Instance.instanceOf(aggregateFnReturnType, M3Paths.DataType, processorSupport)) {
                throw new PureCompilationException(aggregationFunctionSpecification._aggregateFn().getSourceInformation(), "An aggregate specification's aggregateFunction return type should be a DataType (primitive type/enumeration)");
            }
        }
        matcher.fullMatch(container._setImplementation(), state);
    }
    matcher.fullMatch(instance._mainSetImplementation(), state);
}
Also used : Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) AggregateSetImplementationContainer(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSetImplementationContainer) AggregationFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationFunctionSpecification) ValidatorState(org.finos.legend.pure.m3.compiler.validation.ValidatorState) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 5 with DataType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType in project legend-pure by finos.

the class PureInstanceSetImplementationValidator method run.

@Override
public void run(PureInstanceSetImplementation classMapping, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    Class mappedClass = (Class) ImportStub.withImportStubByPass(classMapping._classCoreInstance(), processorSupport);
    LambdaFunction filter = classMapping._filter();
    if (filter != null) {
        Validator.validate(filter, (ValidatorState) state, matcher, processorSupport);
        Type booleanType = (Type) processorSupport.package_getByUserPath(M3Paths.Boolean);
        GenericType filterReturnType = ((FunctionType) processorSupport.function_getFunctionType(filter))._returnType();
        if (filterReturnType._rawTypeCoreInstance() != booleanType) {
            throw new PureCompilationException(((RichIterable<ValueSpecification>) filter._expressionSequence()).toList().get(0).getSourceInformation(), "A filter should be a Boolean expression");
        }
    }
    MutableSet<String> requiredProperties = getRequiredProperties(mappedClass, processorSupport);
    for (PropertyMapping propertyMapping : classMapping._propertyMappings()) {
        Property property = (Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport);
        requiredProperties.remove(org.finos.legend.pure.m3.navigation.property.Property.getPropertyName(property));
        LambdaFunction transform = ((PurePropertyMapping) propertyMapping)._transform();
        FunctionType fType = (FunctionType) processorSupport.function_getFunctionType(transform);
        Validator.validate(transform, (ValidatorState) state, matcher, processorSupport);
        GenericType expressionGenericType = fType._returnType();
        GenericType propertyGenericType = ((Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport))._genericType();
        Multiplicity expressionMultiplicity = fType._returnMultiplicity();
        Multiplicity propertyMultiplicity = ((Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport))._multiplicity();
        if (((PurePropertyMapping) propertyMapping)._transformerCoreInstance() != null) {
            CoreInstance propertyRawType = ImportStub.withImportStubByPass(propertyGenericType._rawTypeCoreInstance(), processorSupport);
            EnumerationMapping transformer = (EnumerationMapping) ImportStub.withImportStubByPass(((PurePropertyMapping) propertyMapping)._transformerCoreInstance(), processorSupport);
            if (!propertyRawType.equals(transformer._enumeration())) {
                throw new PureCompilationException(propertyMapping.getSourceInformation(), "Property : [" + property._name() + "] is of type : [" + PackageableElement.getUserPathForPackageableElement(propertyRawType) + "] but enumeration mapping : [" + transformer._name() + "] is defined on enumeration : [" + PackageableElement.getUserPathForPackageableElement(transformer._enumeration()) + "].");
            }
        } else if (ImportStub.withImportStubByPass(propertyGenericType._rawTypeCoreInstance(), processorSupport) instanceof DataType) {
            if (!org.finos.legend.pure.m3.navigation.generictype.GenericType.isGenericCompatibleWith(expressionGenericType, propertyGenericType, processorSupport)) {
                String valTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(expressionGenericType, false, processorSupport);
                String propertyTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(propertyGenericType, false, processorSupport);
                if (valTypeString.equals(propertyTypeString)) {
                    valTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(expressionGenericType, true, processorSupport);
                    propertyTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(propertyGenericType, true, processorSupport);
                }
                throw new PureCompilationException(((RichIterable<ValueSpecification>) ((PurePropertyMapping) propertyMapping)._transform()._expressionSequence()).toList().get(0).getSourceInformation(), "Type Error: '" + valTypeString + "' not a subtype of '" + propertyTypeString + "'");
            }
        } else {
            Mapping mapping = (Mapping) ImportStub.withImportStubByPass(classMapping._parentCoreInstance(), processorSupport);
            SetImplementation setImplementation = org.finos.legend.pure.m2.dsl.mapping.Mapping.getClassMappingById(mapping, propertyMapping._targetSetImplementationId(), processorSupport);
            if (setImplementation == null) {
                throw new PureCompilationException(propertyMapping.getSourceInformation(), "The set implementation '" + propertyMapping._targetSetImplementationId() + "' is unknown in the mapping '" + mapping.getName() + "'");
            }
            Type srcClass = setImplementation instanceof PureInstanceSetImplementation ? (Type) ImportStub.withImportStubByPass(((PureInstanceSetImplementation) setImplementation)._srcClassCoreInstance(), processorSupport) : null;
            Type expRawType = (Type) ImportStub.withImportStubByPass(expressionGenericType._rawTypeCoreInstance(), processorSupport);
            if (srcClass != null && srcClass != expRawType) {
                throw new PureCompilationException(((RichIterable<ValueSpecification>) ((PurePropertyMapping) propertyMapping)._transform()._expressionSequence()).toList().get(0).getSourceInformation(), "Type Error: '" + PackageableElement.getUserPathForPackageableElement(srcClass) + "' is not '" + PackageableElement.getUserPathForPackageableElement(expRawType) + "'");
            }
        }
        if (!((PurePropertyMapping) propertyMapping)._explodeProperty() && !org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.subsumes(propertyMultiplicity, expressionMultiplicity)) {
            throw new PureCompilationException(((RichIterable<ValueSpecification>) transform._expressionSequence()).toList().get(0).getSourceInformation(), "Multiplicity Error ' The property '" + org.finos.legend.pure.m3.navigation.property.Property.getPropertyName(propertyMapping._propertyCoreInstance()) + "' has a multiplicity range of " + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(propertyMultiplicity) + " when the given expression has a multiplicity range of " + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(expressionMultiplicity));
        }
    }
// TODO add this validation once violations have been removed
// if (requiredProperties.notEmpty())
// {
// StringBuilder message = new StringBuilder("The following required properties for ");
// _Class.print(message, mappedClass, true);
// message.append(" are not mapped: ");
// requiredProperties.toSortedList().appendString(message, ", ");
// throw new PureCompilationException(classMapping.getSourceInformation(), message.toString());
// }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) RichIterable(org.eclipse.collections.api.RichIterable) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)4 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)3 DataType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType)3 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)3 RichIterable (org.eclipse.collections.api.RichIterable)2 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)2 PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)2 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)2 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)2 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)2 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)2 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)2 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1