Search in sources :

Example 1 with BlockConnection

use of org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection in project legend-engine by finos.

the class RelationalExecutionNodeExecutor method createTempTableFromRealizedRelationalResultInBlockConnection.

private void createTempTableFromRealizedRelationalResultInBlockConnection(RealizedRelationalResult realizedRelationalResult, String tempTableName, DatabaseConnection databaseConnection, String databaseType, String databaseTimeZone) {
    try (Scope ignored = GlobalTracer.get().buildSpan("create temp table").withTag("tempTableName", tempTableName).withTag("databaseType", databaseType).startActive(true)) {
        RelationalStoreExecutionState relationalStoreExecutionState = (RelationalStoreExecutionState) this.executionState.getStoreExecutionState(StoreType.Relational);
        DatabaseManager databaseManager = DatabaseManager.fromString(databaseType);
        BlockConnection blockConnection = relationalStoreExecutionState.getBlockConnectionContext().getBlockConnection(relationalStoreExecutionState, databaseConnection, this.profiles);
        databaseManager.relationalDatabaseSupport().accept(RelationalDatabaseCommandsVisitorBuilder.getStreamResultToTempTableVisitor(relationalStoreExecutionState.getRelationalExecutor().getRelationalExecutionConfiguration(), blockConnection, realizedRelationalResult, tempTableName, databaseTimeZone));
        blockConnection.addCommitQuery(databaseManager.relationalDatabaseSupport().dropTempTable(tempTableName));
        blockConnection.addRollbackQuery(databaseManager.relationalDatabaseSupport().dropTempTable(tempTableName));
        blockConnection.close();
    }
}
Also used : Scope(io.opentracing.Scope) DatabaseManager(org.finos.legend.engine.plan.execution.stores.relational.connection.driver.DatabaseManager) BlockConnection(org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection)

Example 2 with BlockConnection

use of org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection in project legend-engine by finos.

the class RelationalExecutionNodeExecutor method getConnection.

private Connection getConnection(CreateAndPopulateTempTableExecutionNode createAndPopulateTempTableExecutionNode, RelationalDatabaseCommands databaseCommands, MutableList<CommonProfile> profiles, ExecutionState executionState) {
    if (((RelationalStoreExecutionState) executionState.getStoreExecutionState(StoreType.Relational)).retainConnection()) {
        BlockConnection blockConnection = ((RelationalStoreExecutionState) executionState.getStoreExecutionState(StoreType.Relational)).getBlockConnectionContext().getBlockConnection(((RelationalStoreExecutionState) executionState.getStoreExecutionState(StoreType.Relational)), createAndPopulateTempTableExecutionNode.connection, profiles);
        blockConnection.addRollbackQuery(databaseCommands.dropTempTable(createAndPopulateTempTableExecutionNode.tempTableName));
        blockConnection.addCommitQuery(databaseCommands.dropTempTable(createAndPopulateTempTableExecutionNode.tempTableName));
        return blockConnection;
    }
    throw new RuntimeException("CreateAndPopulateTempTableExecutionNode should be used within RelationalBlockExecutionNode");
}
Also used : BlockConnection(org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection)

Aggregations

BlockConnection (org.finos.legend.engine.plan.execution.stores.relational.blockConnection.BlockConnection)2 Scope (io.opentracing.Scope)1 DatabaseManager (org.finos.legend.engine.plan.execution.stores.relational.connection.driver.DatabaseManager)1