@Override public void run() throws OdpsException, ODPSConsoleException { Odps odps = getCurrentOdps(); ExecutionContext context = getContext(); Instance instance = odps.instances().get(id); InstanceRunner runner = new InstanceRunner(odps, instance, context); runner.waitForCompletion(); String queryResult = runner.getResult(); DefaultOutputWriter writer = context.getOutputWriter(); if (queryResult != null && !queryResult.trim().equals("")) { writer.writeResult(queryResult); } }
protected void runJob(Task task) throws OdpsException, ODPSConsoleException { ExecutionContext context = getContext(); Map<String, String> config = task.getProperties(); addSetting(config, SetCommand.setMap); for (Entry<String, String> property : config.entrySet()) { task.setProperty(property.getKey(), property.getValue()); } InstanceRunner runner = new InstanceRunner(getCurrentOdps(), task, context); runner.submit(); //delay hooks after print result OdpsHooks hooks = runner.getInstance().getOdpsHooks(); runner.getInstance().setOdpsHooks(null); if (context.isAsyncMode()) { instanceId = runner.getInstance().getId(); // 如果是异常模式,提交job后直接退出 return; } runner.waitForCompletion(); // 执行完了再重新拿一次 instanceId = runner.getInstance().getId(); try { reportResult(runner); } finally { if (hooks != null) { hooks.after(runner.getInstance(), getCurrentOdps()); } } }