org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException Java Examples

The following examples show how to use org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException. 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: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDb_DatabaseAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);

	exception.expect(DatabaseAlreadyExistException.class);
	exception.expectMessage("Database db1 already exists in Catalog");
	catalog.createDatabase(db1, createDb(), false);
}
 
Example #2
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void createDatabase(String databaseName, CatalogDatabase db, boolean ignoreIfExists)
		throws DatabaseAlreadyExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName));
	checkNotNull(db);

	if (databaseExists(databaseName)) {
		if (!ignoreIfExists) {
			throw new DatabaseAlreadyExistException(getName(), databaseName);
		}
	} else {
		databases.put(databaseName, db.copy());
	}
}
 
Example #3
Source File: DependencyTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Catalog createCatalog(String name, Map<String, String> properties) {
	// Test HiveCatalogFactory.createCatalog
	// But not use it for testing purpose
	assertTrue(super.createCatalog(name, properties) != null);

	// Developers may already have their own production/testing hive-site.xml set in their environment,
	// and Flink tests should avoid using those hive-site.xml.
	// Thus, explicitly create a testing HiveConf for unit tests here
	Catalog hiveCatalog = HiveTestUtils.createHiveCatalog(name, properties.get(HiveCatalogValidator.CATALOG_HIVE_VERSION));

	// Creates an additional database to test tableEnv.useDatabase() will switch current database of the catalog
	hiveCatalog.open();
	try {
		hiveCatalog.createDatabase(
			ADDITIONAL_TEST_DATABASE,
			new CatalogDatabaseImpl(new HashMap<>(), null),
			false);
		hiveCatalog.createTable(
			new ObjectPath(ADDITIONAL_TEST_DATABASE, TEST_TABLE),
			new CatalogTableImpl(
				TableSchema.builder()
					.field("testcol", DataTypes.INT())
					.build(),
				new HashMap<String, String>() {{
					put(CatalogConfig.IS_GENERIC, String.valueOf(true));
				}},
				""
			),
			false
		);
	} catch (DatabaseAlreadyExistException | TableAlreadyExistException | DatabaseNotExistException e) {
		throw new CatalogException(e);
	}

	return hiveCatalog;
}
 
Example #4
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDb_DatabaseAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);

	exception.expect(DatabaseAlreadyExistException.class);
	exception.expectMessage("Database db1 already exists in Catalog");
	catalog.createDatabase(db1, createDb(), false);
}
 
Example #5
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void createDatabase(String databaseName, CatalogDatabase db, boolean ignoreIfExists)
		throws DatabaseAlreadyExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName));
	checkNotNull(db);

	if (databaseExists(databaseName)) {
		if (!ignoreIfExists) {
			throw new DatabaseAlreadyExistException(getName(), databaseName);
		}
	} else {
		databases.put(databaseName, db.copy());
	}
}
 
Example #6
Source File: DependencyTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Catalog createCatalog(String name, Map<String, String> properties) {
	// Developers may already have their own production/testing hive-site.xml set in their environment,
	// and Flink tests should avoid using those hive-site.xml.
	// Thus, explicitly create a testing HiveConf for unit tests here
	Catalog hiveCatalog = HiveTestUtils.createHiveCatalog(name, properties.get(HiveCatalogValidator.CATALOG_HIVE_VERSION));

	// Creates an additional database to test tableEnv.useDatabase() will switch current database of the catalog
	hiveCatalog.open();
	try {
		hiveCatalog.createDatabase(
			ADDITIONAL_TEST_DATABASE,
			new CatalogDatabaseImpl(new HashMap<>(), null),
			false);
		hiveCatalog.createTable(
			new ObjectPath(ADDITIONAL_TEST_DATABASE, TEST_TABLE),
			new CatalogTableImpl(
				TableSchema.builder()
					.field("testcol", DataTypes.INT())
					.build(),
				new HashMap<String, String>() {{
					put(CatalogConfig.IS_GENERIC, String.valueOf(false));
				}},
				""
			),
			false
		);
		// create a table to test parameterized types
		hiveCatalog.createTable(new ObjectPath("default", TABLE_WITH_PARAMETERIZED_TYPES),
				tableWithParameterizedTypes(),
				false);
	} catch (DatabaseAlreadyExistException | TableAlreadyExistException | DatabaseNotExistException e) {
		throw new CatalogException(e);
	}

	return hiveCatalog;
}
 
Example #7
Source File: AbstractReadOnlyCatalog.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists) throws DatabaseAlreadyExistException, CatalogException {
    throw UNSUPPORTED_ERR;
}
 
Example #8
Source File: AbstractJdbcCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists) throws DatabaseAlreadyExistException, CatalogException {
	throw new UnsupportedOperationException();
}
 
Example #9
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Create a database.
 *
 * @param name           Name of the database to be created
 * @param database       The database definition
 * @param ignoreIfExists Flag to specify behavior when a database with the given name already exists:
 *                       if set to false, throw a DatabaseAlreadyExistException,
 *                       if set to true, do nothing.
 * @throws DatabaseAlreadyExistException if the given database already exists and ignoreIfExists is false
 * @throws CatalogException in case of any runtime exception
 */
void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
	throws DatabaseAlreadyExistException, CatalogException;
 
Example #10
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Create a database.
 *
 * @param name           Name of the database to be created
 * @param database       The database definition
 * @param ignoreIfExists Flag to specify behavior when a database with the given name already exists:
 *                       if set to false, throw a DatabaseAlreadyExistException,
 *                       if set to true, do nothing.
 * @throws DatabaseAlreadyExistException if the given database already exists and ignoreIfExists is false
 * @throws CatalogException in case of any runtime exception
 */
void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
	throws DatabaseAlreadyExistException, CatalogException;