Search in sources :

Example 66 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.
 * @throws Exception
 */
@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")).build();
    client.createFunction(function);
    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 67 with Function

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

the class TestFunctions method testDropFunctionCaseInsensitive.

@Test
public void testDropFunctionCaseInsensitive() throws Exception {
    Function function = testFunctions[0];
    // Test in upper case
    client.dropFunction(function.getDbName().toUpperCase(), function.getFunctionName().toUpperCase());
    // Check if the function is really removed
    try {
        client.getFunction(function.getDbName(), function.getFunctionName());
        Assert.fail("Expected a NoSuchObjectException to be thrown");
    } catch (NoSuchObjectException exception) {
    // Expected exception
    }
    // Test in mixed case
    client.createFunction(function);
    client.dropFunction("DeFaUlt", "tEsT_FuncTION_tO_FinD_1");
    // Check if the function is really removed
    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) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 68 with Function

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

the class TestDatabases method testDropDatabaseWithFunction.

@Test(expected = InvalidOperationException.class)
public void testDropDatabaseWithFunction() throws Exception {
    Database database = testDatabases[0];
    Function testFunction = new FunctionBuilder().setDbName(database.getName()).setName("test_function").setClass("org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper").build();
    client.createFunction(testFunction);
    client.dropDatabase(database.getName(), true, true, false);
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) FunctionBuilder(org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder) Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 69 with Function

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

the class ObjectStore method getFunction.

@Override
public Function getFunction(String dbName, String funcName) throws MetaException {
    boolean commited = false;
    Function func = null;
    Query query = null;
    try {
        openTransaction();
        func = convertToFunction(getMFunction(dbName, funcName));
        commited = commitTransaction();
    } finally {
        rollbackAndCleanup(commited, query);
    }
    return func;
}
Also used : MFunction(org.apache.hadoop.hive.metastore.model.MFunction) Function(org.apache.hadoop.hive.metastore.api.Function) Query(javax.jdo.Query)

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