Search in sources :

Example 66 with Database

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

the class ObjectStore method getJDODatabase.

public Database getJDODatabase(String name) throws NoSuchObjectException {
    MDatabase mdb = null;
    boolean commited = false;
    try {
        openTransaction();
        mdb = getMDatabase(name);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    Database db = new Database();
    db.setName(mdb.getName());
    db.setDescription(mdb.getDescription());
    db.setLocationUri(mdb.getLocationUri());
    db.setParameters(convertMap(mdb.getParameters()));
    db.setOwnerName(mdb.getOwnerName());
    String type = mdb.getOwnerType();
    db.setOwnerType((null == type || type.trim().isEmpty()) ? null : PrincipalType.valueOf(type));
    return db;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 67 with Database

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

the class HBaseImport method copyIndexes.

private void copyIndexes() throws MetaException, InvalidObjectException, InterruptedException {
    screen("Copying indexes");
    // Start the parallel threads that will copy the indexes
    Thread[] copiers = new Thread[parallel];
    writingToQueue = true;
    for (int i = 0; i < parallel; i++) {
        copiers[i] = new IndexCopier();
        copiers[i].start();
    }
    // Put indexes from the databases we copied into the queue
    for (Database db : dbs) {
        screen("Coyping indexes in database " + db.getName());
        for (String tableName : rdbmsStore.get().getAllTables(db.getName())) {
            for (Index index : rdbmsStore.get().getIndexes(db.getName(), tableName, -1)) {
                indexNameQueue.put(new String[] { db.getName(), tableName, index.getIndexName() });
            }
        }
    }
    // Now put any specifically requested tables into the queue
    if (tablesToImport != null) {
        for (String compoundTableName : tablesToImport) {
            String[] tn = compoundTableName.split("\\.");
            if (tn.length != 2) {
                error(compoundTableName + " not in proper form.  Must be in form dbname.tablename.  " + "Ignoring this table and continuing.");
            } else {
                for (Index index : rdbmsStore.get().getIndexes(tn[0], tn[1], -1)) {
                    indexNameQueue.put(new String[] { tn[0], tn[1], index.getIndexName() });
                }
            }
        }
    }
    writingToQueue = false;
    // Wait until we've finished adding all the tables
    for (Thread copier : copiers) copier.join();
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) Index(org.apache.hadoop.hive.metastore.api.Index)

Example 68 with Database

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

the class HBaseImport method copyDbs.

private void copyDbs() throws MetaException, NoSuchObjectException, InvalidObjectException {
    screen("Copying databases");
    List<String> toCopy = doAll ? rdbmsStore.get().getAllDatabases() : dbsToImport;
    for (String dbName : toCopy) {
        Database db = rdbmsStore.get().getDatabase(dbName);
        dbs.add(db);
        screen("Copying database " + dbName);
        hbaseStore.get().createDatabase(db);
    }
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database)

Example 69 with Database

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

the class MetaStorePersisterTest method testBasicLoadMetaStoreEntity.

@Test
public void testBasicLoadMetaStoreEntity() throws Exception {
    setupClient();
    Database database = new Database();
    database.setName("name");
    database.setDescription("description");
    database.setLocationUri("uri");
    database.setParameters(new HashMap<String, String>());
    metaStorePersister.save(database.metaDataMap, database, database.getName());
    Database foundDb = new Database();
    foundDb.setName("name");
    metaStorePersister.load(foundDb, "name");
    assertEquals(database, foundDb);
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database)

Example 70 with Database

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

the class MetaStorePersisterTest method testFindMetaStoreEntities.

@Test
public void testFindMetaStoreEntities() throws Exception {
    setupClient();
    Database database = new Database();
    database.setName("dbname");
    database.setDescription("description");
    database.setLocationUri("uri");
    database.setParameters(new HashMap<String, String>());
    metaStorePersister.save(database.metaDataMap, database, database.getName());
    Table table = new Table();
    table.setDbName("dbname");
    table.setTableName("table_one");
    metaStorePersister.save(table.metaDataMap, table, table.getDbName());
    table.setTableName("table_two");
    metaStorePersister.save(table.metaDataMap, table, table.getDbName());
    table.setTableName("table_three");
    metaStorePersister.save(table.metaDataMap, table, table.getDbName());
    table.setTableName("other_table");
    metaStorePersister.save(table.metaDataMap, table, table.getDbName());
    List tables = metaStorePersister.find(table, "dbname");
    assertEquals(4, tables.size());
    tables = metaStorePersister.find(table, "dbname", "table", 100);
    assertEquals(3, tables.size());
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) Database(org.apache.hadoop.hive.metastore.api.Database)

Aggregations

Database (org.apache.hadoop.hive.metastore.api.Database)153 Table (org.apache.hadoop.hive.metastore.api.Table)49 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)42 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)30 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)29 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)29 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)28 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)24 Path (org.apache.hadoop.fs.Path)23 Partition (org.apache.hadoop.hive.metastore.api.Partition)21 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)18 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)18 HashMap (java.util.HashMap)17 TException (org.apache.thrift.TException)17 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)16 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)15 IOException (java.io.IOException)14 SQLException (java.sql.SQLException)13 HiveInputFormat (org.apache.hadoop.hive.ql.io.HiveInputFormat)13