void updateDbLocation(Database db, Path newLocation) throws HiveException { String msg = String.format("ALTER DATABASE %s SET LOCATION '%s'", db.getName(), newLocation); LOG.info(msg); db.setLocationUri(newLocation.toString()); hive.alterDatabase(db.getName(), db); }
private void makeLocationQualified(Database database) throws HiveException { if (database.isSetLocationUri()) { database.setLocationUri(Utilities.getQualifiedPath(conf, new Path(database.getLocationUri()))); } else { // Location is not set we utilize METASTOREWAREHOUSE together with database name database.setLocationUri( Utilities.getQualifiedPath(conf, new Path(HiveConf.getVar(conf, HiveConf.ConfVars.METASTOREWAREHOUSE), database.getName().toLowerCase() + DATABASE_PATH_SUFFIX))); } }
private void makeLocationQualified(Database database) throws HiveException { if (database.isSetLocationUri()) { database.setLocationUri(Utilities.getQualifiedPath(conf, new Path(database.getLocationUri()))); } else { // Location is not set we utilize METASTOREWAREHOUSE together with database name database.setLocationUri( Utilities.getQualifiedPath(conf, new Path(HiveConf.getVar(conf, HiveConf.ConfVars.METASTOREWAREHOUSE), database.getName().toLowerCase() + DATABASE_PATH_SUFFIX))); } }
public DatabaseBuilder name(String name) { database.setName(name); File databaseFolder = new File(warehouseFolder, name + ".db"); String databaseLocation = "raw://" + databaseFolder.toURI().getPath(); database.setLocationUri(databaseLocation); return this; }
Database toHiveDb() { Database hiveDB = new Database(); hiveDB.setDescription(this.comment); hiveDB.setLocationUri(this.locationUri); hiveDB.setName(this.dbName); hiveDB.setParameters(this.dbProperties); return hiveDB; }
@Override public synchronized void createDatabase(Database database) { requireNonNull(database, "database is null"); File directory; if (database.getLocationUri() != null) { directory = new File(URI.create(database.getLocationUri())); } else { // use Hive default naming convention directory = new File(baseDirectory, database.getName() + ".db"); database = database.deepCopy(); database.setLocationUri(directory.toURI().toString()); } checkArgument(!directory.exists(), "Database directory already exists"); checkArgument(isParentDir(directory, baseDirectory), "Database directory must be inside of the metastore base directory"); checkArgument(directory.mkdirs(), "Could not create database directory"); if (databases.putIfAbsent(database.getName(), database) != null) { throw new SchemaAlreadyExistsException(database.getName()); } }
db.setLocationUri(new Path(this.hiveDbRootDir.get(), hiveDbName + HIVE_DB_EXTENSION).toString());
db.setLocationUri(MetastoreDirectSqlUtils.extractSqlString(dbline[2])); db.setDescription(MetastoreDirectSqlUtils.extractSqlString(dbline[3])); db.setOwnerName(MetastoreDirectSqlUtils.extractSqlString(dbline[4]));
database.setLocationUri(newLocation);
newDB.setLocationUri(wh.getDnsPath(new Path(newDB.getLocationUri())).toString());
db.setLocationUri(dbPath.toString()); long time = System.currentTimeMillis()/1000; db.setCreateTime((int) time);
@Test public void testDBLocationChange() throws IOException, TException { final String dbName = "alterDbLocation"; String defaultUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/default_location.db"; String newUri = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/new_location.db"; new DatabaseBuilder() .setName(dbName) .setLocation(defaultUri) .create(client, conf); Database db = client.getDatabase(dbName); assertEquals("Incorrect default location of the database", warehouse.getDnsPath(new Path(defaultUri)).toString(), db.getLocationUri()); db.setLocationUri(newUri); client.alterDatabase(dbName, db); db = client.getDatabase(dbName); assertEquals("Incorrect new location of the database", warehouse.getDnsPath(new Path(newUri)).toString(), db.getLocationUri()); client.dropDatabase(dbName); silentDropDatabase(dbName); }
/** * Create a Database * @param db * @param crtDb * @return Always returns 0 * @throws HiveException */ private int createDatabase(Hive db, CreateDatabaseDesc crtDb) throws HiveException { Database database = new Database(); database.setName(crtDb.getName()); database.setDescription(crtDb.getComment()); database.setLocationUri(crtDb.getLocationUri()); database.setParameters(crtDb.getDatabaseProperties()); database.setOwnerName(SessionState.getUserFromAuthenticator()); database.setOwnerType(PrincipalType.USER); try { makeLocationQualified(database); db.createDatabase(database, crtDb.getIfNotExists()); } catch (AlreadyExistsException ex) { //it would be better if AlreadyExistsException had an errorCode field.... throw new HiveException(ex, ErrorMsg.DATABASE_ALREADY_EXISTS, crtDb.getName()); } return 0; }
Database db = new Database(); db.setName(databaseName); db.setLocationUri(dbLocation); client.createDatabase(db);
/** * Create a Database * @param db * @param crtDb * @return Always returns 0 * @throws HiveException */ private int createDatabase(Hive db, CreateDatabaseDesc crtDb) throws HiveException { Database database = new Database(); database.setName(crtDb.getName()); database.setDescription(crtDb.getComment()); database.setLocationUri(crtDb.getLocationUri()); database.setParameters(crtDb.getDatabaseProperties()); database.setOwnerName(SessionState.getUserFromAuthenticator()); database.setOwnerType(PrincipalType.USER); try { if (!Utilities.isDefaultNameNode(conf)) { makeLocationQualified(database); } db.createDatabase(database, crtDb.getIfNotExists()); } catch (AlreadyExistsException ex) { //it would be better if AlreadyExistsException had an errorCode field.... throw new HiveException(ex, ErrorMsg.DATABSAE_ALREADY_EXISTS, crtDb.getName()); } return 0; }
public Database getJDODatabase(String catName, String name) throws NoSuchObjectException { MDatabase mdb = null; boolean commited = false; try { openTransaction(); mdb = getMDatabase(catName, 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 = org.apache.commons.lang.StringUtils.defaultIfBlank(mdb.getOwnerType(), null); PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type); db.setOwnerType(principalType); db.setCatalogName(catName); db.setCreateTime(mdb.getCreateTime()); return db; }
unsetLocationUri(); } else { setLocationUri((String)value);
@Override public Optional<Database> getDatabase(String databaseName) { Optional<Database> database = super.getDatabase(databaseName); if (database.isPresent()) { database.get().setLocationUri("s3://" + writableBucket + "/"); } return database; }
Database toHiveDb() { Database hiveDB = new Database(); hiveDB.setDescription(this.comment); hiveDB.setLocationUri(this.locationUri); hiveDB.setName(this.dbName); hiveDB.setParameters(this.dbProperties); return hiveDB; }
Database toHiveDb() { Database hiveDB = new Database(); hiveDB.setDescription(this.comment); hiveDB.setLocationUri(this.locationUri); hiveDB.setName(this.dbName); hiveDB.setParameters(this.dbProperties); return hiveDB; }