Search in sources :

Example 1 with GraphFetchTree

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

the class RelationalExecutionNodeExecutor method executeRelationalCrossRootQueryTempTableGraphFetchExecutionNode.

private Result executeRelationalCrossRootQueryTempTableGraphFetchExecutionNode(RelationalCrossRootQueryTempTableGraphFetchExecutionNode node) {
    boolean isLeaf = node.children == null || node.children.isEmpty();
    List<Object> childObjects = new ArrayList<>();
    Result childResult = null;
    RelationalStoreExecutionState relationalStoreExecutionState = (RelationalStoreExecutionState) this.executionState.getStoreExecutionState(StoreType.Relational);
    BlockConnectionContext oldBlockConnectionContext = relationalStoreExecutionState.getBlockConnectionContext();
    boolean oldRetainConnectionFlag = relationalStoreExecutionState.retainConnection();
    relationalStoreExecutionState.setBlockConnectionContext(new BlockConnectionContext());
    relationalStoreExecutionState.setRetainConnection(true);
    try (Scope ignored = GlobalTracer.get().buildSpan("cross store property graph fetch").withTag("storeType", "relational").withTag("property", ((PropertyGraphFetchTree) node.graphFetchTree).property).startActive(true)) {
        IRelationalCrossRootQueryTempTableGraphFetchExecutionNodeSpecifics nodeSpecifics = ExecutionNodeJavaPlatformHelper.getNodeSpecificsInstance(node, this.executionState, this.profiles);
        RelationalGraphObjectsBatch relationalGraphObjectsBatch = new RelationalGraphObjectsBatch(this.executionState.graphObjectsBatch);
        List<?> parentObjects = relationalGraphObjectsBatch.getObjectsForNodeIndex(node.parentIndex);
        if ((parentObjects != null) && !parentObjects.isEmpty()) {
            GraphFetchTree nodeSubTree = node.graphFetchTree;
            boolean cachingEnabled = false;
            ExecutionCache<GraphFetchCacheKey, List<Object>> crossCache = relationalGraphObjectsBatch.getXStorePropertyCacheForNodeIndex(node.nodeIndex);
            List<Method> parentCrossKeyGettersOrderedPerTargetProperties = null;
            if (crossCache != null) {
                cachingEnabled = true;
                parentCrossKeyGettersOrderedPerTargetProperties = nodeSpecifics.parentCrossKeyGettersOrderedByTargetProperties();
            }
            List<Object> parentsToDeepFetch = new ArrayList<>();
            for (Object parent : parentObjects) {
                if (cachingEnabled) {
                    List<Object> children = crossCache.getIfPresent(new RelationalGraphFetchUtils.RelationalCrossObjectGraphFetchCacheKey(parent, parentCrossKeyGettersOrderedPerTargetProperties));
                    if (children == null) {
                        parentsToDeepFetch.add(parent);
                    } else {
                        for (Object child : children) {
                            childObjects.add(child);
                            nodeSpecifics.addChildToParent(parent, child, DefaultExecutionNodeContext.factory().create(this.executionState, null));
                        }
                    }
                } else {
                    parentsToDeepFetch.add(parent);
                }
            }
            if (!parentsToDeepFetch.isEmpty()) {
                Map<Object, List<Object>> parentToChildMap = new HashMap<>();
                RealizedRelationalResult parentRealizedRelationalResult = RealizedRelationalResult.emptyRealizedRelationalResult(node.parentTempTableColumns);
                List<Method> crossKeyGetters = nodeSpecifics.parentCrossKeyGetters();
                for (Object parentObject : parentsToDeepFetch) {
                    this.addKeyRowToRealizedRelationalResult(parentObject, crossKeyGetters, parentRealizedRelationalResult);
                    parentToChildMap.put(parentObject, new ArrayList<>());
                }
                this.executionState.addResult(node.parentTempTableName, parentRealizedRelationalResult);
                childResult = node.executionNodes.get(0).accept(new ExecutionNodeExecutor(this.profiles, this.executionState));
                SQLExecutionResult childSqlResult = (SQLExecutionResult) childResult;
                DatabaseConnection databaseConnection = childSqlResult.getSQLExecutionNode().connection;
                ResultSet childResultSet = childSqlResult.getResultSet();
                List<String> parentSQLKeyColumns = nodeSpecifics.parentCrossKeyColumns(childSqlResult.getResultColumns().stream().map(ResultColumn::getNonQuotedLabel).collect(Collectors.toList()));
                List<Integer> parentCrossKeyIndices = parentSQLKeyColumns.stream().map(FunctionHelper.unchecked(childResultSet::findColumn)).collect(Collectors.toList());
                @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") DoubleStrategyHashMap<Object, List<Object>, SQLExecutionResult> parentMap = new DoubleStrategyHashMap<>(RelationalGraphFetchUtils.objectSQLResultDoubleHashStrategy(crossKeyGetters, parentCrossKeyIndices));
                parentsToDeepFetch.forEach((o) -> parentMap.getIfAbsentPut(o, ArrayList::new).add(o));
                RealizedRelationalResult realizedRelationalResult = RealizedRelationalResult.emptyRealizedRelationalResult(node.columns);
                List<Method> primaryKeyGetters = nodeSpecifics.primaryKeyGetters();
                DoubleStrategyHashMap<Object, Object, SQLExecutionResult> currentMap = new DoubleStrategyHashMap<>(RelationalGraphFetchUtils.objectSQLResultDoubleHashStrategyWithEmptySecondStrategy(primaryKeyGetters));
                /* Prepare for reading */
                nodeSpecifics.prepare(childResultSet, childSqlResult.getDatabaseTimeZone(), ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports().writeValueAsString(databaseConnection));
                while (childResultSet.next()) {
                    relationalGraphObjectsBatch.incrementRowCount();
                    List<Object> parents = parentMap.getWithSecondKey(childSqlResult);
                    if (parents == null) {
                        throw new RuntimeException("Cannot find the parent for child");
                    }
                    IGraphInstance<? extends IReferencedObject> childGraphInstance = nodeSpecifics.nextGraphInstance();
                    Object child = childGraphInstance.getValue();
                    Object mapObject = currentMap.putIfAbsent(child, child);
                    if (mapObject == null) {
                        mapObject = child;
                        childObjects.add(mapObject);
                        relationalGraphObjectsBatch.addObjectMemoryUtilization(childGraphInstance.instanceSize());
                        if (!isLeaf) {
                            this.addKeyRowToRealizedRelationalResult(child, primaryKeyGetters, realizedRelationalResult);
                        }
                    }
                    for (Object parent : parents) {
                        if (parentToChildMap.containsKey(parent)) {
                            parentToChildMap.get(parent).add(mapObject);
                        } else {
                            parentToChildMap.put(parent, new ArrayList<>());
                            parentToChildMap.get(parent).add(mapObject);
                        }
                        nodeSpecifics.addChildToParent(parent, mapObject, DefaultExecutionNodeContext.factory().create(this.executionState, null));
                    }
                }
                relationalGraphObjectsBatch.setObjectsForNodeIndex(node.nodeIndex, childObjects);
                childResult.close();
                childResult = null;
                /* Execute store local children */
                if (!isLeaf) {
                    ExecutionState newState = new ExecutionState(executionState);
                    newState.graphObjectsBatch = relationalGraphObjectsBatch;
                    this.executeTempTableNodeChildren(node, realizedRelationalResult, databaseConnection, childSqlResult.getDatabaseType(), childSqlResult.getDatabaseTimeZone(), currentMap, primaryKeyGetters, newState);
                }
                if (cachingEnabled) {
                    List<Method> getters = parentCrossKeyGettersOrderedPerTargetProperties;
                    parentToChildMap.forEach((p, cs) -> {
                        crossCache.put(new RelationalGraphFetchUtils.RelationalCrossObjectGraphFetchCacheKey(p, getters), cs);
                    });
                }
            }
        }
        return new ConstantResult(childObjects);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (childResult != null) {
            childResult.close();
        }
        relationalStoreExecutionState.getBlockConnectionContext().unlockAllBlockConnections();
        relationalStoreExecutionState.getBlockConnectionContext().closeAllBlockConnectionsAsync();
        relationalStoreExecutionState.setBlockConnectionContext(oldBlockConnectionContext);
        relationalStoreExecutionState.setRetainConnection(oldRetainConnectionFlag);
    }
}
Also used : PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) GraphExecutionState(org.finos.legend.engine.plan.execution.nodes.state.GraphExecutionState) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalGraphObjectsBatch(org.finos.legend.engine.plan.execution.stores.relational.result.graphFetch.RelationalGraphObjectsBatch) DoubleStrategyHashMap(org.finos.legend.engine.shared.core.collectionsExtensions.DoubleStrategyHashMap) ExecutionNodeExecutor(org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) IRelationalResult(org.finos.legend.engine.plan.dependencies.store.relational.IRelationalResult) TempTableStreamingResult(org.finos.legend.engine.plan.execution.stores.relational.result.TempTableStreamingResult) PreparedTempTableResult(org.finos.legend.engine.plan.execution.stores.relational.result.PreparedTempTableResult) SQLExecutionResult(org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult) GraphFetchResult(org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) RealizedRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RealizedRelationalResult) Result(org.finos.legend.engine.plan.execution.result.Result) BlockConnectionContext(org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnectionContext) ResultSet(java.sql.ResultSet) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) RealizedRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RealizedRelationalResult) ResultColumn(org.finos.legend.engine.plan.execution.stores.relational.result.ResultColumn) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) DoubleStrategyHashMap(org.finos.legend.engine.shared.core.collectionsExtensions.DoubleStrategyHashMap) GraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.GraphFetchTree) RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) GraphFetchCacheKey(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheKey) Scope(io.opentracing.Scope) IReferencedObject(org.finos.legend.engine.plan.dependencies.store.shared.IReferencedObject) SQLExecutionResult(org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult)

