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());
}
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();
}
}
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);
}
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);
}
}
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;
}
Aggregations