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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations