use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class TestFunctions method testCreateGetDeleteFunction.
/**
* This test creates and queries a function and then drops it. Good for testing the happy path.
* @throws Exception
*/
@Test
public void testCreateGetDeleteFunction() throws Exception {
Function function = new FunctionBuilder().setDbName(OTHER_DATABASE).setName("test_function").setClass(TEST_FUNCTION_CLASS).setFunctionType(FunctionType.JAVA).setOwnerType(PrincipalType.ROLE).setOwner("owner").setCreateTime(100).addResourceUri(new ResourceUri(ResourceType.JAR, "hdfs:///tmp/jar1.jar")).addResourceUri(new ResourceUri(ResourceType.FILE, "hdfs:///tmp/file1.txt")).addResourceUri(new ResourceUri(ResourceType.ARCHIVE, "hdfs:///tmp/archive1.tgz")).build();
client.createFunction(function);
Function createdFunction = client.getFunction(function.getDbName(), function.getFunctionName());
// The createTime will be set on the server side, so the comparison should skip it
function.setCreateTime(createdFunction.getCreateTime());
Assert.assertEquals("Comparing functions", function, createdFunction);
client.dropFunction(function.getDbName(), function.getFunctionName());
try {
client.getFunction(function.getDbName(), function.getFunctionName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
}
use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class TestFunctions method testDropFunctionCaseInsensitive.
@Test
public void testDropFunctionCaseInsensitive() throws Exception {
Function function = testFunctions[0];
// Test in upper case
client.dropFunction(function.getDbName().toUpperCase(), function.getFunctionName().toUpperCase());
// Check if the function is really removed
try {
client.getFunction(function.getDbName(), function.getFunctionName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
// Test in mixed case
client.createFunction(function);
client.dropFunction("DeFaUlt", "tEsT_FuncTION_tO_FinD_1");
// Check if the function is really removed
try {
client.getFunction(function.getDbName(), function.getFunctionName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
}
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").build();
client.createFunction(testFunction);
client.dropDatabase(database.getName(), true, true, false);
}
use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.
the class ObjectStore method getFunction.
@Override
public Function getFunction(String dbName, String funcName) throws MetaException {
boolean commited = false;
Function func = null;
Query query = null;
try {
openTransaction();
func = convertToFunction(getMFunction(dbName, funcName));
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return func;
}
Aggregations