Search in sources :

Example 26 with CommandProcessorException

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

the class CliDriver method processCmd1.

public CommandProcessorResponse processCmd1(String cmd) throws CommandProcessorException {
    CliSessionState ss = (CliSessionState) SessionState.get();
    String cmd_trimmed = HiveStringUtils.removeComments(cmd).trim();
    String[] tokens = tokenizeCmd(cmd_trimmed);
    CommandProcessorResponse response = new CommandProcessorResponse();
    if (cmd_trimmed.toLowerCase().equals("quit") || cmd_trimmed.toLowerCase().equals("exit")) {
        // if we have come this far - either the previous commands
        // are all successful or this is command line. in either case
        // this counts as a successful run
        ss.close();
        System.exit(0);
    } else if (tokens[0].equalsIgnoreCase("source")) {
        String cmd_1 = getFirstCmd(cmd_trimmed, tokens[0].length());
        cmd_1 = new VariableSubstitution(new HiveVariableSource() {

            @Override
            public Map<String, String> getHiveVariable() {
                return SessionState.get().getHiveVariables();
            }
        }).substitute(ss.getConf(), cmd_1);
        File sourceFile = new File(cmd_1);
        if (!sourceFile.isFile()) {
            console.printError("File: " + cmd_1 + " is not a file.");
            throw new CommandProcessorException(1);
        } else {
            try {
                response = processFile(cmd_1);
            } catch (IOException e) {
                console.printError("Failed processing file " + cmd_1 + " " + e.getLocalizedMessage(), stringifyException(e));
                throw new CommandProcessorException(1);
            }
        }
    } else if (cmd_trimmed.startsWith("!")) {
        // for shell commands, use unstripped command
        String shell_cmd = cmd.trim().substring(1);
        shell_cmd = new VariableSubstitution(new HiveVariableSource() {

            @Override
            public Map<String, String> getHiveVariable() {
                return SessionState.get().getHiveVariables();
            }
        }).substitute(ss.getConf(), shell_cmd);
        // shell_cmd = "/bin/bash -c \'" + shell_cmd + "\'";
        try {
            ShellCmdExecutor executor = new ShellCmdExecutor(shell_cmd, ss.out, ss.err);
            int responseCode = executor.execute();
            if (responseCode != 0) {
                console.printError("Command failed with exit code = " + response);
                ss.resetThreadName();
                throw new CommandProcessorException(responseCode);
            }
            response = new CommandProcessorResponse();
        } catch (Exception e) {
            console.printError("Exception raised from Shell command " + e.getLocalizedMessage(), stringifyException(e));
            throw new CommandProcessorException(1);
        }
    } else {
        // local mode
        try {
            try (CommandProcessor proc = CommandProcessorFactory.get(tokens, (HiveConf) conf)) {
                if (proc instanceof IDriver) {
                    // Let Driver strip comments using sql parser
                    response = processLocalCmd(cmd, proc, ss);
                } else {
                    response = processLocalCmd(cmd_trimmed, proc, ss);
                }
            }
        } catch (SQLException e) {
            console.printError("Failed processing command " + tokens[0] + " " + e.getLocalizedMessage(), org.apache.hadoop.util.StringUtils.stringifyException(e));
            throw new CommandProcessorException(1);
        } catch (CommandProcessorException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return response;
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) SQLException(java.sql.SQLException) VariableSubstitution(org.apache.hadoop.hive.conf.VariableSubstitution) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) HiveVariableSource(org.apache.hadoop.hive.conf.HiveVariableSource) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) StringUtils.stringifyException(org.apache.hadoop.util.StringUtils.stringifyException) CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) IOException(java.io.IOException) CommandProcessor(org.apache.hadoop.hive.ql.processors.CommandProcessor) IDriver(org.apache.hadoop.hive.ql.IDriver) File(java.io.File) Map(java.util.Map) ShellCmdExecutor(org.apache.hadoop.hive.common.cli.ShellCmdExecutor)

Example 27 with CommandProcessorException

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

the class TestHiveDecimalParse method testDecimalType8.

@Test
public void testDecimalType8() throws ParseException {
    String query = "create table `dec` (d decimal(7a))";
    Driver driver = createDriver();
    try {
        driver.compile(query, true, false);
    } catch (CommandProcessorException cpe) {
        Assert.assertTrue("Got " + cpe.getResponseCode() + ", expected not zero", cpe.getResponseCode() != 0);
        Assert.assertTrue(cpe.getMessage(), cpe.getMessage().contains("mismatched input '7a' expecting Number near '('"));
        return;
    }
    Assert.assertTrue("Expected to receive an exception", false);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Driver(org.apache.hadoop.hive.ql.Driver) Test(org.junit.Test)

Example 28 with CommandProcessorException

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

the class TestHiveDecimalParse method testDecimalType9.

@Test
public void testDecimalType9() throws ParseException {
    String query = "create table `dec` (d decimal(20,23))";
    Driver driver = createDriver();
    try {
        driver.compile(query, true, false);
    } catch (CommandProcessorException cpe) {
        Assert.assertTrue("Got " + cpe.getResponseCode() + ", expected not zero", cpe.getResponseCode() != 0);
        Assert.assertTrue(cpe.getMessage(), cpe.getMessage().contains("Decimal scale must be less than or equal to precision"));
        return;
    }
    Assert.assertTrue("Expected to receive an exception", false);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Driver(org.apache.hadoop.hive.ql.Driver) Test(org.junit.Test)

Example 29 with CommandProcessorException

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

the class TestHiveDecimalParse method testDecimalType7.

@Test
public void testDecimalType7() throws ParseException {
    String query = "create table `dec` (d decimal(7,33,4))";
    Driver driver = createDriver();
    try {
        driver.compile(query, true, false);
    } catch (CommandProcessorException cpe) {
        Assert.assertTrue("Got " + cpe.getResponseCode() + ", expected not zero", cpe.getResponseCode() != 0);
        Assert.assertTrue(cpe.getMessage(), cpe.getMessage().contains("missing ) at ',' near ',' in column name or constraint"));
        return;
    }
    Assert.assertTrue("Expected to receive an exception", false);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Driver(org.apache.hadoop.hive.ql.Driver) Test(org.junit.Test)

Example 30 with CommandProcessorException

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

the class TestHiveDecimalParse method testDecimalType5.

@Test
public void testDecimalType5() throws ParseException {
    String query = "create table `dec` (d decimal(7,33))";
    Driver driver = createDriver();
    try {
        driver.compile(query, true, false);
    } catch (CommandProcessorException cpe) {
        Assert.assertTrue("Got " + cpe.getResponseCode() + ", expected not zero", cpe.getResponseCode() != 0);
        Assert.assertTrue(cpe.getMessage(), cpe.getMessage().contains("Decimal scale must be less than or equal to precision"));
        return;
    }
    Assert.assertTrue("Expected to receive an exception", false);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Driver(org.apache.hadoop.hive.ql.Driver) Test(org.junit.Test)

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