Search in sources :

Example 1 with CommandNeedRetryException

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;
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException)

Example 2 with CommandNeedRetryException

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();
    }
}
Also used : TezTask(org.apache.hadoop.hive.ql.exec.tez.TezTask) Task(org.apache.hadoop.hive.ql.exec.Task) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Schema(org.apache.hadoop.hive.llap.Schema) Driver(org.apache.hadoop.hive.ql.Driver) IOException(java.io.IOException) QueryPlan(org.apache.hadoop.hive.ql.QueryPlan) TezTask(org.apache.hadoop.hive.ql.exec.tez.TezTask) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) TezWork(org.apache.hadoop.hive.ql.plan.TezWork)

Example 3 with CommandNeedRetryException

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() : "")));
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException)

Example 4 with CommandNeedRetryException

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() : "")));
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException)

Aggregations

CommandNeedRetryException (org.apache.hadoop.hive.ql.CommandNeedRetryException)4 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)4 IOException (java.io.IOException)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 Schema (org.apache.hadoop.hive.llap.Schema)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 Driver (org.apache.hadoop.hive.ql.Driver)1 QueryPlan (org.apache.hadoop.hive.ql.QueryPlan)1 Task (org.apache.hadoop.hive.ql.exec.Task)1 TezTask (org.apache.hadoop.hive.ql.exec.tez.TezTask)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 TezWork (org.apache.hadoop.hive.ql.plan.TezWork)1