Example 2 with GraphFetchTree

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

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

the class HelperValueSpecificationBuilder method buildPropertyGraphFetchTree.

private static GraphFetchTree buildPropertyGraphFetchTree(PropertyGraphFetchTree propertyGraphFetchTree, CompileContext context, Class<?> parentClass, MutableList<String> openVariables, ProcessingContext processingContext) {
    AbstractProperty<?> property;
    MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> pureParameters = Lists.mutable.empty();
    if (!propertyGraphFetchTree.parameters.isEmpty()) {
        Variable thisVariable = new Variable("this", HelperModelBuilder.getElementFullPath(parentClass, context.pureModel.getExecutionSupport()), new Multiplicity(1, 1));
        property = HelperModelBuilder.getAppliedProperty(context, parentClass, Optional.of(Lists.mutable.<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification>with(thisVariable).withAll(propertyGraphFetchTree.parameters)), propertyGraphFetchTree.property);
        processingContext.push("PropertyTree");
        processingContext.addInferredVariables("this", HelperModelBuilder.createThisVariableForClass(context, HelperModelBuilder.getElementFullPath(parentClass, context.pureModel.getExecutionSupport())));
        pureParameters = ListIterate.collect(propertyGraphFetchTree.parameters, x -> x.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)));
        processingContext.flushVariable("this");
        processingContext.pop();
    } else {
        property = HelperModelBuilder.getAppliedProperty(context, parentClass, Optional.empty(), propertyGraphFetchTree.property, propertyGraphFetchTree.sourceInformation);
    }
    Class<?> subType = propertyGraphFetchTree.subType == null ? null : context.resolveClass(propertyGraphFetchTree.subType, propertyGraphFetchTree.sourceInformation);
    Type returnType = subType == null ? property._genericType()._rawType() : subType;
    ListIterable<GraphFetchTree> children = ListIterate.collect(propertyGraphFetchTree.subTrees, subTree -> buildGraphFetchTree(subTree, context, (Class<?>) returnType, openVariables, processingContext));
    return new Root_meta_pure_graphFetch_PropertyGraphFetchTree_Impl("")._property(property)._parameters(pureParameters)._alias(propertyGraphFetchTree.alias)._subType(subType)._subTrees(children);
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) 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) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) PackageableElementPtr(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PackageableElementPtr) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) BaseExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.BaseExecutionContext) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) AnalyticsExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.AnalyticsExecutionContext) AppliedProperty(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedProperty) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) Objects(java.util.Objects) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) org.finos.legend.pure.generated(org.finos.legend.pure.generated) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) List(java.util.List) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Lists(org.eclipse.collections.impl.factory.Lists) ExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.executionContext.ExecutionContext) VariableExpressionAccessor(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpressionAccessor) ListIterable(org.eclipse.collections.api.list.ListIterable) Optional(java.util.Optional) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) GraphFetchTree(org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree) 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) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)

