Search in sources :

Example 31 with Function

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

the class TestFunctions method testDropFunctionNoSuchFunctionInThisDatabase.

@Test(expected = NoSuchObjectException.class)
public void testDropFunctionNoSuchFunctionInThisDatabase() throws Exception {
    // Choosing the 2nd function, since the 1st one is duplicated in the dummy database
    Function function = testFunctions[1];
    client.dropFunction(OTHER_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 32 with Function

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

the class TestFunctions method testAlterFunctionNoSuchDatabaseInNew.

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

Example 33 with Function

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

the class TestHiveMetaStore method createFunction.

private void createFunction(String dbName, String funcName, String className, String ownerName, PrincipalType ownerType, int createTime, org.apache.hadoop.hive.metastore.api.FunctionType functionType, List<ResourceUri> resources) throws Exception {
    Function func = new Function(funcName, dbName, className, ownerName, ownerType, createTime, functionType, resources);
    client.createFunction(func);
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function)

Example 34 with Function

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

the class TestHiveMetaStore method testFunctionWithResources.

@Test
public void testFunctionWithResources() throws Exception {
    String dbName = "test_db2";
    String funcName = "test_func";
    String className = "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper";
    String owner = "test_owner";
    PrincipalType ownerType = PrincipalType.USER;
    int createTime = (int) (System.currentTimeMillis() / 1000);
    FunctionType funcType = FunctionType.JAVA;
    List<ResourceUri> resList = new ArrayList<>();
    resList.add(new ResourceUri(ResourceType.JAR, "hdfs:///tmp/jar1.jar"));
    resList.add(new ResourceUri(ResourceType.FILE, "hdfs:///tmp/file1.txt"));
    resList.add(new ResourceUri(ResourceType.ARCHIVE, "hdfs:///tmp/archive1.tgz"));
    try {
        cleanUp(dbName, null, null);
        createDb(dbName);
        createFunction(dbName, funcName, className, owner, ownerType, createTime, funcType, resList);
        // Try the different getters
        // getFunction()
        Function func = client.getFunction(dbName, funcName);
        assertEquals("function db name", dbName, func.getDbName());
        assertEquals("function name", funcName, func.getFunctionName());
        assertEquals("function class name", className, func.getClassName());
        assertEquals("function owner name", owner, func.getOwnerName());
        assertEquals("function owner type", PrincipalType.USER, func.getOwnerType());
        assertEquals("function type", funcType, func.getFunctionType());
        List<ResourceUri> resources = func.getResourceUris();
        assertEquals("Resource list size", resList.size(), resources.size());
        for (ResourceUri res : resources) {
            assertTrue("Matching resource " + res.getResourceType() + " " + res.getUri(), resList.indexOf(res) >= 0);
        }
        client.dropFunction(dbName, funcName);
    } catch (Exception e) {
        System.err.println(StringUtils.stringifyException(e));
        System.err.println("testConcurrentMetastores() failed.");
        throw e;
    } finally {
        silentDropDatabase(dbName);
    }
}
Also used : ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) Function(org.apache.hadoop.hive.metastore.api.Function) FunctionType(org.apache.hadoop.hive.metastore.api.FunctionType) ArrayList(java.util.ArrayList) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) ConfigValSecurityException(org.apache.hadoop.hive.metastore.api.ConfigValSecurityException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) IOException(java.io.IOException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test)

Example 35 with Function

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

the class Registry method getFunctionInfoFromMetastoreNoLock.

/**
 * This is called outside of the lock. Some of the methods that are called transitively by
 * this (e.g. addFunction) will take the lock again and then release it, which is ok.
 */
private FunctionInfo getFunctionInfoFromMetastoreNoLock(String functionName, HiveConf conf) {
    try {
        String[] parts = FunctionUtils.getQualifiedFunctionNameParts(functionName);
        Function func = Hive.get(conf).getFunction(parts[0].toLowerCase(), parts[1]);
        if (func == null) {
            return null;
        }
        // Found UDF in metastore - now add it to the function registry.
        FunctionInfo fi = registerPermanentFunction(functionName, func.getClassName(), true, FunctionTask.toFunctionResource(func.getResourceUris()));
        if (fi == null) {
            LOG.error(func.getClassName() + " is not a valid UDF class and was not registered");
            return null;
        }
        return fi;
    } catch (Throwable e) {
        LOG.info("Unable to look up " + functionName + " in metastore", e);
    }
    return null;
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function)

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