Search in sources :

Example 11 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testAlterFunction.

@Test
public void testAlterFunction() throws Exception {
    Function newFunction = new FunctionBuilder().setDbName(OTHER_DATABASE).setName("test_function_2").setOwner("Owner2").setOwnerType(PrincipalType.GROUP).setClass("org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper2").setFunctionType(FunctionType.JAVA).build();
    client.alterFunction(testFunctions[0].getDbName(), testFunctions[0].getFunctionName(), newFunction);
    Function alteredFunction = client.getFunction(newFunction.getDbName(), newFunction.getFunctionName());
    // Currently this method only sets
    // - Database
    // - FunctionName
    // - OwnerName
    // - OwnerType
    // - ClassName
    // - FunctionType
    Assert.assertEquals("Comparing Database", newFunction.getDbName(), alteredFunction.getDbName());
    Assert.assertEquals("Comparing FunctionName", newFunction.getFunctionName(), alteredFunction.getFunctionName());
    Assert.assertEquals("Comparing OwnerName", newFunction.getOwnerName(), alteredFunction.getOwnerName());
    Assert.assertEquals("Comparing OwnerType", newFunction.getOwnerType(), alteredFunction.getOwnerType());
    Assert.assertEquals("Comparing ClassName", newFunction.getClassName(), alteredFunction.getClassName());
    Assert.assertEquals("Comparing FunctionType", newFunction.getFunctionType(), alteredFunction.getFunctionType());
    try {
        client.getFunction(testFunctions[0].getDbName(), testFunctions[0].getDbName());
        Assert.fail("Expected a NoSuchObjectException to be thrown");
    } catch (NoSuchObjectException exception) {
    // Expected exception
    }
    // Test that not changing the database and the function name, but only other parameters, like
    // function class will not cause Exception
    newFunction = testFunctions[1].deepCopy();
    newFunction.setClassName("NewClassName");
    client.alterFunction(testFunctions[1].getDbName(), testFunctions[1].getFunctionName(), newFunction);
    alteredFunction = client.getFunction(newFunction.getDbName(), newFunction.getFunctionName());
    Assert.assertEquals("Comparing functions", newFunction, alteredFunction);
}
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 12 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testAlterFunctionNullClassInNew.

@Test
public void testAlterFunctionNullClassInNew() throws Exception {
    Function newFunction = getNewFunction();
    newFunction.setClassName(null);
    try {
        client.alterFunction(DEFAULT_DATABASE, "test_function_to_find_2", newFunction);
        // TODO: Should have a check on the server side. Embedded metastore throws
        // InvalidObjectException, remote throws TApplicationException
        Assert.fail("Expected an InvalidObjectException or TApplicationException to be thrown");
    } catch (InvalidObjectException exception) {
    // Expected exception - Embedded MetaStore
    } catch (TApplicationException exception) {
    // Expected exception - Remote MetaStore
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TApplicationException(org.apache.thrift.TApplicationException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 13 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testAlterFunctionNullFunctionTypeInNew.

@Test
public void testAlterFunctionNullFunctionTypeInNew() throws Exception {
    Function newFunction = getNewFunction();
    newFunction.setFunctionType(null);
    try {
        client.alterFunction(DEFAULT_DATABASE, "test_function_to_find_2", newFunction);
        // TODO: Should have a check on the server side. Embedded metastore throws
        // NullPointerException, remote throws TTransportException
        Assert.fail("Expected an NullPointerException or TTransportException to be thrown");
    } catch (NullPointerException exception) {
    // Expected exception - Embedded MetaStore
    } catch (TTransportException exception) {
    // Expected exception - Remote MetaStore
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 14 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testAlterFunctionNullDatabase.

@Test
public void testAlterFunctionNullDatabase() throws Exception {
    Function newFunction = getNewFunction();
    try {
        client.alterFunction(null, OTHER_DATABASE, newFunction);
        // TODO: Should have a check on the server side. Embedded metastore throws
        // NullPointerException, remote throws TTransportException
        Assert.fail("Expected an NullPointerException or TTransportException to be thrown");
    } catch (NullPointerException exception) {
    // Expected exception - Embedded MetaStore
    } catch (TTransportException exception) {
    // Expected exception - Remote MetaStore
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 15 with Function

use of org.apache.hadoop.hive.metastore.api.Function in project hive by apache.

the class TestFunctions method testCreateFunctionNullDatabaseName.

@Test
public void testCreateFunctionNullDatabaseName() throws Exception {
    Function function = testFunctions[0];
    function.setDbName(null);
    try {
        client.createFunction(function);
        // TODO: Should have a check on the server side. Embedded metastore throws
        // NullPointerException, remote throws TTransportException
        Assert.fail("Expected an NullPointerException or TTransportException to be thrown");
    } catch (NullPointerException exception) {
    // Expected exception - Embedded MetaStore
    } catch (TTransportException exception) {
    // Expected exception - Remote MetaStore
    }
}
Also used : Function(org.apache.hadoop.hive.metastore.api.Function) TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

Function (org.apache.hadoop.hive.metastore.api.Function)69 Test (org.junit.Test)47 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)38 ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)17 TTransportException (org.apache.thrift.transport.TTransportException)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)9 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)6 FunctionBuilder (org.apache.hadoop.hive.metastore.client.builder.FunctionBuilder)6 Database (org.apache.hadoop.hive.metastore.api.Database)4 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)4 TApplicationException (org.apache.thrift.TApplicationException)4 TException (org.apache.thrift.TException)4 HashSet (java.util.HashSet)3 Path (org.apache.hadoop.fs.Path)3 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)3 Partition (org.apache.hadoop.hive.metastore.api.Partition)3 SQLException (java.sql.SQLException)2