Search in sources :

Example 1 with PartialClassBuilder

use of org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder in project legend-engine by finos.

the class ExecutionNodeExecutor method visit.

@Override
public Result visit(GlobalGraphFetchExecutionNode globalGraphFetchExecutionNode) {
    final Span topSpan = GlobalTracer.get().activeSpan();
    final boolean isGraphRoot = globalGraphFetchExecutionNode.parentIndex == null;
    if (isGraphRoot) {
        final boolean enableConstraints = globalGraphFetchExecutionNode.enableConstraints == null ? false : globalGraphFetchExecutionNode.enableConstraints;
        final boolean checked = globalGraphFetchExecutionNode.checked == null ? false : globalGraphFetchExecutionNode.checked;
        // Handle batching at root level
        final AtomicLong rowCount = new AtomicLong(0L);
        final AtomicLong objectCount = new AtomicLong(0L);
        final DoubleSummaryStatistics memoryStatistics = new DoubleSummaryStatistics();
        GraphFetchResult graphFetchResult = (GraphFetchResult) globalGraphFetchExecutionNode.localGraphFetchExecutionNode.accept(new ExecutionNodeExecutor(this.profiles, this.executionState));
        Stream<?> objectStream = graphFetchResult.getGraphObjectsBatchStream().map(batch -> {
            List<?> parentObjects = batch.getObjectsForNodeIndex(0);
            boolean nonEmptyObjectList = !parentObjects.isEmpty();
            ExecutionState newState = new ExecutionState(this.executionState).setGraphObjectsBatch(batch);
            if (globalGraphFetchExecutionNode.children != null && !globalGraphFetchExecutionNode.children.isEmpty() && nonEmptyObjectList) {
                globalGraphFetchExecutionNode.children.forEach(c -> c.accept(new ExecutionNodeExecutor(this.profiles, newState)));
            }
            rowCount.addAndGet(batch.getRowCount());
            if (nonEmptyObjectList) {
                long currentObjectCount = objectCount.addAndGet(parentObjects.size());
                memoryStatistics.accept(batch.getTotalObjectMemoryUtilization() / (parentObjects.size() * 1.0));
                if (graphFetchResult.getGraphFetchSpan() != null) {
                    Span graphFetchSpan = graphFetchResult.getGraphFetchSpan();
                    graphFetchSpan.setTag("batchCount", memoryStatistics.getCount());
                    graphFetchSpan.setTag("objectCount", currentObjectCount);
                    graphFetchSpan.setTag("avgMemoryUtilizationInBytesPerObject", memoryStatistics.getAverage());
                }
            }
            if (!nonEmptyObjectList) {
                if (topSpan != null && rowCount.get() > 0) {
                    topSpan.setTag("lastQueryRowCount", rowCount);
                }
            }
            if (checked) {
                return parentObjects.stream().map(x -> (IChecked<?>) x).map(x -> x.getValue() instanceof Constrained ? ((Constrained<?>) x.getValue()).toChecked(x.getSource(), enableConstraints) : x).collect(Collectors.toList());
            }
            if (enableConstraints) {
                return parentObjects.stream().map(x -> x instanceof Constrained ? ((Constrained<?>) x).withConstraintsApplied() : x).collect(Collectors.toList());
            }
            return parentObjects;
        }).flatMap(Collection::stream);
        boolean realizeAsConstant = this.executionState.inAllocation && ExecutionNodeResultHelper.isResultSizeRangeSet(globalGraphFetchExecutionNode) && ExecutionNodeResultHelper.isSingleRecordResult(globalGraphFetchExecutionNode);
        if (realizeAsConstant) {
            return new ConstantResult(objectStream.findFirst().orElseThrow(() -> new RuntimeException("Constant value not found")));
        }
        return new StreamingObjectResult<>(objectStream, new PartialClassBuilder(globalGraphFetchExecutionNode), graphFetchResult);
    } else {
        GraphObjectsBatch graphObjectsBatch = this.executionState.graphObjectsBatch;
        List<?> parentObjects = graphObjectsBatch.getObjectsForNodeIndex(globalGraphFetchExecutionNode.parentIndex);
        if ((parentObjects != null) && !parentObjects.isEmpty()) {
            if (globalGraphFetchExecutionNode.xStorePropertyFetchDetails != null && globalGraphFetchExecutionNode.xStorePropertyFetchDetails.supportsCaching && this.executionState.graphFetchCaches != null) {
                graphObjectsBatch.setXStorePropertyCachesForNodeIndex(globalGraphFetchExecutionNode.localGraphFetchExecutionNode.nodeIndex, findGraphFetchCacheByTargetCrossKeys(globalGraphFetchExecutionNode));
            }
            globalGraphFetchExecutionNode.localGraphFetchExecutionNode.accept(new ExecutionNodeExecutor(this.profiles, this.executionState));
            if (globalGraphFetchExecutionNode.children != null && !globalGraphFetchExecutionNode.children.isEmpty()) {
                globalGraphFetchExecutionNode.children.forEach(c -> c.accept(new ExecutionNodeExecutor(this.profiles, this.executionState)));
            }
        }
        return new ConstantResult(parentObjects);
    }
}
Also used : Maps(org.eclipse.collections.impl.factory.Maps) ExecutionNodeVisitor(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNodeVisitor) Arrays(java.util.Arrays) DefaultExecutionNodeContext(org.finos.legend.engine.plan.execution.nodes.helpers.platform.DefaultExecutionNodeContext) Spliterators(java.util.Spliterators) GraphFetchCacheKey(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheKey) ExecutionNodeSerializerHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeSerializerHelper) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) MutableList(org.eclipse.collections.api.list.MutableList) InMemoryCrossStoreGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryCrossStoreGraphFetchExecutionNode) ErrorExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ErrorExecutionNode) IPlatformPureExpressionExecutionNodeSerializeSpecifics(org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeSerializeSpecifics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StoreStreamReadingExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.StoreStreamReadingExecutionNode) Map(java.util.Map) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) ExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode) FunctionParametersValidationNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.FunctionParametersValidationNode) AppliedFunction(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction) AllocationExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AllocationExecutionNode) ConstantExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ConstantExecutionNode) Collection(java.util.Collection) GraphExecutionState(org.finos.legend.engine.plan.execution.nodes.state.GraphExecutionState) FunctionParametersParametersValidation(org.finos.legend.engine.plan.execution.validation.FunctionParametersParametersValidation) SerializationConfig(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.SerializationConfig) Collectors(java.util.stream.Collectors) Constrained(org.finos.legend.engine.plan.dependencies.domain.dataQuality.Constrained) IExecutionNodeContext(org.finos.legend.engine.plan.dependencies.store.shared.IExecutionNodeContext) Objects(java.util.Objects) InMemoryRootGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryRootGraphFetchExecutionNode) List(java.util.List) Stream(java.util.stream.Stream) Lists(org.eclipse.collections.impl.factory.Lists) Span(io.opentracing.Span) Scope(io.opentracing.Scope) FreeMarkerConditionalExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.FreeMarkerConditionalExecutionNode) Spliterator(java.util.Spliterator) FreeMarkerExecutor(org.finos.legend.engine.plan.execution.nodes.helpers.freemarker.FreeMarkerExecutor) IPlatformPureExpressionExecutionNodeGraphFetchUnionSpecifics(org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeGraphFetchUnionSpecifics) StoreType(org.finos.legend.engine.plan.execution.stores.StoreType) MultiResultSequenceExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.MultiResultSequenceExecutionNode) CommonProfile(org.pac4j.core.profile.CommonProfile) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) GraphFetchCache(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCache) AggregationAwareExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AggregationAwareExecutionNode) IPlatformPureExpressionExecutionNodeGraphFetchMergeSpecifics(org.finos.legend.engine.plan.dependencies.store.platform.IPlatformPureExpressionExecutionNodeGraphFetchMergeSpecifics) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) GraphFetchResult(org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult) GraphFetchM2MExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.GraphFetchM2MExecutionNode) ExecutionNodeResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeResultHelper) GraphFetchCrossAssociationKeys(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCrossAssociationKeys) ExecutionCache(org.finos.legend.engine.plan.execution.cache.ExecutionCache) PureExpressionPlatformExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.PureExpressionPlatformExecutionNode) GraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.GraphFetchExecutionNode) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) JavaHelper(org.finos.legend.engine.plan.execution.nodes.helpers.platform.JavaHelper) StreamSupport(java.util.stream.StreamSupport) IChecked(org.finos.legend.engine.plan.dependencies.domain.dataQuality.IChecked) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) SequenceExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.SequenceExecutionNode) Result(org.finos.legend.engine.plan.execution.result.Result) ResultVisitor(org.finos.legend.engine.plan.execution.result.ResultVisitor) XStorePropertyFetchDetails(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.XStorePropertyFetchDetails) GraphFetchCacheByTargetCrossKeys(org.finos.legend.engine.plan.execution.cache.graphFetch.GraphFetchCacheByTargetCrossKeys) ExecutionNodeJavaPlatformHelper(org.finos.legend.engine.plan.execution.nodes.helpers.platform.ExecutionNodeJavaPlatformHelper) GlobalTracer(io.opentracing.util.GlobalTracer) GraphObjectsBatch(org.finos.legend.engine.plan.execution.result.graphFetch.GraphObjectsBatch) InMemoryPropertyGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryPropertyGraphFetchExecutionNode) ProfileManager(org.pac4j.core.profile.ProfileManager) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) MultiResult(org.finos.legend.engine.plan.execution.result.MultiResult) GlobalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.GlobalGraphFetchExecutionNode) LocalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.LocalGraphFetchExecutionNode) GraphExecutionState(org.finos.legend.engine.plan.execution.nodes.state.GraphExecutionState) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) GraphObjectsBatch(org.finos.legend.engine.plan.execution.result.graphFetch.GraphObjectsBatch) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) GraphFetchResult(org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult) Span(io.opentracing.Span) AtomicLong(java.util.concurrent.atomic.AtomicLong) IChecked(org.finos.legend.engine.plan.dependencies.domain.dataQuality.IChecked) Constrained(org.finos.legend.engine.plan.dependencies.domain.dataQuality.Constrained) Collection(java.util.Collection) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List)

