Search in sources :

Example 66 with CommandProcessorException

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);
    }
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)

Example 67 with CommandProcessorException

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());
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Driver(org.apache.hadoop.hive.ql.Driver) Test(org.junit.Test)

Example 68 with CommandProcessorException

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());
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Driver(org.apache.hadoop.hive.ql.Driver) Test(org.junit.Test)

Example 69 with CommandProcessorException

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);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Driver(org.apache.hadoop.hive.ql.Driver) Test(org.junit.Test)

Example 70 with CommandProcessorException

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