Example 4 with GraphFetchTree

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

the class RelationalGraphFetchUtils method findCacheByEqualityKeys.

static GraphFetchCacheByEqualityKeys findCacheByEqualityKeys(GraphFetchTree graphFetchTree, String mappingId, String instanceSetId, List<GraphFetchCache> graphFetchCaches) {
    if (!subTreeValidForCaching(graphFetchTree)) {
        return null;
    }
    String subTree = getSubTreeString(graphFetchTree);
    GraphFetchCacheByEqualityKeys matchingUtilizedCache = null;
    for (GraphFetchCache c : graphFetchCaches) {
        if (c instanceof GraphFetchCacheByEqualityKeys) {
            GraphFetchCacheByEqualityKeys ce = (GraphFetchCacheByEqualityKeys) c;
            if (ce.isCacheUtilized() && mappingId.equals(ce.getMappingId()) && instanceSetId.equals(ce.getInstanceSetId()) && subTree.equals(ce.getSubTree())) {
                matchingUtilizedCache = ce;
                break;
            }
        }
    }
    if (matchingUtilizedCache == null) {
        GraphFetchCacheByEqualityKeys unUtilizedCache = null;
        for (GraphFetchCache c : graphFetchCaches) {
            if (c instanceof GraphFetchCacheByEqualityKeys) {
                GraphFetchCacheByEqualityKeys ce = (GraphFetchCacheByEqualityKeys) c;
                if (!ce.isCacheUtilized() && mappingId.equals(ce.getMappingId()) && instanceSetId.equals(ce.getInstanceSetId())) {
                    unUtilizedCache = ce;
                    break;
                }
            }
        }
        if (unUtilizedCache != null) {
            unUtilizedCache.setSubTree(subTree);
            return unUtilizedCache;
        }
        return null;
    }
    return matchingUtilizedCache;
}
Also used : GraphFetchCache(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCache) GraphFetchCacheByEqualityKeys(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheByEqualityKeys) CString(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)