Example 2 with PartialClassBuilder

use of org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder in project legend-engine by finos.

the class ExecutionNodeExecutor method visit.

@Deprecated
@Override
public Result visit(GraphFetchExecutionNode graphFetchExecutionNode) {
    final Span topSpan = GlobalTracer.get().activeSpan();
    try (Scope ignored1 = GlobalTracer.get().buildSpan("Graph Query: Execute").startActive(true)) {
        Result rootResult;
        try (Scope ignored2 = GlobalTracer.get().buildSpan("Graph Query: Execute Root").startActive(true)) {
            rootResult = graphFetchExecutionNode.rootExecutionNode.accept(new ExecutionNodeExecutor(profiles, executionState));
        }
        if (graphFetchExecutionNode.implementation != null) {
            if (!(rootResult instanceof StreamingObjectResult)) {
                throw new RuntimeException("Unexpected result : " + rootResult.getClass().getName());
            }
            StreamingObjectResult<?> objectResult = (StreamingObjectResult<?>) rootResult;
            try {
                if (!(graphFetchExecutionNode.implementation instanceof JavaPlatformImplementation)) {
                    throw new RuntimeException("Only Java implementations are currently supported, found: " + graphFetchExecutionNode.implementation);
                }
                JavaPlatformImplementation javaPlatformImpl = (JavaPlatformImplementation) graphFetchExecutionNode.implementation;
                String executionClassName = JavaHelper.getExecutionClassFullName(javaPlatformImpl);
                String executionMethodName = JavaHelper.getExecutionMethodName(javaPlatformImpl);
                Stream<?> transformedResult = ExecutionNodeJavaPlatformHelper.executeStaticJavaMethod(graphFetchExecutionNode, executionClassName, executionMethodName, Arrays.asList(StreamingObjectResult.class, ExecutionNode.class, ExecutionState.class, ProfileManager.class), Arrays.asList(objectResult, graphFetchExecutionNode, this.executionState, this.profiles), this.executionState, this.profiles);
                return new StreamingObjectResult<>(transformedResult, objectResult.getResultBuilder(), objectResult);
            } catch (Exception e) {
                objectResult.close();
                throw e;
            }
        } else {
            final long maxMemoryBytesForGraph = 52_428_800L;
            /* 50MB - 50 * 1024 * 1024 */
            final int batchSize = graphFetchExecutionNode.batchSize;
            final GlobalGraphFetchExecutionNode rootGlobalNode = graphFetchExecutionNode.globalGraphFetchExecutionNode;
            final LocalGraphFetchExecutionNode rootLocalNode = rootGlobalNode.localGraphFetchExecutionNode;
            final AtomicInteger batchIndex = new AtomicInteger(1);
            final AtomicLong rowCount = new AtomicLong(0);
            try {
                Stream<List<?>> batchedStoreLocalObjectStream = StreamSupport.stream(new Spliterators.AbstractSpliterator<List<?>>(Long.MAX_VALUE, Spliterator.ORDERED) {

                    @Override
                    public boolean tryAdvance(Consumer<? super List<?>> action) {
                        int currentBatch = batchIndex.getAndIncrement();
                        try (Scope scope = GlobalTracer.get().buildSpan("Graph Query: Execute Batch " + currentBatch).startActive(true)) {
                            GraphExecutionState graphExecutionState = new GraphExecutionState(executionState, batchSize, rootResult, maxMemoryBytesForGraph);
                            ConstantResult constantResult = (ConstantResult) rootLocalNode.accept(new ExecutionNodeExecutor(ExecutionNodeExecutor.this.profiles, graphExecutionState));
                            List<?> objects = (List<?>) constantResult.getValue();
                            boolean nonEmptyObjectList = !objects.isEmpty();
                            if (rootGlobalNode.children != null && (rootGlobalNode.children.size() > 0) && nonEmptyObjectList) {
                                try (Scope ignored3 = GlobalTracer.get().buildSpan("Graph Query: Execute Cross Store Children").startActive(true)) {
                                    for (GlobalGraphFetchExecutionNode crossChild : rootGlobalNode.children) {
                                        try (Scope ignored4 = GlobalTracer.get().buildSpan("Graph Query: Execute Cross Store Child").startActive(true)) {
                                            graphExecutionState.setObjectsToGraphFetch(objects);
                                            ExecutionNodeExecutor.this.executeGlobalGraphOperation(crossChild, graphExecutionState);
                                        }
                                    }
                                }
                            }
                            rowCount.addAndGet(graphExecutionState.getRowCount());
                            action.accept(objects);
                            if (nonEmptyObjectList) {
                                scope.span().setTag("batchObjectCount", objects.size());
                                scope.span().setTag("batchMemoryUtilization", graphExecutionState.getTotalObjectMemoryUtilization());
                            } else {
                                if (topSpan != null) {
                                    topSpan.setTag("lastQueryRowCount", rowCount);
                                }
                            }
                            return nonEmptyObjectList && (objects.size() >= batchSize);
                        }
                    }
                }, false);
                Stream<?> globalObjectStream = batchedStoreLocalObjectStream.flatMap(Collection::stream);
                return new StreamingObjectResult<>(globalObjectStream, new PartialClassBuilder(graphFetchExecutionNode), rootResult);
            } catch (Exception e) {
                rootResult.close();
                throw e;
            }
        }
    }
}
Also used : ProfileManager(org.pac4j.core.profile.ProfileManager) GraphExecutionState(org.finos.legend.engine.plan.execution.nodes.state.GraphExecutionState) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) LocalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.LocalGraphFetchExecutionNode) InMemoryCrossStoreGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryCrossStoreGraphFetchExecutionNode) ErrorExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ErrorExecutionNode) StoreStreamReadingExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.StoreStreamReadingExecutionNode) ExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode) AllocationExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AllocationExecutionNode) ConstantExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ConstantExecutionNode) InMemoryRootGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryRootGraphFetchExecutionNode) FreeMarkerConditionalExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.FreeMarkerConditionalExecutionNode) MultiResultSequenceExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.MultiResultSequenceExecutionNode) AggregationAwareExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AggregationAwareExecutionNode) GraphFetchM2MExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.GraphFetchM2MExecutionNode) PureExpressionPlatformExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.PureExpressionPlatformExecutionNode) GraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.GraphFetchExecutionNode) SequenceExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.SequenceExecutionNode) InMemoryPropertyGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryPropertyGraphFetchExecutionNode) GlobalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.GlobalGraphFetchExecutionNode) LocalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.LocalGraphFetchExecutionNode) Span(io.opentracing.Span) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) GraphFetchResult(org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) Result(org.finos.legend.engine.plan.execution.result.Result) MultiResult(org.finos.legend.engine.plan.execution.result.MultiResult) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) GraphExecutionState(org.finos.legend.engine.plan.execution.nodes.state.GraphExecutionState) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) Spliterators(java.util.Spliterators) AtomicLong(java.util.concurrent.atomic.AtomicLong) Scope(io.opentracing.Scope) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) GlobalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.GlobalGraphFetchExecutionNode)

