Search in sources :

Example 1 with SQLWriteRequest

use of io.cdap.cdap.etl.api.engine.sql.request.SQLWriteRequest in project cdap by caskdata.

the class BatchSQLEngineAdapter method write.

/**
 * Try to write the output directly to the SQLEngineOutput registered by this engine.
 *
 * @param datasetName     dataset to write
 * @param sqlEngineOutput output instance created by this engine
 * @return {@link SQLEngineJob<Boolean>} representing if the write operation succeded.
 */
public SQLEngineJob<Boolean> write(String datasetName, SQLEngineOutput sqlEngineOutput) {
    String outputStageName = sqlEngineOutput.getStageName();
    SQLEngineWriteJobKey writeJobKey = new SQLEngineWriteJobKey(datasetName, outputStageName, SQLEngineJobType.WRITE);
    // Run write job
    return runJob(writeJobKey, () -> {
        getDatasetForStage(datasetName);
        LOG.debug("Attempting write for dataset {} into {}", datasetName, sqlEngineOutput);
        SQLWriteResult writeResult = sqlEngine.write(new SQLWriteRequest(datasetName, sqlEngineOutput));
        LOG.debug("Write dataset {} into {} was {}", datasetName, sqlEngineOutput, writeResult.isSuccessful() ? "completed" : "refused");
        // If the result was successful, add stage metrics.
        if (writeResult.isSuccessful()) {
            DefaultStageMetrics stageMetrics = new DefaultStageMetrics(metrics, outputStageName);
            StageStatisticsCollector statisticsCollector = statsCollectors.get(outputStageName);
            countRecordsIn(writeResult.getNumRecords(), statisticsCollector, stageMetrics);
            countRecordsOut(writeResult.getNumRecords(), statisticsCollector, stageMetrics);
        }
        return writeResult.isSuccessful();
    });
}
Also used : SQLWriteRequest(io.cdap.cdap.etl.api.engine.sql.request.SQLWriteRequest) StageStatisticsCollector(io.cdap.cdap.etl.common.StageStatisticsCollector) SQLEngineWriteJobKey(io.cdap.cdap.etl.engine.SQLEngineWriteJobKey) SQLWriteResult(io.cdap.cdap.etl.api.engine.sql.request.SQLWriteResult) DefaultStageMetrics(io.cdap.cdap.etl.common.DefaultStageMetrics)

Aggregations

SQLWriteRequest (io.cdap.cdap.etl.api.engine.sql.request.SQLWriteRequest)1 SQLWriteResult (io.cdap.cdap.etl.api.engine.sql.request.SQLWriteResult)1 DefaultStageMetrics (io.cdap.cdap.etl.common.DefaultStageMetrics)1 StageStatisticsCollector (io.cdap.cdap.etl.common.StageStatisticsCollector)1 SQLEngineWriteJobKey (io.cdap.cdap.etl.engine.SQLEngineWriteJobKey)1