use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.
the class ReExecDriver method compileAndRespond.
@Override
public CommandProcessorResponse compileAndRespond(String statement) throws CommandProcessorException {
currentQuery = statement;
checkHookConfig();
int compileIndex = 0;
int maxCompilations = 1 + coreDriver.getConf().getIntVar(ConfVars.HIVE_QUERY_MAX_RECOMPILATION_COUNT);
while (true) {
compileIndex++;
final int currentIndex = compileIndex;
plugins.forEach(p -> p.beforeCompile(currentIndex));
LOG.info("Compile #{} of query", compileIndex);
CommandProcessorResponse cpr = null;
CommandProcessorException cpe = null;
try {
cpr = coreDriver.compileAndRespond(statement);
} catch (CommandProcessorException e) {
cpe = e;
}
final boolean success = cpe == null;
plugins.forEach(p -> p.afterCompile(success));
// If the compilation was successful return the result
if (success) {
return cpr;
}
if (compileIndex >= maxCompilations || !plugins.stream().anyMatch(p -> p.shouldReCompile(currentIndex))) {
// If we do not have to recompile, return the last error
throw cpe;
}
// Prepare for the recompile and start the next loop
plugins.forEach(IReExecutionPlugin::prepareToReCompile);
}
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.
the class TestQueryHooks method testQueryLifeTimeWithParseHooksWithCompileError.
@Test
public void testQueryLifeTimeWithParseHooksWithCompileError() throws Exception {
String query = "select * from foo";
ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query);
QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class);
Driver driver = createDriver();
driver.getHookRunner().addLifeTimeHook(mockHook);
try {
driver.run(query);
Assert.fail("Expected compilation to fail");
} catch (CommandProcessorException e) {
// we expect to get here
}
verify(mockHook).beforeParse(argThat(argMatcher));
verify(mockHook).afterParse(argThat(argMatcher), eq(false));
verify(mockHook).beforeCompile(argThat(argMatcher));
verify(mockHook).afterCompile(argThat(argMatcher), eq(true));
verify(mockHook, never()).beforeExecution(any());
verify(mockHook, never()).afterExecution(any(), anyBoolean());
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.
the class TestQueryHooks method testQueryLifeTimeWithParseHooksWithParseError.
@Test
public void testQueryLifeTimeWithParseHooksWithParseError() throws Exception {
String query = "invalidquery";
ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query);
QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class);
Driver driver = createDriver();
driver.getHookRunner().addLifeTimeHook(mockHook);
try {
driver.run(query);
Assert.fail("Expected parsing to fail");
} catch (CommandProcessorException e) {
// we expect to get here
}
verify(mockHook).beforeParse(argThat(argMatcher));
verify(mockHook).afterParse(argThat(argMatcher), eq(true));
verify(mockHook, never()).beforeCompile(any());
verify(mockHook, never()).afterCompile(any(), anyBoolean());
verify(mockHook, never()).beforeExecution(any());
verify(mockHook, never()).afterExecution(any(), anyBoolean());
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.
the class TestHiveDecimalParse method testDecimalType6.
@Test
public void testDecimalType6() throws ParseException {
String query = "create table `dec` (d decimal(7,-1))";
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("extraneous input '-' expecting Number"));
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 testDecimalType3.
@Test
public void testDecimalType3() throws ParseException {
String query = "create table `dec` (d decimal(66,7))";
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 precision out of allowed range [1,38]"));
return;
}
Assert.assertTrue("Expected to receive an exception", false);
}
Aggregations