Search in sources :

Example 86 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").create(client, metaStore.getConf());
    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 87 with Function

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

the class TestHiveMetaStore method testSimpleFunction.

@Test
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) 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) 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) Test(org.junit.Test)

Example 88 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 catName, String dbName, String funcName) throws MetaException {
    boolean commited = false;
    Function func = null;
    Query query = null;
    try {
        openTransaction();
        func = convertToFunction(getMFunction(catName, 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) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery)

Example 89 with Function

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

the class ObjectStore method convertToFunction.

private Function convertToFunction(MFunction mfunc) {
    if (mfunc == null) {
        return null;
    }
    Function func = new Function(mfunc.getFunctionName(), mfunc.getDatabase().getName(), mfunc.getClassName(), mfunc.getOwnerName(), PrincipalType.valueOf(mfunc.getOwnerType()), mfunc.getCreateTime(), FunctionType.findByValue(mfunc.getFunctionType()), convertToResourceUriList(mfunc.getResourceUris()));
    func.setCatName(mfunc.getDatabase().getCatalogName());
    return func;
}
Also used : MFunction(org.apache.hadoop.hive.metastore.model.MFunction) Function(org.apache.hadoop.hive.metastore.api.Function)

Example 90 with Function

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

the class HiveCatalog method alterFunction.

@Override
public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
    checkNotNull(functionPath, "functionPath cannot be null");
    checkNotNull(newFunction, "newFunction cannot be null");
    try {
        // check if function exists
        getFunction(functionPath);
        Function hiveFunction;
        if (newFunction instanceof CatalogFunctionImpl) {
            hiveFunction = instantiateHiveFunction(functionPath, newFunction);
        } else {
            throw new CatalogException(String.format("Unsupported catalog function type %s", newFunction.getClass().getName()));
        }
        client.alterFunction(functionPath.getDatabaseName(), functionPath.getObjectName(), hiveFunction);
    } catch (FunctionNotExistException e) {
        if (!ignoreIfNotExists) {
            throw e;
        }
    } catch (TException e) {
        throw new CatalogException(String.format("Failed to alter function %s", functionPath.getFullName()), e);
    }
}
Also used : FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) TException(org.apache.thrift.TException) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) Function(org.apache.hadoop.hive.metastore.api.Function) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl)

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