@Override
public void execute(QueryMaster.QueryMasterContext context, QueryContext queryContext,
Query query, ExecutionBlockId finalExecBlockId, Path finalOutputDir)
throws Exception {
CatalogService catalog = context.getWorkerContext().getCatalog();
SubQuery lastStage = query.getSubQuery(finalExecBlockId);
TableMeta meta = lastStage.getTableMeta();
TableStats stats = lastStage.getResultStats();
InsertNode insertNode = (InsertNode) lastStage.getBlock().getPlan();
TableDesc finalTable;
if (insertNode.hasTargetTable()) {
String tableName = insertNode.getTableName();
finalTable = catalog.getTableDesc(tableName);
} else {
String tableName = query.getId().toString();
finalTable = new TableDesc(tableName, lastStage.getSchema(), meta, finalOutputDir);
}
long volume = getTableVolume(query.systemConf, finalOutputDir);
stats.setNumBytes(volume);
finalTable.setStats(stats);
if (insertNode.hasTargetTable()) {
catalog.dropTable(insertNode.getTableName());
catalog.createTable(finalTable);
}
query.setResultDesc(finalTable);
}