Search in sources :

Example 81 with Function

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

the class TestFunctions method testCreateGetDeleteFunction.

/**
 * This test creates and queries a function and then drops it. Good for testing the happy path.
 */
@Test
public void testCreateGetDeleteFunction() throws Exception {
    Function function = new FunctionBuilder().setDbName(OTHER_DATABASE).setName("test_function").setClass(TEST_FUNCTION_CLASS).setFunctionType(FunctionType.JAVA).setOwnerType(PrincipalType.ROLE).setOwner("owner").setCreateTime(100).addResourceUri(new ResourceUri(ResourceType.JAR, "hdfs:///tmp/jar1.jar")).addResourceUri(new ResourceUri(ResourceType.FILE, "hdfs:///tmp/file1.txt")).addResourceUri(new ResourceUri(ResourceType.ARCHIVE, "hdfs:///tmp/archive1.tgz")).create(client, metaStore.getConf());
    Function createdFunction = client.getFunction(function.getDbName(), function.getFunctionName());
    // The createTime will be set on the server side, so the comparison should skip it
    function.setCreateTime(createdFunction.getCreateTime());
    Assert.assertEquals("Comparing functions", function, createdFunction);
    client.dropFunction(function.getDbName(), function.getFunctionName());
    try {
        client.getFunction(function.getDbName(), function.getFunctionName());
        Assert.fail("Expected a NoSuchObjectException to be thrown");
    } catch (NoSuchObjectException exception) {
    // Expected exception
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) FunctionBuilder(org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 82 with Function

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

the class TestFunctions method testDropFunctionNoSuchDatabase.

@Test(expected = NoSuchObjectException.class)
public void testDropFunctionNoSuchDatabase() throws Exception {
    // Choosing the 2nd function, since the 1st one is duplicated in the dummy database
    Function function = testFunctions[1];
    client.dropFunction("no_such_database", function.getFunctionName());
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 83 with Function

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

the class TestFunctions method testGetFunctionNoSuchFunction.

@Test(expected = NoSuchObjectException.class)
public void testGetFunctionNoSuchFunction() throws Exception {
    // Choosing the 2nd function, since the 1st one is duplicated in the dummy database
    Function function = testFunctions[1];
    client.getFunction(function.getDbName(), "no_such_function");
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 84 with Function

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

the class TestFunctions method testAlterFunctionEmptyNameInNew.

@Test(expected = MetaException.class)
public void testAlterFunctionEmptyNameInNew() throws Exception {
    Function newFunction = getNewFunction();
    newFunction.setFunctionName("");
    client.alterFunction(DEFAULT_DATABASE, "test_function_to_find_2", newFunction);
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 85 with Function

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

the class TestFunctions method testAlterFunctionInvalidNameInNew.

@Test(expected = MetaException.class)
public void testAlterFunctionInvalidNameInNew() throws Exception {
    Function newFunction = getNewFunction();
    newFunction.setFunctionName("test_function_2;");
    client.alterFunction(DEFAULT_DATABASE, "test_function_to_find_2", newFunction);
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

Function (org.apache.hadoop.hive.metastore.api.Function)90 Test (org.junit.Test)54 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)40 ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)22 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)13 ArrayList (java.util.ArrayList)12 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)11 IOException (java.io.IOException)10 FunctionBuilder (org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder)9 Database (org.apache.hadoop.hive.metastore.api.Database)7 HashSet (java.util.HashSet)6 Path (org.apache.hadoop.fs.Path)6 TException (org.apache.thrift.TException)6 HiveConf (org.apache.hadoop.hive.conf.HiveConf)5 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)4 Partition (org.apache.hadoop.hive.metastore.api.Partition)4 Before (org.junit.Before)4 List (java.util.List)3 FunctionType (org.apache.hadoop.hive.metastore.api.FunctionType)3 GetAllFunctionsResponse (org.apache.hadoop.hive.metastore.api.GetAllFunctionsResponse)3