Example 5 with GraphFetchTree

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

the class GraphFetchTreeParseTreeWalker method visitRootGraphDefinition.

private RootGraphFetchTree visitRootGraphDefinition(GraphFetchTreeParserGrammar.GraphDefinitionContext graphDefinitionContext, GraphFetchTreeParserGrammar.DefinitionContext definitionContext) {
    List<GraphFetchTree> subTrees = new ArrayList<>();
    for (GraphFetchTreeParserGrammar.GraphPathContext graphPathContext : graphDefinitionContext.graphPaths().graphPath()) {
        subTrees.add(this.visitGraphPathContext(graphPathContext));
    }
    RootGraphFetchTree result = new RootGraphFetchTree();
    result._class = PureGrammarParserUtility.fromQualifiedName(definitionContext.qualifiedName().packagePath() == null ? Collections.emptyList() : definitionContext.qualifiedName().packagePath().identifier(), definitionContext.qualifiedName().identifier());
    result.sourceInformation = walkerSourceInformation.getSourceInformation(definitionContext.qualifiedName());
    result.subTrees = subTrees;
    return result;
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) GraphFetchTreeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.graphFetchTree.GraphFetchTreeParserGrammar) ArrayList(java.util.ArrayList) RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) PropertyGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree) GraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.GraphFetchTree)

Aggregations

PropertyGraphFetchTree (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.PropertyGraphFetchTree)5 CString (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)4 GraphFetchTree (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.GraphFetchTree)4 RootGraphFetchTree (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree)4 ArrayList (java.util.ArrayList)3 Method (java.lang.reflect.Method)2 List (java.util.List)2 Objects (java.util.Objects)2 MutableList (org.eclipse.collections.api.list.MutableList)2 FastList (org.eclipse.collections.impl.list.mutable.FastList)2 GraphFetchTreeParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.graphFetchTree.GraphFetchTreeParserGrammar)2 GraphFetchCache (org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCache)2 GraphFetchCacheByEqualityKeys (org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheByEqualityKeys)2 GraphFetchCacheKey (org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheKey)2 SQLExecutionResult (org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult)2 DoubleStrategyHashMap (org.finos.legend.engine.shared.core.collectionsExtensions.DoubleStrategyHashMap)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Scope (io.opentracing.Scope)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1