Search in sources :

Example 1 with CommandProcessorException

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

the class QTestUtil method initFromScript.

private void initFromScript() throws IOException {
    File scriptFile = new File(this.initScript);
    if (!scriptFile.isFile()) {
        LOG.info("No init script detected. Skipping");
        return;
    }
    String initCommands = FileUtils.readFileToString(scriptFile);
    LOG.info("Initial setup (" + initScript + "):\n" + initCommands);
    try {
        cliDriver.processLine(initCommands);
        LOG.info("Result from cliDrriver.processLine in createSources=0");
    } catch (CommandProcessorException e) {
        Assert.fail("Failed during createSources processLine with code=" + e.getResponseCode());
    }
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) File(java.io.File)

Example 2 with CommandProcessorException

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

the class QTestUtil method executeClientInternal.

private CommandProcessorResponse executeClientInternal(String commands) throws CommandProcessorException {
    List<String> cmds = CliDriver.splitSemiColon(commands);
    CommandProcessorResponse response = new CommandProcessorResponse();
    StringBuilder command = new StringBuilder();
    QTestSyntaxUtil qtsu = new QTestSyntaxUtil(this, conf, pd);
    qtsu.checkQFileSyntax(cmds);
    for (String oneCmd : cmds) {
        if (StringUtils.endsWith(oneCmd, "\\")) {
            command.append(StringUtils.chop(oneCmd) + "\\;");
            continue;
        } else {
            if (isHiveCommand(oneCmd)) {
                command.setLength(0);
            }
            command.append(oneCmd);
        }
        if (StringUtils.isBlank(command.toString())) {
            continue;
        }
        String strCommand = command.toString();
        try {
            if (isCommandUsedForTesting(strCommand)) {
                response = executeTestCommand(strCommand);
            } else {
                response = cliDriver.processLine(strCommand);
            }
        } catch (CommandProcessorException e) {
            if (!ignoreErrors()) {
                throw e;
            }
        }
        command.setLength(0);
    }
    if (SessionState.get() != null) {
        // reset
        SessionState.get().setLastCommand(null);
    }
    return response;
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)

Example 3 with CommandProcessorException

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

the class QTestUtil method executeTestCommand.

private CommandProcessorResponse executeTestCommand(String command) throws CommandProcessorException {
    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) {
            try {
                CommandProcessorResponse response = proc.run(commandArgs.trim());
                return response;
            } catch (CommandProcessorException e) {
                SessionState.getConsole().printError(e.toString(), e.getCause() != null ? Throwables.getStackTraceAsString(e.getCause()) : "");
                throw e;
            }
        } 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 : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) CommandProcessor(org.apache.hadoop.hive.ql.processors.CommandProcessor) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) FileNotFoundException(java.io.FileNotFoundException) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) SQLException(java.sql.SQLException) IOException(java.io.IOException) InvalidTableException(org.apache.hadoop.hive.ql.metadata.InvalidTableException)

Example 4 with CommandProcessorException

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

the class CoreHBaseCliDriver method runTest.

@Override
public void runTest(String tname, String fname, String fpath) {
    long startTime = System.currentTimeMillis();
    try {
        System.err.println("Begin query: " + fname);
        qt.setInputFile(fpath);
        qt.cliInit();
        try {
            qt.executeClient();
        } catch (CommandProcessorException e) {
            qt.failedQuery(e.getCause(), e.getResponseCode(), fname, null);
        }
        QTestProcessExecResult result = qt.checkCliDriverResults();
        if (result.getReturnCode() != 0) {
            qt.failedDiff(result.getReturnCode(), fname, result.getCapturedOutput());
        }
    } catch (Exception e) {
        qt.failedWithException(e, fname, null);
    }
    long elapsedTime = System.currentTimeMillis() - startTime;
    System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime / 1000 + "s");
    assertTrue("Test passed", true);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) QTestProcessExecResult(org.apache.hadoop.hive.ql.QTestProcessExecResult) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException)

Example 5 with CommandProcessorException

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

the class CoreKuduCliDriver method runTest.

@Override
public void runTest(String tname, String fname, String fpath) {
    long startTime = System.currentTimeMillis();
    try {
        System.err.println("Begin query: " + fname);
        qt.setInputFile(fpath);
        qt.cliInit();
        try {
            qt.executeClient();
        } catch (CommandProcessorException e) {
            qt.failedQuery(e.getCause(), e.getResponseCode(), fname, null);
        }
        QTestProcessExecResult result = qt.checkCliDriverResults();
        if (result.getReturnCode() != 0) {
            qt.failedDiff(result.getReturnCode(), fname, result.getCapturedOutput());
        }
        qt.clearPostTestEffects();
    } catch (Exception e) {
        qt.failedWithException(e, fname, null);
    }
    long elapsedTime = System.currentTimeMillis() - startTime;
    System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime / 1000 + "s");
    assertTrue("Test passed", true);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) QTestProcessExecResult(org.apache.hadoop.hive.ql.QTestProcessExecResult) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException)

Aggregations

CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)85 Test (org.junit.Test)42 IOException (java.io.IOException)14 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)14 Driver (org.apache.hadoop.hive.ql.Driver)12 ArrayList (java.util.ArrayList)10 HiveConf (org.apache.hadoop.hive.conf.HiveConf)10 QTestProcessExecResult (org.apache.hadoop.hive.ql.QTestProcessExecResult)9 Path (org.apache.hadoop.fs.Path)8 FileSystem (org.apache.hadoop.fs.FileSystem)7 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)6 File (java.io.File)5 IDriver (org.apache.hadoop.hive.ql.IDriver)5 FileNotFoundException (java.io.FileNotFoundException)4 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Map (java.util.Map)3 Nullable (javax.annotation.Nullable)3 Database (org.apache.hadoop.hive.metastore.api.Database)3