use of org.apache.hadoop.hive.metastore.api.Catalog in project hive by apache.
the class ObjectStore method mCatToCat.
private Catalog mCatToCat(MCatalog mCat) {
Catalog cat = new Catalog(mCat.getName(), mCat.getLocationUri());
if (mCat.getDescription() != null) {
cat.setDescription(mCat.getDescription());
}
cat.setCreateTime(mCat.getCreateTime());
return cat;
}
use of org.apache.hadoop.hive.metastore.api.Catalog in project hive by apache.
the class CatalogBuilder method create.
/**
* Build the catalog object and create it in the metastore.
* @param client metastore client
* @return new catalog object
* @throws TException thrown from the client
*/
public Catalog create(IMetaStoreClient client) throws TException {
Catalog cat = build();
client.createCatalog(cat);
return cat;
}
use of org.apache.hadoop.hive.metastore.api.Catalog 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);
}
use of org.apache.hadoop.hive.metastore.api.Catalog in project hive by apache.
the class TestTablesList method otherCatalogs.
@Test
public void otherCatalogs() throws TException {
String catName = "list_tables_in_other_catalogs";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "db_in_other_catalog";
// 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[] tableNames = new String[4];
for (int i = 0; i < tableNames.length; i++) {
tableNames[i] = "table_in_other_catalog_" + i;
TableBuilder builder = new TableBuilder().inDb(db).setTableName(tableNames[i]).addCol("col1_" + i, ColumnType.STRING_TYPE_NAME).addCol("col2_" + i, ColumnType.INT_TYPE_NAME);
if (i == 0)
builder.addTableParam("the_key", "the_value");
builder.create(client, metaStore.getConf());
}
String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "the_key=\"the_value\"";
List<String> fetchedNames = client.listTableNamesByFilter(catName, dbName, filter, (short) -1);
Assert.assertEquals(1, fetchedNames.size());
Assert.assertEquals(tableNames[0], fetchedNames.get(0));
}
use of org.apache.hadoop.hive.metastore.api.Catalog in project hive by apache.
the class TestHiveMetaStoreSchemaMethods method mapSerdeToSchemaVersionOtherDb.
@Test
public void mapSerdeToSchemaVersionOtherDb() throws TException {
String catName = "other_cat_for_map_to";
Catalog cat = new CatalogBuilder().setName(catName).setLocation(MetaStoreTestUtils.getTestWarehouseDir(catName)).build();
client.createCatalog(cat);
String dbName = "map_other_db";
Database db = new DatabaseBuilder().setName(dbName).setCatalogName(catName).create(client, conf);
ISchema schema = new ISchemaBuilder().setSchemaType(SchemaType.AVRO).inDb(db).setName(uniqueSchemaName()).build();
client.createISchema(schema);
// Create schema with no serde, then map it
SchemaVersion schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(1).addCol("x", ColumnType.BOOLEAN_TYPE_NAME).build();
client.addSchemaVersion(schemaVersion);
SerDeInfo serDeInfo = new SerDeInfo(uniqueSerdeName(), "lib", Collections.emptyMap());
client.addSerDe(serDeInfo);
client.mapSchemaVersionToSerde(catName, dbName, schema.getName(), schemaVersion.getVersion(), serDeInfo.getName());
schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), schemaVersion.getVersion());
Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
// Create schema with a serde, then remap it
String serDeName = uniqueSerdeName();
schemaVersion = new SchemaVersionBuilder().versionOf(schema).setVersion(2).addCol("x", ColumnType.BOOLEAN_TYPE_NAME).setSerdeName(serDeName).setSerdeLib("x").build();
client.addSchemaVersion(schemaVersion);
schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), 2);
Assert.assertEquals(serDeName, schemaVersion.getSerDe().getName());
serDeInfo = new SerDeInfo(uniqueSerdeName(), "y", Collections.emptyMap());
client.addSerDe(serDeInfo);
client.mapSchemaVersionToSerde(catName, dbName, schema.getName(), 2, serDeInfo.getName());
schemaVersion = client.getSchemaVersion(catName, dbName, schema.getName(), 2);
Assert.assertEquals(serDeInfo.getName(), schemaVersion.getSerDe().getName());
}
Aggregations