Search in sources :

Example 1 with FunctionType

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

the class TestHiveMetaStore method testFunctionWithResources.

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<ResourceUri>();
    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) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) 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) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 2 with FunctionType

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

the class TestHiveMetaStore method testSimpleFunction.

public void testSimpleFunction() throws Exception {
    String dbName = "test_db";
    String funcName = "test_func";
    String className = "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper";
    String owner = "test_owner";
    final int N_FUNCTIONS = 5;
    PrincipalType ownerType = PrincipalType.USER;
    int createTime = (int) (System.currentTimeMillis() / 1000);
    FunctionType funcType = FunctionType.JAVA;
    try {
        cleanUp(dbName, null, null);
        for (Function f : client.getAllFunctions().getFunctions()) {
            client.dropFunction(f.getDbName(), f.getFunctionName());
        }
        createDb(dbName);
        for (int i = 0; i < N_FUNCTIONS; i++) {
            createFunction(dbName, funcName + "_" + i, className, owner, ownerType, createTime, funcType, null);
        }
        // Try the different getters
        // getFunction()
        Function func = client.getFunction(dbName, funcName + "_0");
        assertEquals("function db name", dbName, func.getDbName());
        assertEquals("function name", funcName + "_0", 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();
        assertTrue("function resources", resources == null || resources.size() == 0);
        boolean gotException = false;
        try {
            func = client.getFunction(dbName, "nonexistent_func");
        } catch (NoSuchObjectException e) {
            // expected failure
            gotException = true;
        }
        assertEquals(true, gotException);
        // getAllFunctions()
        GetAllFunctionsResponse response = client.getAllFunctions();
        List<Function> allFunctions = response.getFunctions();
        assertEquals(N_FUNCTIONS, allFunctions.size());
        assertEquals(funcName + "_3", allFunctions.get(3).getFunctionName());
        // getFunctions()
        List<String> funcs = client.getFunctions(dbName, "*_func_*");
        assertEquals(N_FUNCTIONS, funcs.size());
        assertEquals(funcName + "_0", funcs.get(0));
        funcs = client.getFunctions(dbName, "nonexistent_func");
        assertEquals(0, funcs.size());
        // dropFunction()
        for (int i = 0; i < N_FUNCTIONS; i++) {
            client.dropFunction(dbName, funcName + "_" + i);
        }
        // Confirm that the function is now gone
        funcs = client.getFunctions(dbName, funcName);
        assertEquals(0, funcs.size());
        response = client.getAllFunctions();
        allFunctions = response.getFunctions();
        assertEquals(0, allFunctions.size());
    } 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) FunctionType(org.apache.hadoop.hive.metastore.api.FunctionType) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) 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) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Function(org.apache.hadoop.hive.metastore.api.Function) GetAllFunctionsResponse(org.apache.hadoop.hive.metastore.api.GetAllFunctionsResponse) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Aggregations

SQLException (java.sql.SQLException)2 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)2 ConfigValSecurityException (org.apache.hadoop.hive.metastore.api.ConfigValSecurityException)2 Function (org.apache.hadoop.hive.metastore.api.Function)2 FunctionType (org.apache.hadoop.hive.metastore.api.FunctionType)2 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)2 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)2 ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)2 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)2 TException (org.apache.thrift.TException)2 ArrayList (java.util.ArrayList)1 GetAllFunctionsResponse (org.apache.hadoop.hive.metastore.api.GetAllFunctionsResponse)1