Search in sources :

Example 56 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestCatalogs method dropCatalogWithNonEmptyDefaultDb.

@Test(expected = InvalidOperationException.class)
public void dropCatalogWithNonEmptyDefaultDb() throws TException {
    String catName = "toBeDropped2";
    new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).create(client);
    new TableBuilder().setTableName("not_droppable").setCatName(catName).addCol("cola1", "bigint").create(client, metaStore.getConf());
    client.dropCatalog(catName);
}
Also used : CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 57 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestDatabases method testDropDatabaseWithTableCascade.

@Test
public void testDropDatabaseWithTableCascade() throws Exception {
    Database database = testDatabases[0];
    Table testTable = new TableBuilder().setDbName(database.getName()).setTableName("test_table").addCol("test_col", "int").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) 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 58 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder 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").create(client, metaStore.getConf());
    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 59 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestAlterPartitions method otherCatalog.

@Test
@ConditionalIgnoreOnSessionHiveMetastoreClient
public void otherCatalog() throws TException {
    String catName = "alter_partition_catalog";
    Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
    client.createCatalog(cat);
    String dbName = "alter_partition_database_in_other_catalog";
    Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, metaStore.getConf());
    String tableName = "table_in_other_catalog";
    Table table = new TableBuilder().inDb(db).setTableName(tableName).addCol("id", "int").addCol("name", "string").addPartCol("partcol", "string").create(client, metaStore.getConf());
    Partition[] parts = new Partition[5];
    for (int i = 0; i < 5; i++) {
        parts[i] = new PartitionBuilder().inTable(table).addValue("a" + i).setLocation(MetaStoreTestUtils.getTestWarehouseDir("b" + i)).build(metaStore.getConf());
    }
    client.add_partitions(Arrays.asList(parts));
    Partition newPart = client.getPartition(catName, dbName, tableName, Collections.singletonList("a0"));
    newPart.getParameters().put("test_key", "test_value");
    client.alter_partition(catName, dbName, tableName, newPart);
    Partition fetched = client.getPartition(catName, dbName, tableName, Collections.singletonList("a0"));
    Assert.assertEquals(catName, fetched.getCatName());
    Assert.assertEquals("test_value", fetched.getParameters().get("test_key"));
    newPart = client.getPartition(catName, dbName, tableName, Collections.singletonList("a1"));
    newPart.setLastAccessTime(3);
    Partition newPart1 = client.getPartition(catName, dbName, tableName, Collections.singletonList("a2"));
    newPart1.getSd().setLocation(MetaStoreTestUtils.getTestWarehouseDir("somewhere"));
    client.alter_partitions(catName, dbName, tableName, Arrays.asList(newPart, newPart1));
    fetched = client.getPartition(catName, dbName, tableName, Collections.singletonList("a1"));
    Assert.assertEquals(catName, fetched.getCatName());
    Assert.assertEquals(3L, fetched.getLastAccessTime());
    fetched = client.getPartition(catName, dbName, tableName, Collections.singletonList("a2"));
    Assert.assertEquals(catName, fetched.getCatName());
    Assert.assertTrue(fetched.getSd().getLocation().contains("somewhere"));
    newPart = client.getPartition(catName, dbName, tableName, Collections.singletonList("a4"));
    newPart.getParameters().put("test_key", "test_value");
    EnvironmentContext ec = new EnvironmentContext();
    ec.setProperties(Collections.singletonMap("a", "b"));
    client.alter_partition(catName, dbName, tableName, newPart, ec);
    fetched = client.getPartition(catName, dbName, tableName, Collections.singletonList("a4"));
    Assert.assertEquals(catName, fetched.getCatName());
    Assert.assertEquals("test_value", fetched.getParameters().get("test_key"));
    client.dropDatabase(catName, dbName, true, true, true);
    client.dropCatalog(catName);
}
Also used : EnvironmentContext(org.apache.hadoop.hive.metastore.api.EnvironmentContext) DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) Database(org.apache.hadoop.hive.metastore.api.Database) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Catalog(org.apache.hadoop.hive.metastore.api.Catalog) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 60 with TableBuilder

use of org.apache.hadoop.hive.metastore.client.builder.TableBuilder in project hive by apache.

the class TestAddPartitions method noSuchCatalog.

@Test(expected = InvalidObjectException.class)
@ConditionalIgnoreOnSessionHiveMetastoreClient
public void noSuchCatalog() throws TException {
    String tableName = "table_for_no_such_catalog";
    Table table = new TableBuilder().setTableName(tableName).addCol("id", "int").addCol("name", "string").addPartCol("partcol", "string").create(client, metaStore.getConf());
    Partition part = new PartitionBuilder().inTable(table).addValue("a").build(metaStore.getConf());
    // Explicitly mis-set the catalog name
    part.setCatName("nosuch");
    client.add_partition(part);
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionBuilder(org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)136 Table (org.apache.hadoop.hive.metastore.api.Table)111 Test (org.junit.Test)92 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)81 Database (org.apache.hadoop.hive.metastore.api.Database)40 Partition (org.apache.hadoop.hive.metastore.api.Partition)36 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)35 PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)33 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)31 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)30 ArrayList (java.util.ArrayList)28 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)27 SourceTable (org.apache.hadoop.hive.metastore.api.SourceTable)25 CatalogBuilder (org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder)23 Path (org.apache.hadoop.fs.Path)19 Catalog (org.apache.hadoop.hive.metastore.api.Catalog)19 Type (org.apache.hadoop.hive.metastore.api.Type)19 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)17 TException (org.apache.thrift.TException)16 IOException (java.io.IOException)15