Search in sources :

Example 1 with VoidRelationalResult

use of org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult in project legend-engine by finos.

the class RelationalExecutor method execute.

public Result execute(RelationalExecutionNode node, MutableList<CommonProfile> profiles, ExecutionState executionState) {
    Connection connectionManagerConnection;
    String databaseTimeZone = node.getDatabaseTimeZone() == null ? DEFAULT_DB_TIME_ZONE : node.getDatabaseTimeZone();
    String databaseTypeName = node.getDatabaseTypeName();
    List<String> tempTableList = new FastList<>();
    connectionManagerConnection = getConnection(node, profiles, ((RelationalStoreExecutionState) executionState.getStoreExecutionState(StoreType.Relational)));
    Span span = GlobalTracer.get().activeSpan();
    if (span != null) {
        span.log("Connection acquired");
    }
    this.prepareForSQLExecution(node, connectionManagerConnection, databaseTimeZone, databaseTypeName, tempTableList, profiles, executionState);
    if (executionState.inAllocation) {
        if ((ExecutionNodeTDSResultHelper.isResultTDS(node) || (ExecutionNodeResultHelper.isResultSizeRangeSet(node) && !ExecutionNodeResultHelper.isSingleRecordResult(node))) && !executionState.transformAllocation) {
            return new RelationalResult(executionState.activities, node, node.resultColumns, databaseTypeName, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
        } else if (node.isResultVoid()) {
            return new VoidRelationalResult(executionState.activities, connectionManagerConnection, profiles);
        } else {
            // Refactor and clean up the flush to Constant
            RelationalResult result = new RelationalResult(executionState.activities, node, node.resultColumns, databaseTypeName, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
            if (node.isResultPrimitiveType()) {
                try {
                    if (result.resultSet.next()) {
                        MutableList<Function<Object, Object>> transformers = result.getTransformers();
                        Object convertedValue = transformers.get(0).valueOf(result.resultSet.getObject(1));
                        return new ConstantResult(convertedValue);
                    } else {
                        throw new RuntimeException("Result set is empty for allocation node");
                    }
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            } else {
                try {
                    RealizedRelationalResult realizedRelationalResult = (RealizedRelationalResult) result.realizeInMemory();
                    List<Map<String, Object>> rowValueMaps = realizedRelationalResult.getRowValueMaps(false);
                    Result res = evaluateAdditionalExtractors(this.resultInterpreterExtensions, executionState, rowValueMaps);
                    if (res != null) {
                        return res;
                    } else if (ExecutionNodeClassResultHelper.isClassResult(node) && rowValueMaps.size() == 1) {
                        return new ConstantResult(rowValueMaps.get(0));
                    } else {
                        return new ConstantResult(rowValueMaps);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    } else if (node.isResultVoid()) {
        return new VoidRelationalResult(executionState.activities, connectionManagerConnection, profiles);
    } else {
        return new RelationalResult(executionState.activities, node, node.resultColumns, databaseTypeName, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
    }
}
Also used : RealizedRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RealizedRelationalResult) SQLException(java.sql.SQLException) Connection(java.sql.Connection) BlockConnection(org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) FastList(org.eclipse.collections.impl.list.mutable.FastList) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) Span(io.opentracing.Span) SQLException(java.sql.SQLException) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) StreamingResult(org.finos.legend.engine.plan.execution.result.StreamingResult) PreparedTempTableResult(org.finos.legend.engine.plan.execution.stores.relational.result.PreparedTempTableResult) SQLExecutionResult(org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult) VoidRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) RealizedRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RealizedRelationalResult) Result(org.finos.legend.engine.plan.execution.result.Result) MutableList(org.eclipse.collections.api.list.MutableList) VoidRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) RealizedRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RealizedRelationalResult) VoidRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) FastList(org.eclipse.collections.impl.list.mutable.FastList)

Example 2 with VoidRelationalResult

use of org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult in project legend-engine by finos.

the class RelationalExecutor method execute.

public Result execute(SQLExecutionNode node, MutableList<CommonProfile> profiles, ExecutionState executionState) {
    Connection connectionManagerConnection;
    String databaseTimeZone = node.getDatabaseTimeZone() == null ? DEFAULT_DB_TIME_ZONE : node.getDatabaseTimeZone();
    String databaseType = node.getDatabaseTypeName();
    List<String> tempTableList = FastList.newList();
    Span span = GlobalTracer.get().activeSpan();
    connectionManagerConnection = getConnection(node, profiles, (RelationalStoreExecutionState) executionState.getStoreExecutionState(StoreType.Relational));
    if (span != null) {
        span.log("Connection acquired");
    }
    this.prepareForSQLExecution(node, connectionManagerConnection, databaseTimeZone, databaseType, tempTableList, profiles, executionState);
    if (node.isResultVoid()) {
        return new VoidRelationalResult(executionState.activities, connectionManagerConnection, profiles);
    }
    return new SQLExecutionResult(executionState.activities, node, databaseType, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
}
Also used : RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) Connection(java.sql.Connection) BlockConnection(org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) VoidRelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult) Span(io.opentracing.Span) SQLExecutionResult(org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult)

Aggregations

Span (io.opentracing.Span)2 Connection (java.sql.Connection)2 BlockConnection (org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection)2 SQLExecutionResult (org.finos.legend.engine.plan.execution.stores.relational.result.SQLExecutionResult)2 VoidRelationalResult (org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult)2 DatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection)2 SQLException (java.sql.SQLException)1 List (java.util.List)1 MutableList (org.eclipse.collections.api.list.MutableList)1 FastList (org.eclipse.collections.impl.list.mutable.FastList)1 ConstantResult (org.finos.legend.engine.plan.execution.result.ConstantResult)1 Result (org.finos.legend.engine.plan.execution.result.Result)1 StreamingResult (org.finos.legend.engine.plan.execution.result.StreamingResult)1 RelationalStoreExecutionState (org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState)1 PreparedTempTableResult (org.finos.legend.engine.plan.execution.stores.relational.result.PreparedTempTableResult)1 RealizedRelationalResult (org.finos.legend.engine.plan.execution.stores.relational.result.RealizedRelationalResult)1 RelationalResult (org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult)1