Search in sources :

Example 1 with CString

use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString 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 CString

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

the class ValueSpecificationBuilder method visit.

@Override
public ValueSpecification visit(AppliedFunction appliedFunction) {
    processingContext.push("Applying " + appliedFunction.function);
    if (appliedFunction.function.equals("letFunction")) {
        MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> vs = ListIterate.collect(appliedFunction.parameters, expression -> expression.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)));
        String letName = ((CString) appliedFunction.parameters.get(0)).values.get(0);
        org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification ve = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("")._name(letName);
        ve._genericType(vs.get(1)._genericType());
        ve._multiplicity(vs.get(1)._multiplicity());
        processingContext.addInferredVariables(letName, ve);
    }
    org.eclipse.collections.api.tuple.Pair<SimpleFunctionExpression, List<ValueSpecification>> func = this.context.buildFunctionExpression(appliedFunction.function, appliedFunction.fControl, appliedFunction.parameters, openVariables, appliedFunction.sourceInformation, processingContext);
    processingContext.pop();
    Assert.assertTrue(func != null, () -> "Can't find a match for function '" + appliedFunction.function + "(?)'", appliedFunction.sourceInformation, EngineErrorType.COMPILATION);
    Assert.assertTrue(func.getOne() != null, () -> "Can't find a match for function '" + appliedFunction.function + "(" + (func.getTwo() == null ? "?" : LazyIterate.collect(func.getTwo(), v -> (v._genericType() == null ? "?" : v._genericType()._rawType()._name()) + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(v._multiplicity())).makeString(",")) + ")'", appliedFunction.sourceInformation, EngineErrorType.COMPILATION);
    ValueSpecification result = func.getOne();
    result.setSourceInformation(SourceInformationHelper.toM3SourceInformation(appliedFunction.sourceInformation));
    return result;
}
Also used : ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) PureList(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PureList) FastList(org.eclipse.collections.impl.list.mutable.FastList) Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl)

Example 3 with CString

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

the class GraphFetchTreeParseTreeWalker method instanceLiteralToken.

private ValueSpecification instanceLiteralToken(GraphFetchTreeParserGrammar.InstanceLiteralTokenContext ctx) {
    ValueSpecification result;
    try {
        Multiplicity m = this.getPureOne();
        if (ctx.STRING() != null) {
            List<String> values = new ArrayList<>();
            values.add(PureGrammarParserUtility.fromGrammarString(ctx.getText(), true));
            CString instance = new CString();
            instance.multiplicity = m;
            instance.values = values;
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else if (ctx.INTEGER() != null) {
            List<Long> values = new ArrayList<>();
            values.add(Long.parseLong(ctx.getText()));
            CInteger instance = new CInteger();
            instance.multiplicity = m;
            instance.values = values;
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else if (ctx.FLOAT() != null) {
            List<Double> values = new ArrayList<>();
            values.add(Double.parseDouble(ctx.getText()));
            CFloat instance = new CFloat();
            instance.multiplicity = m;
            instance.values = values;
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else if (ctx.DATE() != null) {
            List<String> values = new ArrayList<>();
            // Likely wrong
            values.add(ctx.getText());
            CDateTime instance = new CDateTime();
            instance.multiplicity = this.getPureOne();
            instance.values = values.stream().map(value -> value.substring(value.lastIndexOf('%') + 1)).collect(Collectors.toList());
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else if (ctx.BOOLEAN() != null) {
            List<Boolean> values = new ArrayList<>();
            values.add(Boolean.parseBoolean(ctx.getText()));
            CBoolean instance = new CBoolean();
            instance.multiplicity = m;
            instance.values = values;
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else {
            // TODO
            throw new UnsupportedOperationException();
        }
    } catch (Exception e) {
        throw new UnsupportedOperationException(ctx.getText());
    }
    return result;
}
Also used : CDateTime(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime) CBoolean(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CBoolean) RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) CDateTime(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation) 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) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) Collection(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) GraphFetchTreeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.graphFetchTree.GraphFetchTreeParserGrammar) List(java.util.List) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) GraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.GraphFetchTree) CFloat(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CFloat) PureGrammarParserUtility(org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserUtility) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) Collections(java.util.Collections) CInteger(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CInteger) CBoolean(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CBoolean) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) ArrayList(java.util.ArrayList) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) CFloat(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CFloat) ArrayList(java.util.ArrayList) List(java.util.List) CBoolean(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CBoolean)

Example 4 with CString

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

the class DomainParseTreeWalker method expression.

