Search in sources :

Example 6 with FunctionBuilder

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())));
}
Also used : Path(org.apache.hadoop.fs.Path) Function(org.apache.hadoop.hive.metastore.api.Function) FunctionBuilder(org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder) Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 7 with FunctionBuilder

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
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) FunctionBuilder(org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 8 with FunctionBuilder

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
    }
}
Also used : 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) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 9 with FunctionBuilder

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
    }
}
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) Database(org.apache.hadoop.hive.metastore.api.Database) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with FunctionBuilder

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);
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) FunctionBuilder(org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder) Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

FunctionBuilder (org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder)10 Function (org.apache.hadoop.hive.metastore.api.Function)9 Test (org.junit.Test)9 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)7 Database (org.apache.hadoop.hive.metastore.api.Database)5 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)5 ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)5 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)4 HashSet (java.util.HashSet)2 CatalogBuilder (org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder)2 Path (org.apache.hadoop.fs.Path)1 Catalog (org.apache.hadoop.hive.metastore.api.Catalog)1 Partition (org.apache.hadoop.hive.metastore.api.Partition)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)1 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)1 Before (org.junit.Before)1