public static void resetDbBootstrapDumpState(Hive hiveDb, String dbName, String uniqueKey) throws HiveException { Database database = hiveDb.getDatabase(dbName); if (database != null) { Map<String, String> params = database.getParameters(); if ((params != null) && params.containsKey(uniqueKey)) { params.remove(uniqueKey); database.setParameters(params); hiveDb.alterDatabase(dbName, database); LOG.info("REPL DUMP:: Reset property for Database: {}, Property: {}", dbName, uniqueKey); } } }
public static void createDbExportDump(FileSystem fs, Path metadataPath, Database dbObj, ReplicationSpec replicationSpec) throws IOException, SemanticException { // WARNING NOTE : at this point, createDbExportDump lives only in a world where ReplicationSpec is in replication scope // If we later make this work for non-repl cases, analysis of this logic might become necessary. Also, this is using // Replv2 semantics, i.e. with listFiles laziness (no copy at export time) // Remove all the entries from the parameters which are added by repl tasks internally. Map<String, String> parameters = dbObj.getParameters(); if (parameters != null) { Map<String, String> tmpParameters = new HashMap<>(parameters); tmpParameters.entrySet() .removeIf(e -> e.getKey().startsWith(Utils.BOOTSTRAP_DUMP_STATE_KEY_PREFIX) || e.getKey().equals(ReplUtils.REPL_CHECKPOINT_KEY) || e.getKey().equals(ReplChangeManager.SOURCE_OF_REPLICATION)); dbObj.setParameters(tmpParameters); } try (JsonWriter jsonWriter = new JsonWriter(fs, metadataPath)) { new DBSerializer(dbObj).writeTo(jsonWriter, replicationSpec); } if (parameters != null) { dbObj.setParameters(parameters); } }
public static String setDbBootstrapDumpState(Hive hiveDb, String dbName) throws HiveException { Database database = hiveDb.getDatabase(dbName); if (database == null) { return null; } Map<String, String> newParams = new HashMap<>(); String uniqueKey = BOOTSTRAP_DUMP_STATE_KEY_PREFIX + UUID.randomUUID().toString(); newParams.put(uniqueKey, ReplDumpState.ACTIVE.name()); Map<String, String> params = database.getParameters(); // if both old params are not null, merge them if (params != null) { params.putAll(newParams); database.setParameters(params); } else { // if one of them is null, replace the old params with the new one database.setParameters(newParams); } hiveDb.alterDatabase(dbName, database); LOG.info("REPL DUMP:: Set property for Database: {}, Property: {}, Value: {}", dbName, uniqueKey, Utils.ReplDumpState.ACTIVE.name()); return uniqueKey; }
Database toHiveDb() { Database hiveDB = new Database(); hiveDB.setDescription(this.comment); hiveDB.setLocationUri(this.locationUri); hiveDB.setName(this.dbName); hiveDB.setParameters(this.dbProperties); return hiveDB; }
public static org.apache.hadoop.hive.metastore.api.Database toMetastoreApiDatabase(Database database) { org.apache.hadoop.hive.metastore.api.Database result = new org.apache.hadoop.hive.metastore.api.Database(); result.setName(database.getDatabaseName()); database.getLocation().ifPresent(result::setLocationUri); result.setOwnerName(database.getOwnerName()); result.setOwnerType(toMetastoreApiPrincipalType(database.getOwnerType())); database.getComment().ifPresent(result::setDescription); result.setParameters(database.getParameters()); return result; }
database.setParameters(params); } else { database.setParameters(newParams);
db.setCatalogName(MetastoreDirectSqlUtils.extractSqlString(dbline[6])); db.setCreateTime(MetastoreDirectSqlUtils.extractSqlInt(dbline[7])); db.setParameters(MetaStoreServerUtils.trimMapNulls(dbParams,convertMapNullsToEmptyStrings)); if (LOG.isDebugEnabled()){ LOG.debug("getDatabase: directsql returning db " + db.getName()
private int alterDatabase(Hive db, AlterDatabaseDesc alterDbDesc) throws HiveException { String dbName = alterDbDesc.getDatabaseName(); Database database = db.getDatabase(dbName); if (database == null) { throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName); } switch (alterDbDesc.getAlterType()) { case ALTER_PROPERTY: Map<String, String> newParams = alterDbDesc.getDatabaseProperties(); Map<String, String> params = database.getParameters(); // if both old and new params are not null, merge them if (params != null && newParams != null) { params.putAll(newParams); database.setParameters(params); } else { // if one of them is null, replace the old params with the new one database.setParameters(newParams); } break; case ALTER_OWNER: database.setOwnerName(alterDbDesc.getOwnerPrincipal().getName()); database.setOwnerType(alterDbDesc.getOwnerPrincipal().getType()); break; default: throw new AssertionError("Unsupported alter database type! : " + alterDbDesc.getAlterType()); } db.alterDatabase(database.getName(), database); return 0; }
/** * 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; }
/** * 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; }
unsetParameters(); } else { setParameters((Map<String,String>)value);
String sql = "SELECT FULLNAMES FROM CUSTOMER WHERE ADDRESS = ? OR ADDRESS = ?"; Map<Integer,Object> param = new HashMap<>(); param.put(1,"NEW YORK"); param.put(2,"CHICAGO"); Database db = new Database(sql); db.setParameters(param); List customers = db.processQuery();
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; }
Database toHiveDb() { Database hiveDB = new Database(); hiveDB.setDescription(this.comment); hiveDB.setLocationUri(this.locationUri); hiveDB.setName(this.dbName); hiveDB.setParameters(this.dbProperties); return hiveDB; }
public static org.apache.hadoop.hive.metastore.api.Database toMetastoreApiDatabase(Database database) { org.apache.hadoop.hive.metastore.api.Database result = new org.apache.hadoop.hive.metastore.api.Database(); result.setName(database.getDatabaseName()); database.getLocation().ifPresent(result::setLocationUri); result.setOwnerName(database.getOwnerName()); result.setOwnerType(toMetastoreApiPrincipalType(database.getOwnerType())); database.getComment().ifPresent(result::setDescription); result.setParameters(database.getParameters()); return result; }
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; }
/** * Create a Database * @param db * @param crtDb * @return Always returns 0 * @throws HiveException * @throws AlreadyExistsException */ private int createDatabase(Hive db, CreateDatabaseDesc crtDb) throws HiveException, AlreadyExistsException { Database database = new Database(); database.setName(crtDb.getName()); database.setDescription(crtDb.getComment()); database.setLocationUri(crtDb.getLocationUri()); database.setParameters(crtDb.getDatabaseProperties()); db.createDatabase(database, crtDb.getIfNotExists()); return 0; }
public Database getDatabase(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(mdb.getParameters()); return db; }