use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.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()));
}
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.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);
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.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);
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.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);
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.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());
// }
}
Aggregations