Search in sources :

Example 71 with Database

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

the class TestDatabases method testDropDatabaseWithTable.

@Test(expected = InvalidOperationException.class)
public void testDropDatabaseWithTable() throws Exception {
    Database database = testDatabases[0];
    Table testTable = new TableBuilder().setDbName(database.getName()).setTableName("test_table").addCol("test_col", "int").build();
    client.createTable(testTable);
    client.dropDatabase(database.getName(), true, true, false);
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) Database(org.apache.hadoop.hive.metastore.api.Database) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 72 with Database

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

the class TestDatabases method testDropDatabaseCaseInsensitive.

@Test
public void testDropDatabaseCaseInsensitive() throws Exception {
    Database database = testDatabases[0];
    // Test in upper case
    client.dropDatabase(database.getName().toUpperCase());
    List<String> allDatabases = client.getAllDatabases();
    Assert.assertEquals("All databases size", 4, allDatabases.size());
    // Test in mixed case
    client.createDatabase(database);
    client.dropDatabase("TesT_DatABaSe_1");
    allDatabases = client.getAllDatabases();
    Assert.assertEquals("All databases size", 4, allDatabases.size());
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 73 with Database

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

the class TestDatabases method testCreateGetDeleteDatabase.

/**
 * This test creates and queries a database and then drops it. Good for testing the happy path.
 * @throws Exception
 */
@Test
public void testCreateGetDeleteDatabase() throws Exception {
    Database database = getDatabaseWithAllParametersSet();
    client.createDatabase(database);
    Database createdDatabase = client.getDatabase(database.getName());
    // The createTime will be set on the server side, so the comparison should skip it
    Assert.assertEquals("Comparing databases", database, createdDatabase);
    Assert.assertTrue("The directory should be created", metaStore.isPathExists(new Path(database.getLocationUri())));
    client.dropDatabase(database.getName());
    Assert.assertFalse("The directory should be removed", metaStore.isPathExists(new Path(database.getLocationUri())));
    try {
        client.getDatabase(database.getName());
        Assert.fail("Expected a NoSuchObjectException to be thrown");
    } catch (NoSuchObjectException exception) {
    // Expected exception
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Database(org.apache.hadoop.hive.metastore.api.Database) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 74 with Database

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

the class TestDatabases method testCreateDatabaseInvalidName.

@Test(expected = InvalidObjectException.class)
public void testCreateDatabaseInvalidName() throws Exception {
    Database database = testDatabases[0];
    // Invalid character in new database name
    database.setName("test_database_1;");
    client.createDatabase(database);
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 75 with Database

use of org.apache.hadoop.hive.metastore.api.Database 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").build();
    client.createFunction(testFunction);
    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)

Aggregations

Database (org.apache.hadoop.hive.metastore.api.Database)236 Test (org.junit.Test)107 Table (org.apache.hadoop.hive.metastore.api.Table)70 ArrayList (java.util.ArrayList)51 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)39 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)39 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)37 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)36 Partition (org.apache.hadoop.hive.metastore.api.Partition)35 Path (org.apache.hadoop.fs.Path)34 IOException (java.io.IOException)29 HashMap (java.util.HashMap)27 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)26 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)24 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)23 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)22 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)22 TException (org.apache.thrift.TException)21 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)20 FileSystem (org.apache.hadoop.fs.FileSystem)17