Search in sources :

Example 1 with EnumValue

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.

the class RelationalGraphFetchUtils method subTreeValidForCaching.

static boolean subTreeValidForCaching(GraphFetchTree graphFetchTree) {
    boolean currentValidity = true;
    if (graphFetchTree instanceof PropertyGraphFetchTree) {
        PropertyGraphFetchTree propertyGraphFetchTree = (PropertyGraphFetchTree) graphFetchTree;
        if (propertyGraphFetchTree.parameters != null && !propertyGraphFetchTree.parameters.isEmpty()) {
            currentValidity = propertyGraphFetchTree.parameters.stream().allMatch(param -> param instanceof CBoolean || param instanceof CInteger || param instanceof CFloat || param instanceof CDecimal || param instanceof CString || param instanceof CStrictDate || param instanceof CDateTime || param instanceof EnumValue || (param instanceof Collection && ((Collection) param).values.stream().allMatch(x -> x instanceof EnumValue)));
        }
    }
    boolean childrenValidity = graphFetchTree.subTrees == null || graphFetchTree.subTrees.isEmpty() || graphFetchTree.subTrees.stream().allMatch(RelationalGraphFetchUtils::subTreeValidForCaching);
    return currentValidity && childrenValidity;
}
Also used : PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) CDateTime(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime) DoubleStrategyHashMap(org.finos.legend.engine.shared.core.collectionsExtensions.DoubleStrategyHashMap) GraphFetchCache(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCache) BiFunction(java.util.function.BiFunction) ObjectInputStream(java.io.ObjectInputStream) GraphFetchCacheKey(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheKey) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) DoubleHashingStrategy(org.finos.legend.engine.shared.core.collectionsExtensions.DoubleHashingStrategy) Function(java.util.function.Function) ArrayList(java.util.ArrayList) GraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.GraphFetchTree) GraphFetchCacheByEqualityKeys(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheByEqualityKeys) CDecimal(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDecimal) CFloat(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CFloat) ObjectOutputStream(java.io.ObjectOutputStream) Collector(java.util.stream.Collector) Method(java.lang.reflect.Method) CBoolean(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CBoolean) CInteger(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CInteger) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) EnumValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue) IOException(java.io.IOException) Collection(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) SQLExecutionResult(org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult) CStrictDate(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CStrictDate) CDateTime(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime) EnumValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue) CBoolean(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CBoolean) CInteger(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CInteger) CFloat(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CFloat) CStrictDate(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CStrictDate) Collection(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection) CDecimal(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDecimal) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)

Example 2 with EnumValue

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.

the class ClassMappingSecondPassBuilder method visit.

