Search in sources :

Example 11 with ResourceUri

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")));
}
Also used : Path(org.apache.hadoop.fs.Path) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) ReplCopyTask(org.apache.hadoop.hive.ql.exec.ReplCopyTask) Task(org.apache.hadoop.hive.ql.exec.Task) ReplicationSpec(org.apache.hadoop.hive.ql.parse.ReplicationSpec) Configuration(org.apache.hadoop.conf.Configuration) HiveConf(org.apache.hadoop.hive.conf.HiveConf) URI(java.net.URI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with ResourceUri

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;
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) ArrayList(java.util.ArrayList) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject) PreCreateFunctionEvent(org.apache.hadoop.hive.metastore.events.PreCreateFunctionEvent)

Example 13 with ResourceUri

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);
    }
}
Also used : ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) Function(org.apache.hadoop.hive.metastore.api.Function) FunctionType(org.apache.hadoop.hive.metastore.api.FunctionType) ArrayList(java.util.ArrayList) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) ConfigValSecurityException(org.apache.hadoop.hive.metastore.api.ConfigValSecurityException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) IOException(java.io.IOException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test)

Example 14 with ResourceUri

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());
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) FunctionBuilder(org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder) Before(org.junit.Before)

Example 15 with ResourceUri

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
    }
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Function(org.apache.hadoop.hive.metastore.api.Function) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) FunctionBuilder(org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder) CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) Database(org.apache.hadoop.hive.metastore.api.Database) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Catalog(org.apache.hadoop.hive.metastore.api.Catalog) HashSet(java.util.HashSet) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)34 Function (org.apache.hadoop.hive.metastore.api.Function)22 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 Database (org.apache.hadoop.hive.metastore.api.Database)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)5 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)5 FunctionBuilder (org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder)5 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)5 IOException (java.io.IOException)4 URI (java.net.URI)4 HashSet (java.util.HashSet)4 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)3 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)3 Hive (org.apache.hadoop.hive.ql.metadata.Hive)3 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 Path (org.apache.hadoop.fs.Path)2 ConfigValSecurityException (org.apache.hadoop.hive.metastore.api.ConfigValSecurityException)2