Search in sources :

Example 6 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestCTTAS method testTemporaryTablesInViewExpansionLogic.

@Test(expected = UserRemoteException.class)
public void testTemporaryTablesInViewExpansionLogic() throws Exception {
    String tableName = "table_for_expansion_logic_test";
    String viewName = "view_for_expansion_logic_test";
    test("use %s", TEMP_SCHEMA);
    test("create table %s as select 'TABLE' as c1 from (values(1))", tableName);
    test("create view %s as select * from %s", viewName, tableName);
    testBuilder().sqlQuery("select * from %s", viewName).unOrdered().baselineColumns("c1").baselineValues("TABLE").go();
    test("drop table %s", tableName);
    test("create temporary table %s as select 'TEMP' as c1 from (values(1))", tableName);
    try {
        test("select * from %s", viewName);
    } catch (UserRemoteException e) {
        assertThat(e.getMessage(), containsString(String.format("VALIDATION ERROR: Temporary tables usage is disallowed. Used temporary table name: [%s]", tableName)));
        throw e;
    }
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 7 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestCTTAS method testCreateWhenTemporaryTableExistsWithoutSchema.

@Test(expected = UserRemoteException.class)
public void testCreateWhenTemporaryTableExistsWithoutSchema() throws Exception {
    String temporaryTableName = "temporary_table_exists_without_schema";
    try {
        test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName);
        test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName);
    } catch (UserRemoteException e) {
        assertThat(e.getMessage(), containsString(String.format("VALIDATION ERROR: A table or view with given name [%s]" + " already exists in schema [%s]", temporaryTableName, TEMP_SCHEMA)));
        throw e;
    }
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 8 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestDynamicUDFSupport method testDropFunction.

@Test
public void testDropFunction() throws Exception {
    copyDefaultJarsToStagingArea();
    test("create function using jar '%s'", default_binary_name);
    test("select custom_lower('A') from (values(1))");
    Path localUdfDirPath = Deencapsulation.getField(getDrillbitContext().getFunctionImplementationRegistry(), "localUdfDir");
    File localUdfDir = new File(localUdfDirPath.toUri().getPath());
    assertTrue("Binary should exist in local udf directory", new File(localUdfDir, default_binary_name).exists());
    assertTrue("Source should exist in local udf directory", new File(localUdfDir, default_source_name).exists());
    String summary = "The following UDFs in jar %s have been unregistered:\n" + "[custom_lower(VARCHAR-REQUIRED)]";
    testBuilder().sqlQuery("drop function using jar '%s'", default_binary_name).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format(summary, default_binary_name)).go();
    try {
        test("select custom_lower('A') from (values(1))");
    } catch (UserRemoteException e) {
        assertThat(e.getMessage(), containsString("No match found for function signature custom_lower(<CHARACTER>)"));
    }
    RemoteFunctionRegistry remoteFunctionRegistry = getDrillbitContext().getRemoteFunctionRegistry();
    assertEquals("Remote registry should be empty", remoteFunctionRegistry.getRegistry(new DataChangeVersion()).getJarList().size(), 0);
    FileSystem fs = remoteFunctionRegistry.getFs();
    assertFalse("Binary should not be present in registry area", fs.exists(new Path(remoteFunctionRegistry.getRegistryArea(), default_binary_name)));
    assertFalse("Source should not be present in registry area", fs.exists(new Path(remoteFunctionRegistry.getRegistryArea(), default_source_name)));
    assertFalse("Binary should not be present in local udf directory", new File(localUdfDir, default_binary_name).exists());
    assertFalse("Source should not be present in local udf directory", new File(localUdfDir, default_source_name).exists());
}
Also used : Path(org.apache.hadoop.fs.Path) RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) FileSystem(org.apache.hadoop.fs.FileSystem) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) File(java.io.File) Test(org.junit.Test)

Example 9 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestDynamicUDFSupport method testLazyInitNoReload.

@Test
public void testLazyInitNoReload() throws Exception {
    FunctionImplementationRegistry functionImplementationRegistry = spyFunctionImplementationRegistry();
    copyDefaultJarsToStagingArea();
    test("create function using jar '%s'", default_binary_name);
    doAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            boolean result = (boolean) invocation.callRealMethod();
            assertTrue("syncWithRemoteRegistry() should return true", result);
            return true;
        }
    }).doAnswer(new Answer() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            boolean result = (boolean) invocation.callRealMethod();
            assertFalse("syncWithRemoteRegistry() should return false", result);
            return false;
        }
    }).when(functionImplementationRegistry).syncWithRemoteRegistry(anyLong());
    test("select custom_lower('A') from (values(1))");
    try {
        test("select unknown_lower('A') from (values(1))");
    } catch (UserRemoteException e) {
        assertThat(e.getMessage(), containsString("No match found for function signature unknown_lower(<CHARACTER>)"));
    }
    verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyLong());
    LocalFunctionRegistry localFunctionRegistry = Deencapsulation.getField(functionImplementationRegistry, "localFunctionRegistry");
    assertEquals("Sync function registry version should match", 1L, localFunctionRegistry.getVersion());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) Test(org.junit.Test)

Example 10 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestHiveStorage method testIncorrectHeaderFooterProperty.

// DRILL-3688
@Test
public void testIncorrectHeaderFooterProperty() throws Exception {
    Map<String, String> testData = ImmutableMap.<String, String>builder().put("hive.skipper.kv_incorrect_skip_header", "skip.header.line.count").put("hive.skipper.kv_incorrect_skip_footer", "skip.footer.line.count").build();
    String query = "select * from %s";
    String exceptionMessage = "Hive table property %s value 'A' is non-numeric";
    for (Map.Entry<String, String> entry : testData.entrySet()) {
        try {
            test(String.format(query, entry.getKey()));
        } catch (UserRemoteException e) {
            assertThat(e.getMessage(), containsString(String.format(exceptionMessage, entry.getValue())));
        }
    }
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)25 Test (org.junit.Test)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 File (java.io.File)2 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)2 QueryState (org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)2 Path (org.apache.hadoop.fs.Path)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 UserException (org.apache.drill.common.exceptions.UserException)1 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)1 LocalFunctionRegistry (org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry)1 RemoteFunctionRegistry (org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry)1 QueryResult (org.apache.drill.exec.proto.UserBitShared.QueryResult)1 RpcException (org.apache.drill.exec.rpc.RpcException)1 DataChangeVersion (org.apache.drill.exec.store.sys.store.DataChangeVersion)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1