use of org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder in project hive by apache.
the class TestDatabases method testDropDatabaseWithFunctionCascade.
@Test
public void testDropDatabaseWithFunctionCascade() 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, true);
Assert.assertFalse("The directory should be removed", metaStore.isPathExists(new Path(database.getLocationUri())));
}
use of org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder in project hive by apache.
the class TestFunctions method testAlterFunctionCaseInsensitive.
@Test
public void testAlterFunctionCaseInsensitive() throws Exception {
Function newFunction = new FunctionBuilder().setDbName(OTHER_DATABASE).setName("test_function_2").setClass(TEST_FUNCTION_CLASS).build(metaStore.getConf());
Function originalFunction = testFunctions[1];
// Test in upper case
client.alterFunction(originalFunction.getDbName().toUpperCase(), originalFunction.getFunctionName().toUpperCase(), newFunction);
Function alteredFunction = client.getFunction(newFunction.getDbName(), newFunction.getFunctionName());
// The creation time is changed, so we do not check that
newFunction.setCreateTime(alteredFunction.getCreateTime());
Assert.assertEquals("Comparing functions", newFunction, alteredFunction);
try {
client.getFunction(originalFunction.getDbName(), originalFunction.getDbName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
// Test in mixed case
originalFunction = testFunctions[2];
newFunction.setFunctionName("test_function_3");
client.alterFunction("DeFaUlt", "tEsT_FuncTION_HiDDEn_1", newFunction);
alteredFunction = client.getFunction(newFunction.getDbName(), newFunction.getFunctionName());
// The creation time is changed, so we do not check that
newFunction.setCreateTime(alteredFunction.getCreateTime());
Assert.assertEquals("Comparing functions", newFunction, alteredFunction);
try {
client.getFunction(originalFunction.getDbName(), originalFunction.getDbName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
}
use of org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder 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.
*/
@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")).create(client, metaStore.getConf());
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.client.builder.FunctionBuilder in project hive by apache.
the class NonCatCallsWithCatalog method functions.
@Test
public void functions() throws TException {
String dbName = "functions_other_catalog_db";
Database db = new DatabaseBuilder().setName(dbName).build(conf);
db.unsetCatalogName();
client.createDatabase(db);
String functionName = "test_function";
Function function = new FunctionBuilder().inDb(db).setName(functionName).setClass(TEST_FUNCTION_CLASS).setFunctionType(FunctionType.JAVA).setOwnerType(PrincipalType.ROLE).setOwner("owner").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(conf);
function.unsetCatName();
client.createFunction(function);
Function createdFunction = client.getFunction(dbName, functionName);
// Creation time will be set by server and not us.
Assert.assertEquals(function.getFunctionName(), createdFunction.getFunctionName());
Assert.assertEquals(function.getDbName(), createdFunction.getDbName());
Assert.assertEquals(expectedCatalog(), createdFunction.getCatName());
Assert.assertEquals(function.getClassName(), createdFunction.getClassName());
Assert.assertEquals(function.getOwnerName(), createdFunction.getOwnerName());
Assert.assertEquals(function.getOwnerType(), createdFunction.getOwnerType());
Assert.assertEquals(function.getFunctionType(), createdFunction.getFunctionType());
Assert.assertEquals(function.getResourceUris(), createdFunction.getResourceUris());
String f2Name = "testy_function2";
Function f2 = new FunctionBuilder().inDb(db).setName(f2Name).setClass(TEST_FUNCTION_CLASS).build(conf);
f2.unsetCatName();
client.createFunction(f2);
Set<String> functions = new HashSet<>(client.getFunctions(dbName, "test*"));
Assert.assertEquals(2, functions.size());
Assert.assertTrue(functions.contains(functionName));
Assert.assertTrue(functions.contains(f2Name));
functions = new HashSet<>(client.getFunctions(dbName, "test_*"));
Assert.assertEquals(1, functions.size());
Assert.assertTrue(functions.contains(functionName));
Assert.assertFalse(functions.contains(f2Name));
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.client.builder.FunctionBuilder 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);
}
Aggregations