use of org.apache.hadoop.hive.metastore.api.ResourceUri in project hive by apache.
the class TestPrimaryToReplicaResourceFunction method createDestinationPath.
@Test
public void createDestinationPath() throws IOException, SemanticException, URISyntaxException {
mockStatic(FileSystem.class);
when(FileSystem.get(any(Configuration.class))).thenReturn(mockFs);
when(FileSystem.get(any(URI.class), any(Configuration.class))).thenReturn(mockFs);
when(mockFs.getScheme()).thenReturn("hdfs");
when(mockFs.getUri()).thenReturn(new URI("hdfs", "somehost:9000", null, null, null));
mockStatic(System.class);
// when(System.nanoTime()).thenReturn(Long.MAX_VALUE);
when(functionObj.getFunctionName()).thenReturn("someFunctionName");
mockStatic(ReplCopyTask.class);
Task mock = mock(Task.class);
when(ReplCopyTask.getLoadCopyTask(any(ReplicationSpec.class), any(Path.class), any(Path.class), any(HiveConf.class), any(), any())).thenReturn(mock);
ResourceUri resourceUri = function.destinationResourceUri(new ResourceUri(ResourceType.JAR, "hdfs://localhost:9000/user/someplace/ab.jar#e094828883"));
assertThat(resourceUri.getUri(), is(equalTo("hdfs://somehost:9000/someBasePath/withADir/replicadbname/somefunctionname/" + String.valueOf(0L) + "/ab.jar")));
}
use of org.apache.hadoop.hive.metastore.api.ResourceUri in project hive by apache.
the class CreateFunctionEvent method getOutputHObjs.
private List<HivePrivilegeObject> getOutputHObjs() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> CreateFunctionEvent.getOutputHObjs()");
}
List<HivePrivilegeObject> ret = new ArrayList<>();
PreCreateFunctionEvent event = (PreCreateFunctionEvent) preEventContext;
Function function = event.getFunction();
List<ResourceUri> uris = function.getResourceUris();
ret.add(new HivePrivilegeObject(HivePrivilegeObject.HivePrivilegeObjectType.DATABASE, function.getDbName(), null, null, null, HivePrivilegeObject.HivePrivObjectActionType.OTHER, null, null, function.getOwnerName(), function.getOwnerType()));
ret.add(new HivePrivilegeObject(HivePrivilegeObject.HivePrivilegeObjectType.FUNCTION, function.getDbName(), function.getFunctionName(), null, null, HivePrivilegeObject.HivePrivObjectActionType.OTHER, null, function.getClassName(), function.getOwnerName(), function.getOwnerType()));
if (uris != null && !uris.isEmpty()) {
for (ResourceUri uri : uris) {
ret.add(new HivePrivilegeObject(HivePrivilegeObject.HivePrivilegeObjectType.DFS_URI, null, uri.getUri()));
}
}
COMMAND_STR = buildCommandString(function);
if (LOG.isDebugEnabled()) {
LOG.debug("<== CreateFunctionEvent.getOutputHObjs(): ret=" + ret);
}
return ret;
}
use of org.apache.hadoop.hive.metastore.api.ResourceUri 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.ResourceUri in project hive by apache.
the class TestFunctions method setUp.
@Before
public void setUp() throws Exception {
// Get new client
client = metaStore.getClient();
// Clean up the database
client.dropDatabase(OTHER_DATABASE, true, true, true);
for (Function function : client.getAllFunctions().getFunctions()) {
client.dropFunction(function.getDbName(), function.getFunctionName());
}
testFunctions[0] = new FunctionBuilder().setDbName(DEFAULT_DATABASE).setName("test_function_to_find_1").setClass(TEST_FUNCTION_CLASS).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(metaStore.getConf());
testFunctions[1] = new FunctionBuilder().setDbName(DEFAULT_DATABASE).setName("test_function_to_find_2").setClass(TEST_FUNCTION_CLASS).build(metaStore.getConf());
testFunctions[2] = new FunctionBuilder().setDbName(DEFAULT_DATABASE).setName("test_function_hidden_1").setClass(TEST_FUNCTION_CLASS).build(metaStore.getConf());
new DatabaseBuilder().setName(OTHER_DATABASE).create(client, metaStore.getConf());
testFunctions[3] = new FunctionBuilder().setDbName(OTHER_DATABASE).setName("test_function_to_find_1").setClass(TEST_FUNCTION_CLASS).build(metaStore.getConf());
// Create the functions, and reload them from the MetaStore
for (int i = 0; i < testFunctions.length; i++) {
client.createFunction(testFunctions[i]);
testFunctions[i] = client.getFunction(testFunctions[i].getDbName(), testFunctions[i].getFunctionName());
}
}
use of org.apache.hadoop.hive.metastore.api.ResourceUri in project hive by apache.
the class TestFunctions method otherCatalog.
@Test
public void otherCatalog() throws TException {
String catName = "functions_catalog";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "functions_other_catalog_db";
Database db = new DatabaseBuilder().setCatalogName(catName).setName(dbName).create(client, metaStore.getConf());
String functionName = "test_function";
Function function = new FunctionBuilder().inDb(db).setName(functionName).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(catName, dbName, functionName);
// 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);
String f2Name = "testy_function2";
Function f2 = new FunctionBuilder().inDb(db).setName(f2Name).setClass(TEST_FUNCTION_CLASS).create(client, metaStore.getConf());
Set<String> functions = new HashSet<>(client.getFunctions(catName, dbName, "test*"));
Assert.assertEquals(2, functions.size());
Assert.assertTrue(functions.contains(functionName));
Assert.assertTrue(functions.contains(f2Name));
functions = new HashSet<>(client.getFunctions(catName, dbName, "test_*"));
Assert.assertEquals(1, functions.size());
Assert.assertTrue(functions.contains(functionName));
Assert.assertFalse(functions.contains(f2Name));
client.dropFunction(function.getCatName(), function.getDbName(), function.getFunctionName());
try {
client.getFunction(function.getCatName(), function.getDbName(), function.getFunctionName());
Assert.fail("Expected a NoSuchObjectException to be thrown");
} catch (NoSuchObjectException exception) {
// Expected exception
}
}
Aggregations