Search in sources :

Example 21 with CatalogBuilder

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

the class TestObjectStoreSchemaMethods method createUniqueDatabaseForTest.

private Database createUniqueDatabaseForTest() throws MetaException, InvalidObjectException {
    String catName;
    if (rand.nextDouble() < 0.5) {
        catName = "unique_cat_for_test_" + dbNum++;
        objectStore.createCatalog(new CatalogBuilder().setName(catName).setLocation("there").build());
    } else {
        catName = DEFAULT_CATALOG_NAME;
    }
    String dbName = "uniquedbfortest" + dbNum++;
    Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).setLocation("somewhere").setDescription("descriptive").build(conf);
    objectStore.createDatabase(db);
    return db;
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 22 with CatalogBuilder

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

the class TestStats method createMetadata.

private List<String> createMetadata(String catName, String dbName, String tableName, String partKey, List<String> partVals, Map<String, Column> colMap) throws TException {
    if (!DEFAULT_CATALOG_NAME.equals(catName) && !NO_CAT.equals(catName)) {
        Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
        client.createCatalog(cat);
    }
    Database db;
    if (!DEFAULT_DATABASE_NAME.equals(dbName)) {
        DatabaseBuilder dbBuilder = new DatabaseBuilder().setName(dbName);
        if (!NO_CAT.equals(catName))
            dbBuilder.setCatalogName(catName);
        db = dbBuilder.create(client, conf);
    } else {
        db = client.getDatabase(DEFAULT_CATALOG_NAME, DEFAULT_DATABASE_NAME);
    }
    TableBuilder tb = new TableBuilder().inDb(db).setTableName(tableName);
    for (Column col : colMap.values()) tb.addCol(col.colName, col.colType);
    if (partKey != null) {
        assert partVals != null && !partVals.isEmpty() : "Must provide partition values for partitioned table";
        tb.addPartCol(partKey, ColumnType.STRING_TYPE_NAME);
    }
    Table table = tb.create(client, conf);
    if (partKey != null) {
        for (String partVal : partVals) {
            new PartitionBuilder().inTable(table).addValue(partVal).addToTable(client, conf);
        }
    }
    SetPartitionsStatsRequest rqst = new SetPartitionsStatsRequest();
    List<String> partNames = new ArrayList<>();
    if (partKey == null) {
        rqst.addToColStats(buildStatsForOneTableOrPartition(catName, dbName, tableName, null, colMap.values()));
    } else {
        for (String partVal : partVals) {
            String partName = partKey + "=" + partVal;
            rqst.addToColStats(buildStatsForOneTableOrPartition(catName, dbName, tableName, partName, colMap.values()));
            partNames.add(partName);
        }
    }
    rqst.setEngine(ENGINE);
    client.setPartitionColumnStatistics(rqst);
    return partNames;
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) 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) ArrayList(java.util.ArrayList) SetPartitionsStatsRequest(org.apache.hadoop.hive.metastore.api.SetPartitionsStatsRequest) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) Catalog(org.apache.hadoop.hive.metastore.api.Catalog)

Example 23 with CatalogBuilder

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

the class TestCatalogs method dropNonEmptyCatalog.

@Test(expected = InvalidOperationException.class)
public void dropNonEmptyCatalog() throws TException {
    String catName = "toBeDropped";
    Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
    client.createCatalog(cat);
    String dbName = "dontDropMe";
    new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, metaStore.getConf());
    client.dropCatalog(catName);
}
Also used : DatabaseBuilder(org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder) CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) Catalog(org.apache.hadoop.hive.metastore.api.Catalog) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 24 with CatalogBuilder

use of org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder 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 25 with CatalogBuilder

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

the class TestCatalogs method alterNonExistentCatalog.

@Test(expected = NoSuchObjectException.class)
public void alterNonExistentCatalog() throws TException {
    String catName = "alter_no_such_catalog";
    Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
    client.alterCatalog(catName, cat);
}
Also used : CatalogBuilder(org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder) 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