Search in sources :

Example 6 with MDatabase

use of org.apache.hadoop.hive.metastore.model.MDatabase in project hive by apache.

the class ObjectStore method listFSRoots.

/** The following API
  *
  *  - listFSRoots
  *
  * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift.
  *
  */
public Set<String> listFSRoots() {
    boolean committed = false;
    Query query = null;
    Set<String> fsRoots = new HashSet<String>();
    try {
        openTransaction();
        query = pm.newQuery(MDatabase.class);
        List<MDatabase> mDBs = (List<MDatabase>) query.execute();
        pm.retrieveAll(mDBs);
        for (MDatabase mDB : mDBs) {
            fsRoots.add(mDB.getLocationUri());
        }
        committed = commitTransaction();
        if (committed) {
            return fsRoots;
        } else {
            return null;
        }
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) Query(javax.jdo.Query) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 7 with MDatabase

use of org.apache.hadoop.hive.metastore.model.MDatabase in project hive by apache.

the class ObjectStore method alterDatabase.

/**
   * Alter the database object in metastore. Currently only the parameters
   * of the database or the owner can be changed.
   * @param dbName the database name
   * @param db the Hive Database object
   * @throws MetaException
   * @throws NoSuchObjectException
   */
@Override
public boolean alterDatabase(String dbName, Database db) throws MetaException, NoSuchObjectException {
    MDatabase mdb = null;
    boolean committed = false;
    try {
        mdb = getMDatabase(dbName);
        mdb.setParameters(db.getParameters());
        mdb.setOwnerName(db.getOwnerName());
        if (db.getOwnerType() != null) {
            mdb.setOwnerType(db.getOwnerType().name());
        }
        openTransaction();
        pm.makePersistent(mdb);
        committed = commitTransaction();
    } finally {
        if (!committed) {
            rollbackTransaction();
            return false;
        }
    }
    return true;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase)

Example 8 with MDatabase

use of org.apache.hadoop.hive.metastore.model.MDatabase in project hive by apache.

the class ObjectStore method createDatabase.

@Override
public void createDatabase(Database db) throws InvalidObjectException, MetaException {
    boolean commited = false;
    MDatabase mdb = new MDatabase();
    mdb.setName(db.getName().toLowerCase());
    mdb.setLocationUri(db.getLocationUri());
    mdb.setDescription(db.getDescription());
    mdb.setParameters(db.getParameters());
    mdb.setOwnerName(db.getOwnerName());
    PrincipalType ownerType = db.getOwnerType();
    mdb.setOwnerType((null == ownerType ? PrincipalType.USER.name() : ownerType.name()));
    try {
        openTransaction();
        pm.makePersistent(mdb);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 9 with MDatabase

use of org.apache.hadoop.hive.metastore.model.MDatabase 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 10 with MDatabase

use of org.apache.hadoop.hive.metastore.model.MDatabase in project hive by apache.

the class ObjectStore method updateMDatabaseURI.

/** The following APIs
  *
  *  - updateMDatabaseURI
  *
  * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift.
  *
  */
public UpdateMDatabaseURIRetVal updateMDatabaseURI(URI oldLoc, URI newLoc, boolean dryRun) {
    boolean committed = false;
    Query query = null;
    Map<String, String> updateLocations = new HashMap<String, String>();
    List<String> badRecords = new ArrayList<String>();
    UpdateMDatabaseURIRetVal retVal = null;
    try {
        openTransaction();
        query = pm.newQuery(MDatabase.class);
        List<MDatabase> mDBs = (List<MDatabase>) query.execute();
        pm.retrieveAll(mDBs);
        for (MDatabase mDB : mDBs) {
            URI locationURI = null;
            String location = mDB.getLocationUri();
            try {
                locationURI = new Path(location).toUri();
            } catch (IllegalArgumentException e) {
                badRecords.add(location);
            }
            if (locationURI == null) {
                badRecords.add(location);
            } else {
                if (shouldUpdateURI(locationURI, oldLoc)) {
                    String dbLoc = mDB.getLocationUri().replaceAll(oldLoc.toString(), newLoc.toString());
                    updateLocations.put(locationURI.toString(), dbLoc);
                    if (!dryRun) {
                        mDB.setLocationUri(dbLoc);
                    }
                }
            }
        }
        committed = commitTransaction();
        if (committed) {
            retVal = new UpdateMDatabaseURIRetVal(badRecords, updateLocations);
        }
        return retVal;
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Query(javax.jdo.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)14 ArrayList (java.util.ArrayList)7 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)6 MTable (org.apache.hadoop.hive.metastore.model.MTable)6 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)5 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)4 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)4 Query (javax.jdo.Query)3 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)3 MDBPrivilege (org.apache.hadoop.hive.metastore.model.MDBPrivilege)3 MPartition (org.apache.hadoop.hive.metastore.model.MPartition)3 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)3 MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)3 MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)3 HashSet (java.util.HashSet)2 MGlobalPrivilege (org.apache.hadoop.hive.metastore.model.MGlobalPrivilege)2