use of org.apache.hadoop.hive.ql.CommandNeedRetryException in project hive by apache.
the class TestStreaming method runDDL.
private static boolean runDDL(Driver driver, String sql) throws QueryFailedException {
LOG.debug(sql);
System.out.println(sql);
// # of times to retry if first attempt fails
int retryCount = 1;
for (int attempt = 0; attempt <= retryCount; ++attempt) {
try {
//LOG.debug("Running Hive Query: "+ sql);
CommandProcessorResponse cpr = driver.run(sql);
if (cpr.getResponseCode() == 0) {
return true;
}
LOG.error("Statement: " + sql + " failed: " + cpr);
} catch (CommandNeedRetryException e) {
if (attempt == retryCount) {
throw new QueryFailedException(sql, e);
}
continue;
}
}
// for
return false;
}
use of org.apache.hadoop.hive.ql.CommandNeedRetryException in project hive by apache.
the class GenericUDTFGetSplits method createPlanFragment.
public PlanFragment createPlanFragment(String query, int num) throws HiveException {
HiveConf conf = new HiveConf(SessionState.get().getConf());
HiveConf.setVar(conf, ConfVars.HIVEFETCHTASKCONVERSION, "none");
HiveConf.setVar(conf, ConfVars.HIVEQUERYRESULTFILEFORMAT, PlanUtils.LLAP_OUTPUT_FORMAT_KEY);
String originalMode = HiveConf.getVar(conf, ConfVars.HIVE_EXECUTION_MODE);
HiveConf.setVar(conf, ConfVars.HIVE_EXECUTION_MODE, "llap");
HiveConf.setBoolVar(conf, ConfVars.HIVE_TEZ_GENERATE_CONSISTENT_SPLITS, true);
HiveConf.setBoolVar(conf, ConfVars.LLAP_CLIENT_CONSISTENT_SPLITS, true);
conf.setBoolean(TezSplitGrouper.TEZ_GROUPING_NODE_LOCAL_ONLY, true);
// Tez/LLAP requires RPC query plan
HiveConf.setBoolVar(conf, ConfVars.HIVE_RPC_QUERY_PLAN, true);
try {
jc = DagUtils.getInstance().createConfiguration(conf);
} catch (IOException e) {
throw new HiveException(e);
}
Driver driver = new Driver(conf);
try {
CommandProcessorResponse cpr = driver.compileAndRespond(query);
if (cpr.getResponseCode() != 0) {
throw new HiveException("Failed to compile query: " + cpr.getException());
}
QueryPlan plan = driver.getPlan();
List<Task<?>> roots = plan.getRootTasks();
Schema schema = convertSchema(plan.getResultSchema());
if (roots == null || roots.size() != 1 || !(roots.get(0) instanceof TezTask)) {
throw new HiveException("Was expecting a single TezTask.");
}
TezWork tezWork = ((TezTask) roots.get(0)).getWork();
if (tezWork.getAllWork().size() != 1) {
String tableName = "table_" + UUID.randomUUID().toString().replaceAll("[^A-Za-z0-9 ]", "");
String ctas = "create temporary table " + tableName + " as " + query;
LOG.info("Materializing the query for LLAPIF; CTAS: " + ctas);
try {
driver.resetQueryState();
HiveConf.setVar(conf, ConfVars.HIVE_EXECUTION_MODE, originalMode);
cpr = driver.run(ctas, false);
} catch (CommandNeedRetryException e) {
throw new HiveException(e);
}
if (cpr.getResponseCode() != 0) {
throw new HiveException("Failed to create temp table: " + cpr.getException());
}
HiveConf.setVar(conf, ConfVars.HIVE_EXECUTION_MODE, "llap");
query = "select * from " + tableName;
cpr = driver.compileAndRespond(query);
if (cpr.getResponseCode() != 0) {
throw new HiveException("Failed to create temp table: " + cpr.getException());
}
plan = driver.getPlan();
roots = plan.getRootTasks();
schema = convertSchema(plan.getResultSchema());
if (roots == null || roots.size() != 1 || !(roots.get(0) instanceof TezTask)) {
throw new HiveException("Was expecting a single TezTask.");
}
tezWork = ((TezTask) roots.get(0)).getWork();
}
return new PlanFragment(tezWork, schema, jc);
} finally {
driver.close();
driver.destroy();
}
}
use of org.apache.hadoop.hive.ql.CommandNeedRetryException in project drill by apache.
the class HiveTestUtilities method executeQuery.
/**
* Execute the give <i>query</i> on given <i>hiveDriver</i> instance. If a {@link CommandNeedRetryException}
* exception is thrown, it tries upto 3 times before returning failure.
* @param hiveDriver
* @param query
*/
public static void executeQuery(Driver hiveDriver, String query) {
CommandProcessorResponse response = null;
boolean failed = false;
int retryCount = 3;
try {
response = hiveDriver.run(query);
} catch (CommandNeedRetryException ex) {
if (--retryCount == 0) {
failed = true;
}
}
if (failed || response.getResponseCode() != 0) {
throw new RuntimeException(String.format("Failed to execute command '%s', errorMsg = '%s'", query, (response != null ? response.getErrorMessage() : "")));
}
}
use of org.apache.hadoop.hive.ql.CommandNeedRetryException in project drill by axbaretto.
the class HiveTestUtilities method executeQuery.
/**
* Execute the give <i>query</i> on given <i>hiveDriver</i> instance. If a {@link CommandNeedRetryException}
* exception is thrown, it tries upto 3 times before returning failure.
* @param hiveDriver
* @param query
*/
public static void executeQuery(Driver hiveDriver, String query) {
CommandProcessorResponse response = null;
boolean failed = false;
int retryCount = 3;
try {
response = hiveDriver.run(query);
} catch (CommandNeedRetryException ex) {
if (--retryCount == 0) {
failed = true;
}
}
if (failed || response.getResponseCode() != 0) {
throw new RuntimeException(String.format("Failed to execute command '%s', errorMsg = '%s'", query, (response != null ? response.getErrorMessage() : "")));
}
}
Aggregations