use of org.apache.hadoop.hive.metastore.api.GetAllFunctionsResponse in project hive by apache.
the class TestFunctions method testGetAllFunctions.
@Test
public void testGetAllFunctions() throws Exception {
GetAllFunctionsResponse response = client.getAllFunctions();
List<Function> allFunctions = response.getFunctions();
Assert.assertEquals("All functions size", 4, allFunctions.size());
for (Function function : allFunctions) {
if (function.getDbName().equals(OTHER_DATABASE)) {
Assert.assertEquals("Comparing functions", testFunctions[3], function);
} else if (function.getFunctionName().equals("test_function_hidden_1")) {
Assert.assertEquals("Comparing functions", testFunctions[2], function);
} else if (function.getFunctionName().equals("test_function_to_find_2")) {
Assert.assertEquals("Comparing functions", testFunctions[1], function);
} else {
Assert.assertEquals("Comparing functions", testFunctions[0], function);
}
}
// Drop one function, see what remains
client.dropFunction(testFunctions[1].getDbName(), testFunctions[1].getFunctionName());
response = client.getAllFunctions();
allFunctions = response.getFunctions();
Assert.assertEquals("All functions size", 3, allFunctions.size());
for (Function function : allFunctions) {
if (function.getDbName().equals(OTHER_DATABASE)) {
Assert.assertEquals("Comparing functions", testFunctions[3], function);
} else if (function.getFunctionName().equals("test_function_hidden_1")) {
Assert.assertEquals("Comparing functions", testFunctions[2], function);
} else {
Assert.assertEquals("Comparing functions", testFunctions[0], function);
}
}
}
use of org.apache.hadoop.hive.metastore.api.GetAllFunctionsResponse 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);
}
}
Aggregations