Search in sources :

Example 31 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class QTestUtil method executeTestCommand.

private int executeTestCommand(final String command) {
    String commandName = command.trim().split("\\s+")[0];
    String commandArgs = command.trim().substring(commandName.length());
    if (commandArgs.endsWith(";")) {
        commandArgs = StringUtils.chop(commandArgs);
    }
    // replace ${hiveconf:hive.metastore.warehouse.dir} with actual dir if existed.
    // we only want the absolute path, so remove the header, such as hdfs://localhost:57145
    String wareHouseDir = SessionState.get().getConf().getVar(ConfVars.METASTOREWAREHOUSE).replaceAll("^[a-zA-Z]+://.*?:\\d+", "");
    commandArgs = commandArgs.replaceAll("\\$\\{hiveconf:hive\\.metastore\\.warehouse\\.dir\\}", wareHouseDir);
    if (SessionState.get() != null) {
        SessionState.get().setLastCommand(commandName + " " + commandArgs.trim());
    }
    enableTestOnlyCmd(SessionState.get().getConf());
    try {
        CommandProcessor proc = getTestCommand(commandName);
        if (proc != null) {
            CommandProcessorResponse response = proc.run(commandArgs.trim());
            int rc = response.getResponseCode();
            if (rc != 0) {
                SessionState.getConsole().printError(response.toString(), response.getException() != null ? Throwables.getStackTraceAsString(response.getException()) : "");
            }
            return rc;
        } else {
            throw new RuntimeException("Could not get CommandProcessor for command: " + commandName);
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not execute test command", e);
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) CommandProcessor(org.apache.hadoop.hive.ql.processors.CommandProcessor) SQLException(java.sql.SQLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) FileNotFoundException(java.io.FileNotFoundException) InvalidTableException(org.apache.hadoop.hive.ql.metadata.InvalidTableException)

Example 32 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestHCatLoaderEncryption method executeStatementOnDriver.

/**
 * Execute Hive CLI statement
 * @param cmd arbitrary statement to execute
 */
static void executeStatementOnDriver(String cmd, IDriver driver) throws Exception {
    LOG.debug("Executing: " + cmd);
    CommandProcessorResponse cpr = driver.run(cmd);
    if (cpr.getResponseCode() != 0) {
        throw new IOException("Failed to execute \"" + cmd + "\". Driver returned " + cpr.getResponseCode() + " Error: " + cpr.getErrorMessage());
    }
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) IOException(java.io.IOException)

Example 33 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestMsgBusConnection method runQuery.

private void runQuery(String query) throws Exception {
    CommandProcessorResponse cpr = driver.run(query);
    assertFalse(cpr.getMessage(), cpr.failed());
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)

Example 34 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestStreaming method runDDL.

private static boolean runDDL(IDriver driver, String sql) throws QueryFailedException {
    LOG.debug(sql);
    System.out.println(sql);
    // LOG.debug("Running Hive Query: "+ sql);
    CommandProcessorResponse cpr = driver.run(sql);
    if (cpr.getResponseCode() == 0) {
        return true;
    }
    LOG.error("Statement: " + sql + " failed: " + cpr);
    return false;
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)

Example 35 with CommandProcessorResponse

use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.

the class TestHiveTestEnvSetup method testMappingSameQuery.

@Test
public void testMappingSameQuery() throws ParseException, Exception {
    IDriver driver = createDriver();
    String query = "select sum(u*u),sum(u) from tu where u>1";
    CommandProcessorResponse ret = driver.run(query);
    assertEquals(0, ret.getResponseCode());
    List res = new ArrayList();
    driver.getFetchTask().fetch(res);
    System.out.println(res);
    assertEquals(1, res.size());
    assertEquals("13\t5", res.get(0));
}
Also used : CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) ArrayList(java.util.ArrayList) IDriver(org.apache.hadoop.hive.ql.IDriver) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)145 Test (org.junit.Test)92 ShowLocksResponseElement (org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement)24 HCatBaseTest (org.apache.hive.hcatalog.mapreduce.HCatBaseTest)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 AddDynamicPartitions (org.apache.hadoop.hive.metastore.api.AddDynamicPartitions)8 Database (org.apache.hadoop.hive.metastore.api.Database)8 HiveConf (org.apache.hadoop.hive.conf.HiveConf)7 Table (org.apache.hadoop.hive.metastore.api.Table)7 Path (org.apache.hadoop.fs.Path)6 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)6 PigServer (org.apache.pig.PigServer)5 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)4 Driver (org.apache.hadoop.hive.ql.Driver)4 IDriver (org.apache.hadoop.hive.ql.IDriver)4 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)4 PerfLogger (org.apache.hadoop.hive.ql.log.PerfLogger)4 ParseException (org.apache.hadoop.hive.ql.parse.ParseException)4 HashMap (java.util.HashMap)3