private ValueSpecification expression(DomainParserGrammar.ExpressionContext ctx, String exprName, List<String> typeParametersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, boolean addLines) {
    ValueSpecification result;
    List<ValueSpecification> expressions = Lists.mutable.of();
    List<ValueSpecification> parameters;
    if (ctx.combinedExpression() != null) {
        return this.combinedExpression(ctx.combinedExpression(), exprName, typeParametersNames, lambdaContext, space, wrapFlag, addLines);
    }
    if (ctx.atomicExpression() != null) {
        result = this.atomicExpression(ctx.atomicExpression(), typeParametersNames, lambdaContext, space, wrapFlag, addLines);
    } else if (ctx.notExpression() != null) {
        result = this.notExpression(ctx.notExpression(), exprName, typeParametersNames, lambdaContext, space, addLines);
    } else if (ctx.signedExpression() != null) {
        result = this.signedExpression(ctx.signedExpression(), exprName, typeParametersNames, lambdaContext, space, addLines);
    } else if (ctx.expressionsArray() != null) {
        for (DomainParserGrammar.ExpressionContext eCtx : ctx.expressionsArray().expression()) {
            expressions.add(this.expression(eCtx, exprName, typeParametersNames, lambdaContext, space, false, addLines));
        }
        result = this.collect(expressions, walkerSourceInformation.getSourceInformation(ctx));
    } else {
        throw new EngineException(ctx.getText() + " is not supported", walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
    }
    if (ctx.propertyOrFunctionExpression() != null) {
        for (DomainParserGrammar.PropertyOrFunctionExpressionContext pfCtx : ctx.propertyOrFunctionExpression()) {
            if (pfCtx.propertyExpression() != null) {
                result = propertyExpression(pfCtx.propertyExpression(), result, typeParametersNames, lambdaContext, space, addLines);
            } else // TODO PropertyBracketExpression is deprecated.  Remove else if clause once all use has been addressed
            if (pfCtx.propertyBracketExpression() != null) {
                if (!allowPropertyBracketExpression) {
                    throw new EngineException("Bracket operation is not supported", walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression()), EngineErrorType.PARSER);
                }
                String getPropertyName = "oneString";
                parameters = new ArrayList<>();
                AppliedProperty appliedProperty = new AppliedProperty();
                appliedProperty.property = getPropertyName;
                appliedProperty.parameters = Lists.mutable.of(result).withAll(parameters);
                if (pfCtx.propertyBracketExpression().STRING() != null) {
                    CString instance = getInstanceString(pfCtx.propertyBracketExpression().STRING().getText());
                    instance.sourceInformation = walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression());
                    appliedProperty.parameters.add(instance);
                } else {
                    CInteger instance = getInstanceInteger(pfCtx.propertyBracketExpression().INTEGER().getText());
                    instance.sourceInformation = walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression());
                    appliedProperty.parameters.add(instance);
                }
                appliedProperty.sourceInformation = walkerSourceInformation.getSourceInformation(pfCtx.propertyBracketExpression());
                result = appliedProperty;
            } else {
                for (int i = 0; i < pfCtx.functionExpression().qualifiedName().size(); i++) {
                    parameters = this.functionExpressionParameters(pfCtx.functionExpression().functionExpressionParameters(i), typeParametersNames, lambdaContext, addLines, space);
                    parameters.add(0, result);
                    result = this.functionExpression(pfCtx.functionExpression().qualifiedName(i), parameters);
                }
            }
        }
    }
    if (ctx.equalNotEqual() != null) {
        result = this.equalNotEqual(ctx.equalNotEqual(), result, exprName, typeParametersNames, lambdaContext, space, wrapFlag, addLines);
    }
    return result;
}
Also used : DomainParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.domain.DomainParserGrammar) CInteger(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CInteger) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) ArrayList(java.util.ArrayList) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) AppliedProperty(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)

Example 5 with CString

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

the class DomainParseTreeWalker method letExpression.

private AppliedFunction letExpression(DomainParserGrammar.LetExpressionContext ctx, List<String> typeParametersNames, LambdaContext lambdaContext, boolean addLines, String space) {
    ValueSpecification result = this.combinedExpression(ctx.combinedExpression(), "", typeParametersNames, lambdaContext, space, true, addLines);
    result.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    CString cString = new CString();
    List<String> values = new ArrayList<>();
    values.add(PureGrammarParserUtility.fromIdentifier(ctx.identifier()));
    cString.multiplicity = this.getMultiplicityOneOne();
    cString.values = values;
    AppliedFunction appliedFunction = this.createAppliedFunction(Lists.mutable.of(cString, result), "letFunction");
    appliedFunction.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    return appliedFunction;
}
Also used : ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) ArrayList(java.util.ArrayList) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)

Aggregations

CString (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)12 ArrayList (java.util.ArrayList)8 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)7 CInteger (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CInteger)5 List (java.util.List)4 CBoolean (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CBoolean)4 CFloat (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CFloat)4 FastList (org.eclipse.collections.impl.list.mutable.FastList)3 Multiplicity (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity)3 AppliedFunction (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction)3 CDateTime (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime)3 Collectors (java.util.stream.Collectors)2 MutableList (org.eclipse.collections.api.list.MutableList)2 Variable (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable)2 AppliedProperty (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty)2 Collection (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection)2 EnumValue (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue)2 GraphFetchTree (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.GraphFetchTree)2 PropertyGraphFetchTree (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree)2 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)2