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();
});
}
Aggregations