Search in sources :

Example 26 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testGetAllFunctions.

@Test
public void testGetAllFunctions() throws Exception {
    GetAllFunctionsResponse response = client.getAllFunctions();
    List<Function> allFunctions = response.getFunctions();
    Assert.assertEquals("All functions size", 4, allFunctions.size());
    for (Function function : allFunctions) {
        if (function.getDbName().equals(OTHER_DATABASE)) {
            Assert.assertEquals("Comparing functions", testFunctions[3], function);
        } else if (function.getFunctionName().equals("test_function_hidden_1")) {
            Assert.assertEquals("Comparing functions", testFunctions[2], function);
        } else if (function.getFunctionName().equals("test_function_to_find_2")) {
            Assert.assertEquals("Comparing functions", testFunctions[1], function);
        } else {
            Assert.assertEquals("Comparing functions", testFunctions[0], function);
        }
    }
    // Drop one function, see what remains
    client.dropFunction(testFunctions[1].getDbName(), testFunctions[1].getFunctionName());
    response = client.getAllFunctions();
    allFunctions = response.getFunctions();
    Assert.assertEquals("All functions size", 3, allFunctions.size());
    for (Function function : allFunctions) {
        if (function.getDbName().equals(OTHER_DATABASE)) {
            Assert.assertEquals("Comparing functions", testFunctions[3], function);
        } else if (function.getFunctionName().equals("test_function_hidden_1")) {
            Assert.assertEquals("Comparing functions", testFunctions[2], function);
        } else {
            Assert.assertEquals("Comparing functions", testFunctions[0], function);
        }
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) GetAllFunctionsResponse(org.apache.hadoop.hive.metastore.api.GetAllFunctionsResponse) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 27 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testAlterFunctionNullOwnerTypeInNew.

@Test
public void testAlterFunctionNullOwnerTypeInNew() throws Exception {
    Function newFunction = getNewFunction();
    newFunction.setOwnerType(null);
    try {
        client.alterFunction(DEFAULT_DATABASE, "test_function_to_find_2", newFunction);
        // TODO: Should have a check on the server side. Embedded metastore throws
        // NullPointerException, remote throws TTransportException
        Assert.fail("Expected an NullPointerException or TTransportException to be thrown");
    } catch (NullPointerException exception) {
    // Expected exception - Embedded MetaStore
    } catch (TTransportException exception) {
    // Expected exception - Remote MetaStore
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 28 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testCreateFunctionDefaultValues.

@Test
public void testCreateFunctionDefaultValues() throws Exception {
    Function function = new Function();
    function.setDbName(OTHER_DATABASE);
    function.setFunctionName("test_function");
    function.setClassName(TEST_FUNCTION_CLASS);
    function.setOwnerType(PrincipalType.USER);
    function.setFunctionType(FunctionType.JAVA);
    client.createFunction(function);
    Function createdFunction = client.getFunction(function.getDbName(), function.getFunctionName());
    Assert.assertNull("Comparing OwnerName", createdFunction.getOwnerName());
    Assert.assertEquals("Comparing ResourceUris", 0, createdFunction.getResourceUris().size());
    // The create time is set
    Assert.assertNotEquals("Comparing CreateTime", 0, createdFunction.getCreateTime());
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 29 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testGetFunctionCaseInsensitive.

@Test
public void testGetFunctionCaseInsensitive() throws Exception {
    Function function = testFunctions[0];
    // Test in upper case
    Function resultUpper = client.getFunction(function.getDbName().toUpperCase(), function.getFunctionName().toUpperCase());
    Assert.assertEquals("Comparing functions", function, resultUpper);
    // Test in mixed case
    Function resultMix = client.getFunction("DeFaUlt", "tEsT_FuncTION_tO_FinD_1");
    Assert.assertEquals("Comparing functions", function, resultMix);
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 30 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testAlterFunctionNullFunction.

@Test
public void testAlterFunctionNullFunction() throws Exception {
    Function originalFunction = testFunctions[1];
    try {
        client.alterFunction(DEFAULT_DATABASE, originalFunction.getFunctionName(), null);
        // TODO: Should have a check on the server side. Embedded metastore throws
        // NullPointerException, remote throws TTransportException
        Assert.fail("Expected an NullPointerException or TTransportException to be thrown");
    } catch (NullPointerException exception) {
    // Expected exception - Embedded MetaStore
    } catch (TTransportException exception) {
    // Expected exception - Remote MetaStore
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

Function (org.apache.hadoop.hive.metastore.api.Function)69 Test (org.junit.Test)47 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)38 ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)17 TTransportException (org.apache.thrift.transport.TTransportException)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)9 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)6 FunctionBuilder (org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder)6 Database (org.apache.hadoop.hive.metastore.api.Database)4 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)4 TApplicationException (org.apache.thrift.TApplicationException)4 TException (org.apache.thrift.TException)4 HashSet (java.util.HashSet)3 Path (org.apache.hadoop.fs.Path)3 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)3 Partition (org.apache.hadoop.hive.metastore.api.Partition)3 SQLException (java.sql.SQLException)2