@Override
public SetImplementation visit(PureInstanceClassMapping classMapping) {
    PureInstanceSetImplementation s = (PureInstanceSetImplementation) parentMapping._classMappings().select(c -> c._id().equals(HelperMappingBuilder.getClassMappingId(classMapping, this.context))).getFirst();
    s._propertyMappings().forEachWithIndex((ObjectIntProcedure<org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping>) ((p, i) -> {
        org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping pm = (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) p;
        org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property<?, ?> property = pm._property();
        SourceInformation pSourceInformation = SourceInformationHelper.fromM3SourceInformation(p.getSourceInformation());
        org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification last = pm._transform()._expressionSequence().getLast();
        List<Type> typesToCheck;
        if (property._genericType()._rawType()._classifierGenericType()._rawType()._name().equals("Class")) {
            SetImplementation setImplementation;
            if (p._targetSetImplementationId() != null && !p._targetSetImplementationId().equals("")) {
                setImplementation = parentMapping._classMappingByIdRecursive(Lists.fixedSize.with(p._targetSetImplementationId()), this.context.pureModel.getExecutionSupport()).getFirst();
                Assert.assertTrue(setImplementation != null, () -> "Can't find class mapping '" + p._targetSetImplementationId() + "'", pSourceInformation, EngineErrorType.COMPILATION);
            } else {
                setImplementation = parentMapping.classMappingByClass((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<Object>) property._genericType()._rawType(), this.context.pureModel.getExecutionSupport()).getFirst();
                Assert.assertTrue(setImplementation != null, () -> "Can't find class mapping for '" + HelperModelBuilder.getElementFullPath(property._genericType()._rawType(), this.context.pureModel.getExecutionSupport()) + "'", pSourceInformation, EngineErrorType.COMPILATION);
            }
            List<? extends InstanceSetImplementation> setImpls = core_pure_router_router_routing.Root_meta_pure_router_routing_resolveOperation_SetImplementation_MANY__Mapping_1__InstanceSetImplementation_MANY_(Lists.immutable.of(setImplementation), parentMapping, this.context.pureModel.getExecutionSupport()).toList();
            typesToCheck = setImpls.stream().map(setImpl -> ((PureInstanceSetImplementation) setImpl)._srcClass()).collect(Collectors.toList());
        } else if (((org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) p)._transformer() != null) {
            EnumerationMapping<Object> m = ((EnumerationMapping<Object>) ((org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) p)._transformer());
            Object val = m._enumValueMappings().getFirst()._sourceValues().getFirst();
            if (val instanceof String) {
                typesToCheck = Collections.singletonList(this.context.pureModel.getType("String"));
            } else if (val instanceof Long) {
                typesToCheck = Collections.singletonList(this.context.pureModel.getType("Integer"));
            } else if (val instanceof EnumValue) {
                typesToCheck = Collections.singletonList(this.context.resolveEnumeration(((EnumValue) val).fullPath, pSourceInformation));
            } else if (val instanceof Enum) {
                GenericType genericType = ((Enum) val)._classifierGenericType();
                typesToCheck = genericType != null ? Collections.singletonList(this.context.resolveEnumeration(PackageableElement.getUserPathForPackageableElement(genericType._rawType()), pSourceInformation)) : Collections.emptyList();
            } else {
                typesToCheck = Collections.emptyList();
            }
        } else {
            typesToCheck = Collections.singletonList(property._genericType()._rawType());
        }
        org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity multiplicityToCheck = pm._explodeProperty() != null && pm._explodeProperty() ? this.context.pureModel.getMultiplicity("zeromany") : property._multiplicity();
        List<ValueSpecification> lines = ((PurePropertyMapping) classMapping.propertyMappings.get(i)).transform.body;
        typesToCheck.stream().filter(Objects::nonNull).forEach(t -> HelperModelBuilder.checkTypeCompatibility(this.context, last._genericType()._rawType(), t, "Error in class mapping '" + HelperModelBuilder.getElementFullPath(parentMapping, this.context.pureModel.getExecutionSupport()) + "' for property '" + pm._property()._name() + "'", lines.get(lines.size() - 1).sourceInformation));
        HelperModelBuilder.checkMultiplicityCompatibility(last._multiplicity(), multiplicityToCheck, "Error in class mapping '" + HelperModelBuilder.getElementFullPath(parentMapping, this.context.pureModel.getExecutionSupport()) + "' for property '" + pm._property()._name() + "'", lines.get(lines.size() - 1).sourceInformation);
    }));
    return s;
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) EnumValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) 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) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) 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) PurePropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.PurePropertyMapping) PurePropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.PurePropertyMapping) InstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation) OperationSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.OperationSetImplementation) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)

Example 3 with EnumValue

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.

the class GraphFetchTreeParseTreeWalker method visitScalarParameterContext.

private ValueSpecification visitScalarParameterContext(GraphFetchTreeParserGrammar.ScalarParameterContext scalarParameterContext) {
    if (scalarParameterContext.enumReference() != null) {
        EnumValue result = new EnumValue();
        result.sourceInformation = walkerSourceInformation.getSourceInformation(scalarParameterContext.enumReference());
        result.fullPath = PureGrammarParserUtility.fromQualifiedName(scalarParameterContext.enumReference().qualifiedName().packagePath() == null ? Collections.emptyList() : scalarParameterContext.enumReference().qualifiedName().packagePath().identifier(), scalarParameterContext.enumReference().qualifiedName().identifier());
        result.value = PureGrammarParserUtility.fromIdentifier(scalarParameterContext.enumReference().identifier());
        return result;
    }
    if (scalarParameterContext.variable() != null) {
        Variable ve = new Variable();
        ve.sourceInformation = walkerSourceInformation.getSourceInformation(scalarParameterContext.variable().identifier());
        ve.name = PureGrammarParserUtility.fromIdentifier(scalarParameterContext.variable().identifier());
        return ve;
    }
    return instanceLiteralToken(scalarParameterContext.instanceLiteral().instanceLiteralToken());
}
Also used : Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) EnumValue(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue)

Example 4 with EnumValue

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.

the class DomainParseTreeWalker method visitEnumValue.

private EnumValue visitEnumValue(DomainParserGrammar.EnumValueContext ctx) {
    EnumValue enumValue = new EnumValue();
    enumValue.value = PureGrammarParserUtility.fromIdentifier(ctx.identifier());
    enumValue.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    enumValue.stereotypes = ctx.stereotypes() == null ? Lists.mutable.empty() : this.visitStereotypes(ctx.stereotypes());
    enumValue.taggedValues = ctx.taggedValues() == null ? Lists.mutable.empty() : this.visitTaggedValues(ctx.taggedValues());
    return enumValue;
}
Also used : EnumValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.EnumValue)

Example 5 with EnumValue

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.

the class HelperValueSpecificationBuilder method processProperty.

