Search in sources :

Example 1 with CBoolean

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

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

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

the class PureCollectionDataParseTreeWalker method visitInstanceLiteral.

private ValueSpecification visitInstanceLiteral(PureCollectionDataParserGrammar.InstanceLiteralContext ctx) {
    ValueSpecification result;
    if (ctx.instanceLiteralToken() != null) {
        PureCollectionDataParserGrammar.InstanceLiteralTokenContext literalToken = ctx.instanceLiteralToken();
        if (literalToken.STRING() != null) {
            result = cString(PureGrammarParserUtility.fromGrammarString(literalToken.STRING().getText(), true));
        } else if (literalToken.INTEGER() != null) {
            result = cInteger(Long.parseLong(literalToken.INTEGER().getText()));
        } else if (literalToken.FLOAT() != null) {
            result = cFloat(Double.parseDouble(literalToken.FLOAT().getText()));
        } else if (literalToken.DECIMAL() != null) {
            String text = literalToken.DECIMAL().getText();
            result = cDecimal(new BigDecimal(text.substring(0, text.length() - 1)));
        } else if (literalToken.DATE() != null) {
            result = new DateParseTreeWalker(literalToken.DATE(), this.walkerSourceInformation).visitDefinition();
        } else if (literalToken.BOOLEAN() != null) {
            result = cBoolean(Boolean.parseBoolean(literalToken.BOOLEAN().getText()));
        } else if (literalToken.STRICTTIME() != null) {
            result = new StrictTimeParseTreeWalker(literalToken.STRICTTIME(), this.walkerSourceInformation).visitStrictTimeDefinition();
        } else {
            throw new IllegalStateException("Unhandled instanceLiteralToken");
        }
    } else if (ctx.INTEGER() != null && ctx.MINUS() != null) {
        result = cInteger(Long.parseLong(ctx.MINUS().getText() + ctx.INTEGER().getText()));
    } else if (ctx.FLOAT() != null && ctx.MINUS() != null) {
        result = cFloat(Double.parseDouble(ctx.MINUS().getText() + ctx.FLOAT().getText()));
    } else if (ctx.DECIMAL() != null && ctx.MINUS() != null) {
        String text = ctx.MINUS().getText() + ctx.DECIMAL().getText();
        result = cDecimal(new BigDecimal(text.substring(0, text.length() - 1)));
    } else if (ctx.INTEGER() != null && ctx.PLUS() != null) {
        result = cInteger(Long.parseLong(ctx.PLUS().getText() + ctx.INTEGER().getText()));
    } else if (ctx.FLOAT() != null && ctx.PLUS() != null) {
        result = cFloat(Double.parseDouble(ctx.PLUS().getText() + ctx.FLOAT().getText()));
    } else if (ctx.DECIMAL() != null && ctx.PLUS() != null) {
        String text = ctx.PLUS().getText() + ctx.DECIMAL().getText();
        result = cDecimal(new BigDecimal(text.substring(0, text.length() - 1)));
    } else {
        throw new IllegalStateException("Unhandled instanceLiteral");
    }
    result.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    return result;
}
Also used : StrictTimeParseTreeWalker(org.finos.legend.engine.language.pure.grammar.from.domain.StrictTimeParseTreeWalker) PureCollectionDataParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.data.embedded.pureCollection.PureCollectionDataParserGrammar) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) BigDecimal(java.math.BigDecimal) DateParseTreeWalker(org.finos.legend.engine.language.pure.grammar.from.domain.DateParseTreeWalker)

Example 4 with CBoolean

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

the class DomainParseTreeWalker method instanceLiteralToken.

private ValueSpecification instanceLiteralToken(DomainParserGrammar.InstanceLiteralTokenContext ctx, boolean wrapFlag) {
    ValueSpecification result;
    try {
        Multiplicity m = this.getMultiplicityOneOne();
        if (ctx.STRING() != null) {
            CString instance = getInstanceString(ctx.getText());
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else if (ctx.INTEGER() != null) {
            CInteger instance = getInstanceInteger(ctx.getText());
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else if (ctx.FLOAT() != null) {
            CFloat instance = getInstanceFloat(ctx.getText());
            instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
            result = instance;
        } else // }
        if (ctx.DATE() != null) {
            result = new DateParseTreeWalker(ctx.DATE(), this.walkerSourceInformation).visitDefinition();
        } else if (ctx.STRICTTIME() != null) {
            result = new StrictTimeParseTreeWalker(ctx.STRICTTIME(), this.walkerSourceInformation).visitStrictTimeDefinition();
        } 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 {
            throw new RuntimeException("TODO");
        }
    } catch (Exception e) {
        throw new EngineException(ctx.getText() + " is not supported", walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
    }
    return result;
}
Also used : 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) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) 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) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList)

Example 5 with CBoolean

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

the class NavigationParseTreeWalker method visitAtomicExpression.

private ValueSpecification visitAtomicExpression(NavigationParserGrammar.AtomicContext ctx) {
    if (ctx.BOOLEAN() != null) {
        CBoolean instance = new CBoolean();
        List<Boolean> values = new ArrayList<>();
        values.add(Boolean.parseBoolean(ctx.getText()));
        instance.multiplicity = this.getMultiplicityOneOne();
        instance.values = values;
        instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
        return instance;
    } else if (ctx.STRING() != null) {
        CString instance = getInstanceString(ctx.getText());
        instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
        return instance;
    } else if (ctx.INTEGER() != null) {
        CInteger instance = getInstanceInteger(ctx.getText());
        instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
        return instance;
    } else if (ctx.FLOAT() != null) {
        CFloat instance = new CFloat();
        instance.multiplicity = this.getMultiplicityOneOne();
        instance.values = Lists.mutable.with(Double.parseDouble(ctx.getText()));
        instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
        return instance;
    } else if (ctx.DATE() != null) {
        CDateTime instance = new CDateTime();
        instance.multiplicity = this.getMultiplicityOneOne();
        String var = ctx.getText();
        instance.values = Lists.mutable.with(var.substring(var.lastIndexOf('%') + 1));
        instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
        return instance;
    } else if (ctx.LATEST_DATE() != null) {
        CLatestDate instance = new CLatestDate();
        instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
        instance.multiplicity = getMultiplicityOneOne();
        return instance;
    }
    throw new EngineException("Unsupported scalar expression for property path: " + ctx.getText());
}
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) CInteger(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CInteger) ArrayList(java.util.ArrayList) CFloat(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CFloat) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) CBoolean(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CBoolean) CLatestDate(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CLatestDate) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)

Aggregations

ArrayList (java.util.ArrayList)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 CInteger (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CInteger)4 CString (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)4 List (java.util.List)3 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)3 CDateTime (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime)3 Collectors (java.util.stream.Collectors)2 Multiplicity (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity)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 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1