Search in sources :

Example 1 with CatalogBuilder

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

the class TestSchemaToolCatalogOps method moveDatabase.

@Test
public void moveDatabase() throws HiveMetaException, TException {
    String toCatName = "moveDbCat";
    String dbName = "moveDbDb";
    String tableName = "moveDbTable";
    String funcName = "movedbfunc";
    String partVal = "moveDbKey";
    new CatalogBuilder().setName(toCatName).setLocation("file:///tmp").create(client);
    Database db = new DatabaseBuilder().setCatalogName(DEFAULT_CATALOG_NAME).setName(dbName).create(client, conf);
    new FunctionBuilder().inDb(db).setName(funcName).setClass("org.apache.hive.myudf").create(client, conf);
    Table table = new TableBuilder().inDb(db).setTableName(tableName).addCol("a", "int").addPartCol("p", "string").create(client, conf);
    new PartitionBuilder().inTable(table).addValue(partVal).addToTable(client, conf);
    String argsMoveDB = String.format("-moveDatabase %s -fromCatalog %s -toCatalog %s", dbName, DEFAULT_CATALOG_NAME, toCatName);
    execute(new SchemaToolTaskMoveDatabase(), argsMoveDB);
    Database fetchedDb = client.getDatabase(toCatName, dbName);
    Assert.assertNotNull(fetchedDb);
    Assert.assertEquals(toCatName.toLowerCase(), fetchedDb.getCatalogName());
    Function fetchedFunction = client.getFunction(toCatName, dbName, funcName);
    Assert.assertNotNull(fetchedFunction);
    Assert.assertEquals(toCatName.toLowerCase(), fetchedFunction.getCatName());
    Assert.assertEquals(dbName.toLowerCase(), fetchedFunction.getDbName());
    Table fetchedTable = client.getTable(toCatName, dbName, tableName);
    Assert.assertNotNull(fetchedTable);
    Assert.assertEquals(toCatName.toLowerCase(), fetchedTable.getCatName());
    Assert.assertEquals(dbName.toLowerCase(), fetchedTable.getDbName());
    Partition fetchedPart = client.getPartition(toCatName, dbName, tableName, Collections.singletonList(partVal));
    Assert.assertNotNull(fetchedPart);
    Assert.assertEquals(toCatName.toLowerCase(), fetchedPart.getCatName());
    Assert.assertEquals(dbName.toLowerCase(), fetchedPart.getDbName());
    Assert.assertEquals(tableName.toLowerCase(), fetchedPart.getTableName());
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) Function(org.apache.hadoop.hive.metastore.api.Function) 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) 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) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Test(org.junit.Test)

Example 2 with CatalogBuilder

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

the class TestSchemaToolCatalogOps method moveDatabaseWithExistingDbOfSameNameAlreadyInTargetCatalog.

@Test
public void moveDatabaseWithExistingDbOfSameNameAlreadyInTargetCatalog() throws TException, HiveMetaException {
    String catName = "clobberCatalog";
    new CatalogBuilder().setName(catName).setLocation("file:///tmp").create(client);
    try {
        String argsMoveDB = String.format("-moveDatabase %s -fromCatalog %s -toCatalog %s", DEFAULT_DATABASE_NAME, catName, DEFAULT_CATALOG_NAME);
        execute(new SchemaToolTaskMoveDatabase(), argsMoveDB);
        Assert.fail("Attempt to move default database should have failed.");
    } catch (HiveMetaException e) {
    // good
    }
    // Make sure nothing really moved
    Set<String> dbNames = new HashSet<>(client.getAllDatabases(DEFAULT_CATALOG_NAME));
    Assert.assertTrue(dbNames.contains(DEFAULT_DATABASE_NAME));
}
Also used : CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with CatalogBuilder

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

the class TestSchemaToolCatalogOps method moveNonExistentDatabase.

@Test(expected = HiveMetaException.class)
public void moveNonExistentDatabase() throws TException, HiveMetaException {
    String catName = "moveNonExistentDb";
    new CatalogBuilder().setName(catName).setLocation("file:///tmp").create(client);
    String argsMoveDB = String.format("-moveDatabase nosuch -fromCatalog %s -toCatalog %s", catName, DEFAULT_CATALOG_NAME);
    execute(new SchemaToolTaskMoveDatabase(), argsMoveDB);
}
Also used : CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) Test(org.junit.Test)

Example 4 with CatalogBuilder

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

the class TestTransactionalValidationListener method createCatalogs.

private void createCatalogs() throws Exception {
    String[] catNames = { "spark", "myapp" };
    String[] location = { MetaStoreTestUtils.getTestWarehouseDir("spark"), MetaStoreTestUtils.getTestWarehouseDir("myapp") };
    for (int i = 0; i < catNames.length; i++) {
        Catalog cat = new CatalogBuilder().setName(catNames[i]).setLocation(location[i]).build();
        client.createCatalog(cat);
        File dir = new File(cat.getLocationUri());
        Assert.assertTrue(dir.exists() && dir.isDirectory());
    }
}
Also used : CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) File(java.io.File) Catalog(org.apache.hadoop.hive.metastore.api.Catalog)

Example 5 with CatalogBuilder

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

the class TestTablesCreateDropAlterTruncate method moveTablesBetweenCatalogsOnAlter.

@Test(expected = InvalidOperationException.class)
public void moveTablesBetweenCatalogsOnAlter() throws TException {
    String catName = "move_table_between_catalogs_on_alter";
    Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
    client.createCatalog(cat);
    String dbName = "a_db";
    // For this one don't specify a location to make sure it gets put in the catalog directory
    Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, metaStore.getConf());
    String tableName = "non_movable_table";
    Table before = new TableBuilder().inDb(db).setTableName(tableName).addCol("col1", ColumnType.STRING_TYPE_NAME).addCol("col2", ColumnType.INT_TYPE_NAME).create(client, metaStore.getConf());
    Table after = before.deepCopy();
    after.setCatName(DEFAULT_CATALOG_NAME);
    client.alter_table(catName, dbName, tableName, after);
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) Table(org.apache.hadoop.hive.metastore.api.Table) TestHiveMetaStore.createSourceTable(org.apache.hadoop.hive.metastore.TestHiveMetaStore.createSourceTable) 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)

Aggregations

CatalogBuilder (org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder)43 Catalog (org.apache.hadoop.hive.metastore.api.Catalog)34 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)30 Test (org.junit.Test)28 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)23 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)23 Database (org.apache.hadoop.hive.metastore.api.Database)19 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)13 Table (org.apache.hadoop.hive.metastore.api.Table)10 PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)10 Before (org.junit.Before)8 Partition (org.apache.hadoop.hive.metastore.api.Partition)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 File (java.io.File)4 ISchema (org.apache.hadoop.hive.metastore.api.ISchema)4 ISchemaBuilder (org.apache.hadoop.hive.metastore.client.builder.ISchemaBuilder)4 SchemaVersion (org.apache.hadoop.hive.metastore.api.SchemaVersion)3 SchemaVersionBuilder (org.apache.hadoop.hive.metastore.client.builder.SchemaVersionBuilder)3 URI (java.net.URI)2