Example 3 with PartialClassBuilder

use of org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder in project legend-engine by finos.

the class RelationalResult method buildTransformersAndBuilder.

private void buildTransformersAndBuilder(ExecutionNode node, DatabaseConnection databaseConnection) throws SQLException {
    boolean isDatabaseIdentifiersCaseSensitive = databaseConnection.accept(new DatabaseIdentifiersCaseSensitiveVisitor());
    if (ExecutionNodeTDSResultHelper.isResultTDS(node)) {
        List<TransformerInput<Integer>> transformerInputs = Lists.mutable.empty();
        for (int columnIndex = 1; columnIndex <= this.columnCount; columnIndex++) {
            TDSColumn c = ExecutionNodeTDSResultHelper.getTDSColumn(node, this.resultSetMetaData.getColumnLabel(columnIndex), isDatabaseIdentifiersCaseSensitive);
            transformerInputs.add(new TransformerInput<>(columnIndex, c.type, (index) -> {
                try {
                    return ExecutionNodeTDSResultHelper.isTDSColumnEnum(node, this.resultSetMetaData.getColumnLabel(index), isDatabaseIdentifiersCaseSensitive);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }, (index) -> {
                try {
                    return ExecutionNodeTDSResultHelper.getTDSEnumTransformer(node, this.resultSetMetaData.getColumnLabel(index), isDatabaseIdentifiersCaseSensitive);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }));
        }
        setTransformers.add(new SetImplTransformers(transformerInputs));
        this.builder = new TDSBuilder(node, this.sqlColumns, isDatabaseIdentifiersCaseSensitive);
        this.columnListForSerializer = ListIterate.collect(((TDSBuilder) this.builder).columns, col -> col.name);
    } else if (ExecutionNodeClassResultHelper.isClassResult(node)) {
        List<? extends ClassMappingInfo> classMappings = ExecutionNodeClassResultHelper.getClassMappingInfoFromClassResult(node);
        for (ClassMappingInfo classMappingInfo : classMappings) {
            List<TransformerInput<String>> transformerInputs = Lists.mutable.empty();
            for (int i = 1; i <= this.columnCount; i++) {
                final String colName = this.resultSetMetaData.getColumnLabel(i);
                PropertyInfo profiles = ListIterate.select(classMappingInfo.properties, p -> isDatabaseIdentifiersCaseSensitive ? p.property.equals(colName) : p.property.equalsIgnoreCase(colName)).getFirst();
                transformerInputs.add(new TransformerInput<>(profiles != null ? profiles.property : colName, resolveType(profiles, colName), (colNameX) -> {
                    try {
                        return !TEMPORAL_DATE_ALIASES.contains(colNameX) && ExecutionNodeClassResultHelper.isClassPropertyEnum(node, classMappingInfo.setImplementationId, colNameX);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }, (colNameX) -> {
                    try {
                        return ExecutionNodeClassResultHelper.getClassEnumTransformer(node, classMappingInfo.setImplementationId, colNameX);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }));
            }
            setTransformers.add(new SetImplTransformers(transformerInputs));
            if (ExecutionNodePartialClassResultHelper.isPartialClassResult(node)) {
                this.builder = new PartialClassBuilder(node);
            } else {
                this.builder = new ClassBuilder(node);
            }
        }
    } else if (ExecutionNodeRelationalResultHelper.isRelationResult(node)) {
        SetImplTransformers setImpl = new SetImplTransformers();
        for (int columnIndex = 1; columnIndex <= this.columnCount; columnIndex++) {
            setImpl.transformers.add(SetImplTransformers.TEMPORARY_DATATYPE_TRANSFORMER);
        }
        setTransformers.add(setImpl);
        this.builder = new RelationBuilder(node);
    } else {
        SetImplTransformers setImpl = new SetImplTransformers();
        for (int i = 1; i <= this.columnCount; i++) {
            setImpl.transformers.add(SetImplTransformers.TEMPORARY_DATATYPE_TRANSFORMER);
        }
        setTransformers.add(setImpl);
        this.builder = new DataTypeBuilder(node);
    }
}
Also used : LoggingEventType(org.finos.legend.engine.shared.core.operational.logs.LoggingEventType) DatabaseManager(org.finos.legend.engine.plan.execution.stores.relational.connection.driver.DatabaseManager) Serializer(org.finos.legend.engine.plan.execution.result.serialization.Serializer) DatabaseType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType) Connection(java.sql.Connection) ClassMappingInfo(org.finos.legend.engine.plan.execution.result.builder._class.ClassMappingInfo) ExecutionNodeTDSResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeTDSResultHelper) SerializationFormat(org.finos.legend.engine.plan.execution.result.serialization.SerializationFormat) RelationalInstantiationExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.RelationalInstantiationExecutionNode) TransformerInput(org.finos.legend.engine.plan.execution.result.transformer.TransformerInput) MutableList(org.eclipse.collections.api.list.MutableList) TDSColumn(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.result.TDSColumn) ResultSet(java.sql.ResultSet) ExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode) RelationBuilder(org.finos.legend.engine.plan.execution.stores.relational.result.builder.relation.RelationBuilder) Builder(org.finos.legend.engine.plan.execution.result.builder.Builder) IRelationalResult(org.finos.legend.engine.plan.dependencies.store.relational.IRelationalResult) SQLResultColumn(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.result.SQLResultColumn) GregorianCalendar(java.util.GregorianCalendar) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) StreamingResult(org.finos.legend.engine.plan.execution.result.StreamingResult) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) RelationalResultToPureTDSSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSSerializer) List(java.util.List) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) Lists(org.eclipse.collections.impl.factory.Lists) PureDate(org.finos.legend.engine.plan.dependencies.domain.date.PureDate) ExecutionNodeClassResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeClassResultHelper) Span(io.opentracing.Span) PropertyInfo(org.finos.legend.engine.plan.execution.result.builder._class.PropertyInfo) ResultSetMetaData(java.sql.ResultSetMetaData) Types(java.sql.Types) CommonProfile(org.pac4j.core.profile.CommonProfile) RelationalExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.RelationalExecutionNode) Function(org.eclipse.collections.api.block.function.Function) ExecutionActivity(org.finos.legend.engine.plan.execution.result.ExecutionActivity) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) SQLException(java.sql.SQLException) RelationalResultToJsonDefaultSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToJsonDefaultSerializer) RelationalExecutionActivity(org.finos.legend.engine.plan.execution.stores.relational.activity.RelationalExecutionActivity) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) Result(org.finos.legend.engine.plan.execution.result.Result) ResultVisitor(org.finos.legend.engine.plan.execution.result.ResultVisitor) Logger(org.slf4j.Logger) ListIterate(org.eclipse.collections.impl.utility.ListIterate) ClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.ClassBuilder) SetImplTransformers(org.finos.legend.engine.plan.execution.result.transformer.SetImplTransformers) DataTypeBuilder(org.finos.legend.engine.plan.execution.result.builder.datatype.DataTypeBuilder) ExecutionNodePartialClassResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodePartialClassResultHelper) Consumer(java.util.function.Consumer) RelationalResultToCSVSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToCSVSerializer) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Statement(java.sql.Statement) RelationalResultToPureTDSToObjectSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToPureTDSToObjectSerializer) TDSBuilder(org.finos.legend.engine.plan.execution.result.builder.tds.TDSBuilder) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) SetImplTransformers(org.finos.legend.engine.plan.execution.result.transformer.SetImplTransformers) PartialClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder) ClassBuilder(org.finos.legend.engine.plan.execution.result.builder._class.ClassBuilder) TransformerInput(org.finos.legend.engine.plan.execution.result.transformer.TransformerInput) SQLException(java.sql.SQLException) ClassMappingInfo(org.finos.legend.engine.plan.execution.result.builder._class.ClassMappingInfo) DataTypeBuilder(org.finos.legend.engine.plan.execution.result.builder.datatype.DataTypeBuilder) TDSColumn(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.result.TDSColumn) RelationBuilder(org.finos.legend.engine.plan.execution.stores.relational.result.builder.relation.RelationBuilder) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) ImmutableList(org.eclipse.collections.api.list.ImmutableList) TDSBuilder(org.finos.legend.engine.plan.execution.result.builder.tds.TDSBuilder) PropertyInfo(org.finos.legend.engine.plan.execution.result.builder._class.PropertyInfo)

Aggregations

Span (io.opentracing.Span)3 List (java.util.List)3 MutableList (org.eclipse.collections.api.list.MutableList)3 Scope (io.opentracing.Scope)2 Collection (java.util.Collection)2 Spliterators (java.util.Spliterators)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Consumer (java.util.function.Consumer)2 Lists (org.eclipse.collections.impl.factory.Lists)2 ExecutionState (org.finos.legend.engine.plan.execution.nodes.state.ExecutionState)2 GraphExecutionState (org.finos.legend.engine.plan.execution.nodes.state.GraphExecutionState)2 ConstantResult (org.finos.legend.engine.plan.execution.result.ConstantResult)2 ErrorResult (org.finos.legend.engine.plan.execution.result.ErrorResult)2 Result (org.finos.legend.engine.plan.execution.result.Result)2 PartialClassBuilder (org.finos.legend.engine.plan.execution.result.builder._class.PartialClassBuilder)2 ExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode)2 GlobalTracer (io.opentracing.util.GlobalTracer)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1