public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification processProperty(CompileContext context, MutableList<String> openVariables, ProcessingContext processingContext, List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> parameters, String property, SourceInformation sourceInformation) {
    // for X.property. X is the first parameter
    processingContext.push("Processing property " + property);
    org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification firstArgument = parameters.get(0);
    MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> processedParameters = ListIterate.collect(parameters, p -> p.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)));
    org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType genericType;
    org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity multiplicity;
    org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification inferredVariable;
    org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification result;
    if (// Only for backward compatibility!
    firstArgument instanceof org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Enum || (processedParameters.get(0)._genericType()._rawType().equals(context.pureModel.getType("meta::pure::metamodel::type::Enumeration")))) {
        org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity();
        m.lowerBound = 1;
        m.setUpperBound(1);
        CString enumValue = new CString();
        enumValue.values = Lists.mutable.of(property);
        enumValue.multiplicity = m;
        // validation to make sure the enum value can be found
        context.resolveEnumValue(((PackageableElementPtr) firstArgument).fullPath, enumValue.values.get(0), firstArgument.sourceInformation, sourceInformation);
        AppliedFunction extractEnum = new AppliedFunction();
        extractEnum.function = "extractEnumValue";
        extractEnum.parameters = Lists.mutable.of(firstArgument, enumValue);
        result = extractEnum.accept(new ValueSpecificationBuilder(context, openVariables, processingContext));
    } else {
        if (firstArgument instanceof Variable) {
            inferredVariable = processingContext.getInferredVariable(((Variable) firstArgument).name);
        } else {
            inferredVariable = processedParameters.get(0);
        }
        Type inferredType = inferredVariable._genericType()._rawType();
        if (// is an enum
        !(inferredType instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)) {
            inferredType = context.pureModel.getType("meta::pure::metamodel::type::Enum");
        }
        org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty<?> foundProperty = findProperty(context, (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) inferredType, parameters, property, sourceInformation);
        if (foundProperty instanceof Property) {
            genericType = (foundProperty._classifierGenericType()._typeArguments()).getLast();
            multiplicity = foundProperty._multiplicity();
        } else if (foundProperty instanceof QualifiedProperty) {
            FunctionType fType = (FunctionType) foundProperty._classifierGenericType()._typeArguments().getFirst()._rawType();
            genericType = fType._returnType();
            multiplicity = fType._returnMultiplicity();
        } else {
            throw new UnsupportedOperationException("Unhandled property: " + foundProperty);
        }
        if (// autoMap
        !inferredVariable._multiplicity().getName().equals("PureOne")) {
            processingContext.push("Building Automap for  " + property);
            org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity();
            m.lowerBound = 1;
            m.setUpperBound(1);
            List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> localParameters = Lists.mutable.ofAll(parameters);
            final String automapName = "v_automap";
            Lambda automapLambda = new Lambda();
            AppliedProperty appliedProperty = new AppliedProperty();
            appliedProperty.property = property;
            Variable automapvar = new Variable();
            Variable automaLambdaparam = new Variable();
            automapvar.name = automapName;
            appliedProperty.parameters = Lists.mutable.of(automapvar);
            if (!localParameters.isEmpty()) {
                localParameters.remove(0);
            }
            appliedProperty.parameters.addAll(localParameters);
            automaLambdaparam.name = automapName;
            automaLambdaparam._class = HelperModelBuilder.getElementFullPath(inferredVariable._genericType()._rawType(), context.pureModel.getExecutionSupport());
            automaLambdaparam.multiplicity = m;
            automapLambda.body = Lists.mutable.of(appliedProperty);
            List<Variable> lambdaParams = new FastList<>();
            lambdaParams.add(automaLambdaparam);
            automapLambda.parameters = lambdaParams;
            List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> newParams = Lists.mutable.of(parameters.get(0), automapLambda);
            result = context.buildFunctionExpression("map", null, newParams, openVariables, null, processingContext).getOne();
            processingContext.pop();
        } else {
            result = new Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl("")._func(foundProperty)._propertyName(new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("")._values(Lists.fixedSize.of(foundProperty.getName())))._genericType(genericType)._multiplicity(multiplicity)._parametersValues(processedParameters);
        }
    }
    processingContext.pop();
    return result;
}
Also used : ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) FastList(org.eclipse.collections.impl.list.mutable.FastList) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) 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) AppliedProperty(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) 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) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) AppliedProperty(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty)

Aggregations

EnumValue (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue)4 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)2 Variable (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable)2 CString (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)2 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Collector (java.util.stream.Collector)1 Collectors (java.util.stream.Collectors)1 FastList (org.eclipse.collections.impl.list.mutable.FastList)1 GraphFetchCache (org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCache)1 GraphFetchCacheByEqualityKeys (org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheByEqualityKeys)1 GraphFetchCacheKey (org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheKey)1 SQLExecutionResult (org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult)1