Java Code Examples for org.apache.hadoop.hive.metastore.api.Database#getParameters()

The following examples show how to use org.apache.hadoop.hive.metastore.api.Database#getParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CatalogDatabase getDatabase(String databaseName) throws DatabaseNotExistException, CatalogException {
	Database hiveDatabase = getHiveDatabase(databaseName);

	Map<String, String> properties = hiveDatabase.getParameters();

	boolean isGeneric = isGenericForGet(properties);
	if (!isGeneric) {
		properties.put(SqlCreateHiveDatabase.DATABASE_LOCATION_URI, hiveDatabase.getLocationUri());
	}

	return new CatalogDatabaseImpl(properties, hiveDatabase.getDescription());
}
 
Example 2
Source File: HiveDatabaseUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
static Database alterDatabase(Database hiveDB, CatalogDatabase newDatabase) {
	Map<String, String> params = hiveDB.getParameters();
	boolean isGeneric = isGenericForGet(params);
	if (isGeneric) {
		// altering generic DB doesn't merge properties, see CatalogTest::testAlterDb
		hiveDB.setParameters(newDatabase.getProperties());
	} else {
		String opStr = newDatabase.getProperties().remove(ALTER_DATABASE_OP);
		if (opStr == null) {
			throw new CatalogException(ALTER_DATABASE_OP + " property is missing for alter database statement");
		}
		String newLocation = newDatabase.getProperties().remove(SqlCreateHiveDatabase.DATABASE_LOCATION_URI);
		Map<String, String> newParams = newDatabase.getProperties();
		SqlAlterHiveDatabase.AlterHiveDatabaseOp op = SqlAlterHiveDatabase.AlterHiveDatabaseOp.valueOf(opStr);
		switch (op) {
			case CHANGE_PROPS:
				if (params == null) {
					hiveDB.setParameters(newParams);
				} else {
					params.putAll(newParams);
				}
				break;
			case CHANGE_LOCATION:
				hiveDB.setLocationUri(newLocation);
				break;
			case CHANGE_OWNER:
				String ownerName = newParams.remove(DATABASE_OWNER_NAME);
				String ownerType = newParams.remove(DATABASE_OWNER_TYPE);
				hiveDB.setOwnerName(ownerName);
				switch (ownerType) {
					case SqlAlterHiveDatabaseOwner.ROLE_OWNER:
						hiveDB.setOwnerType(PrincipalType.ROLE);
						break;
					case SqlAlterHiveDatabaseOwner.USER_OWNER:
						hiveDB.setOwnerType(PrincipalType.USER);
						break;
					default:
						throw new CatalogException("Unsupported database owner type: " + ownerType);
				}
				break;
			default:
				throw new CatalogException("Unsupported alter database op:" + opStr);
		}
	}
	return hiveDB;
}
 
Example 3
Source File: HiveCatalog.java    From flink with Apache License 2.0 3 votes vote down vote up
@Override
public CatalogDatabase getDatabase(String databaseName) throws DatabaseNotExistException, CatalogException {
	Database hiveDatabase = getHiveDatabase(databaseName);

	Map<String, String> properties = hiveDatabase.getParameters();

	properties.put(HiveCatalogConfig.DATABASE_LOCATION_URI, hiveDatabase.getLocationUri());

	return new CatalogDatabaseImpl(properties, hiveDatabase.getDescription());
}