public void alterDatabase(String dbName, Database db) throws HiveException { try { getMSC().alterDatabase(dbName, db); } catch (MetaException e) { throw new HiveException("Unable to alter database " + dbName + ". " + e.getMessage(), e); } catch (NoSuchObjectException e) { throw new HiveException("Database " + dbName + " does not exists.", e); } catch (TException e) { throw new HiveException("Unable to alter database " + dbName + ". " + e.getMessage(), e); } } /**
public void alterDatabase(String dbName, Database db) throws HiveException { try { getMSC().alterDatabase(dbName, db); } catch (MetaException e) { throw new HiveException("Unable to alter database " + dbName + ". " + e.getMessage(), e); } catch (NoSuchObjectException e) { throw new HiveException("Database " + dbName + " does not exists.", e); } catch (TException e) { throw new HiveException("Unable to alter database " + dbName + ". " + e.getMessage(), e); } } /**
@Test(expected = NoSuchObjectException.class) public void testAlterDatabaseNoSuchDatabase() throws Exception { Database newDatabase = new DatabaseBuilder() .setName("test_database_altered") .build(metaStore.getConf()); client.alterDatabase("no_such_database", newDatabase); }
@Test public void testAlterDatabaseCaseInsensitive() throws Exception { Database originalDatabase = testDatabases[0]; Database newDatabase = originalDatabase.deepCopy(); newDatabase.setDescription("Altered database"); // Test in upper case client.alterDatabase(originalDatabase.getName().toUpperCase(), newDatabase); Database alteredDatabase = client.getDatabase(newDatabase.getName()); Assert.assertEquals("Comparing databases", newDatabase, alteredDatabase); // Test in mixed case originalDatabase = testDatabases[2]; newDatabase = originalDatabase.deepCopy(); newDatabase.setDescription("Altered database 2"); client.alterDatabase("TeST_daTAbaSe_TO_FiNd_2", newDatabase); alteredDatabase = client.getDatabase(newDatabase.getName()); Assert.assertEquals("Comparing databases", newDatabase, alteredDatabase); }
@Test public void testAlterDatabase() throws Exception { Database originalDatabase = testDatabases[0]; Database newDatabase = new DatabaseBuilder() // The database name is not changed during alter .setName(originalDatabase.getName()) .setOwnerType(PrincipalType.GROUP) .setOwnerName("owner2") .setLocation(metaStore.getWarehouseRoot() + "/database_location_2") .setDescription("dummy description 2") .addParam("param_key_1", "param_value_1_2") .addParam("param_key_2_3", "param_value_2_3") .setCreateTime(originalDatabase.getCreateTime()) .build(metaStore.getConf()); client.alterDatabase(originalDatabase.getName(), newDatabase); Database alteredDatabase = client.getDatabase(newDatabase.getName()); Assert.assertEquals("Comparing Databases", newDatabase, alteredDatabase); }
@Test public void testAlterDatabaseNotNullableFields() throws Exception { Database database = getDatabaseWithAllParametersSet(); client.createDatabase(database); Database originalDatabase = client.getDatabase(database.getName()); Database newDatabase = new Database(); newDatabase.setName("new_name"); newDatabase.setCatalogName(DEFAULT_CATALOG_NAME); client.alterDatabase(originalDatabase.getName(), newDatabase); // The name should not be changed, so reload the db with the original name Database alteredDatabase = client.getDatabase(originalDatabase.getName()); Assert.assertEquals("Database name should not change", originalDatabase.getName(), alteredDatabase.getName()); Assert.assertEquals("Database description should not change", originalDatabase.getDescription(), alteredDatabase.getDescription()); Assert.assertEquals("Database location should not change", originalDatabase.getLocationUri(), alteredDatabase.getLocationUri()); Assert.assertEquals("Database parameters should be empty", new HashMap<String, String>(), alteredDatabase.getParameters()); Assert.assertNull("Database owner should be empty", alteredDatabase.getOwnerName()); Assert.assertEquals("Database owner type should not change", originalDatabase.getOwnerType(), alteredDatabase.getOwnerType()); Assert.assertNull("Database privileges should be empty", alteredDatabase.getPrivileges()); }
@Override public void alterDatabase(String dbName, CatalogDatabase newDatabase, boolean ignoreIfNotExists) throws DatabaseNotExistException { try { if (dbExists(dbName)) { client.alterDatabase(dbName, HiveMetadataUtil.createHiveDatabase(dbName, newDatabase)); } else if (!ignoreIfNotExists) { throw new DatabaseNotExistException(catalogName, dbName); } } catch (TException e) { throw new FlinkHiveException(String.format("Failed to alter database %s", dbName), e); } }
public void alterDatabase(String dbName, Database db) throws HiveException { try { getMSC().alterDatabase(dbName, db); } catch (MetaException e) { throw new HiveException("Unable to alter database " + dbName, e); } catch (NoSuchObjectException e) { throw new HiveException("Database " + dbName + " does not exists.", e); } catch (TException e) { throw new HiveException("Unable to alter database " + dbName, e); } } /**
public void alterDatabase(String dbName, Database db) throws HiveException { try { getMSC().alterDatabase(dbName, db); } catch (MetaException e) { throw new HiveException("Unable to alter database " + dbName + ". " + e.getMessage(), e); } catch (NoSuchObjectException e) { throw new HiveException("Database " + dbName + " does not exists.", e); } catch (TException e) { throw new HiveException("Unable to alter database " + dbName + ". " + e.getMessage(), e); } } /**
@Test public void db() throws TException { final String dbName = "bigtop_thrift_db_" + rand.nextInt(Integer.MAX_VALUE); Database db = new Database(dbName, "a db", null, new HashMap<String, String>()); client.createDatabase(db); db = client.getDatabase(dbName); Assert.assertNotNull(db); db = new Database(db); db.getParameters().put("a", "b"); client.alterDatabase(dbName, db); List<String> alldbs = client.getDatabases("bigtop_*"); Assert.assertNotNull(alldbs); Assert.assertTrue(alldbs.size() > 0); alldbs = client.getAllDatabases(); Assert.assertNotNull(alldbs); Assert.assertTrue(alldbs.size() > 0); client.dropDatabase(dbName, true, true); }