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

The following examples show how to use org.apache.flink.table.catalog.exceptions.DatabaseNotExistException. 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: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createFunction(ObjectPath path, CatalogFunction function, boolean ignoreIfExists)
		throws FunctionAlreadyExistException, DatabaseNotExistException {
	checkNotNull(path);
	checkNotNull(function);

	ObjectPath functionPath = normalize(path);

	if (!databaseExists(functionPath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), functionPath.getDatabaseName());
	}

	if (functionExists(functionPath)) {
		if (!ignoreIfExists) {
			throw new FunctionAlreadyExistException(getName(), functionPath);
		}
	} else {
		functions.put(functionPath, function.copy());
	}
}
 
Example #2
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void dropDatabase(String databaseName, boolean ignoreIfNotExists)
		throws DatabaseNotExistException, DatabaseNotEmptyException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName));

	if (databases.containsKey(databaseName)) {

		// Make sure the database is empty
		if (isDatabaseEmpty(databaseName)) {
			databases.remove(databaseName);
		} else {
			throw new DatabaseNotEmptyException(getName(), databaseName);
		}
	} else if (!ignoreIfNotExists) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}
}
 
Example #3
Source File: FunctionCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
public String[] getUserDefinedFunctions() {
	List<String> result = new ArrayList<>();

	// Get functions in catalog
	Catalog catalog = catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get();
	try {
		result.addAll(catalog.listFunctions(catalogManager.getCurrentDatabase()));
	} catch (DatabaseNotExistException e) {
		// Ignore since there will always be a current database of the current catalog
	}

	// Get functions registered in memory
	result.addAll(
		userFunctions.values().stream()
			.map(FunctionDefinition::toString)
			.collect(Collectors.toList()));

	return result.toArray(new String[0]);
}
 
Example #4
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void alterDatabase(String databaseName, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
		throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName));
	checkNotNull(newDatabase);

	CatalogDatabase existingDatabase = databases.get(databaseName);

	if (existingDatabase != null) {
		if (existingDatabase.getClass() != newDatabase.getClass()) {
			throw new CatalogException(
				String.format("Database types don't match. Existing database is '%s' and new database is '%s'.",
					existingDatabase.getClass().getName(), newDatabase.getClass().getName())
			);
		}

		databases.put(databaseName, newDatabase.copy());
	} else if (!ignoreIfNotExists) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}
}
 
Example #5
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
		throws TableAlreadyExistException, DatabaseNotExistException {
	checkNotNull(tablePath);
	checkNotNull(table);

	if (!databaseExists(tablePath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), tablePath.getDatabaseName());
	}

	if (tableExists(tablePath)) {
		if (!ignoreIfExists) {
			throw new TableAlreadyExistException(getName(), tablePath);
		}
	} else {
		tables.put(tablePath, table.copy());

		if (isPartitionedTable(tablePath)) {
			partitions.put(tablePath, new LinkedHashMap<>());
			partitionStats.put(tablePath, new LinkedHashMap<>());
			partitionColumnStats.put(tablePath, new LinkedHashMap<>());
		}
	}
}
 
Example #6
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
		throws FunctionAlreadyExistException, DatabaseNotExistException {
	checkNotNull(functionPath);
	checkNotNull(function);

	if (!databaseExists(functionPath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), functionPath.getDatabaseName());
	}

	if (functionExists(functionPath)) {
		if (!ignoreIfExists) {
			throw new FunctionAlreadyExistException(getName(), functionPath);
		}
	} else {
		functions.put(functionPath, function.copy());
	}
}
 
Example #7
Source File: HiveCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> listFunctions(String databaseName) throws DatabaseNotExistException, CatalogException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

	// client.getFunctions() returns empty list when the database doesn't exist
	// thus we need to explicitly check whether the database exists or not
	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}

	try {
		// hive-1.x requires the pattern not being null, so pass a pattern that matches any name
		return client.getFunctions(databaseName, ".*");
	} catch (TException e) {
		throw new CatalogException(
			String.format("Failed to list functions in database %s", databaseName), e);
	}
}
 
Example #8
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws TableAlreadyExistException, DatabaseNotExistException {
	final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
	final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
	final TableSchema tableSchema = TableSchema.builder()
		.field("a", DataTypes.BIGINT())
		.field("b", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.field("c", DataTypes.INT())
		.field("d", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "COLLECTION");
	final CatalogTable catalogTable =  new CatalogTableImpl(tableSchema, properties, "");
	catalog.createTable(path1, catalogTable, true);
	catalog.createTable(path2, catalogTable, true);
}
 
Example #9
Source File: DatabaseCalciteSchemaTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCatalogTable() throws TableAlreadyExistException, DatabaseNotExistException {
	GenericInMemoryCatalog catalog = new GenericInMemoryCatalog(catalogName, databaseName);
	CatalogManager catalogManager = CatalogManagerMocks.preparedCatalogManager()
		.defaultCatalog(catalogName, catalog)
		.build();
	catalogManager.setCatalogTableSchemaResolver(new CatalogTableSchemaResolver(new ParserMock(), true));

	DatabaseCalciteSchema calciteSchema = new DatabaseCalciteSchema(
		true,
		databaseName,
		catalogName,
		catalogManager,
		new TableConfig());

	catalog.createTable(new ObjectPath(databaseName, tableName), new TestCatalogBaseTable(), false);
	Table table = calciteSchema.getTable(tableName);

	assertThat(table, instanceOf(TableSourceTable.class));
	TableSourceTable tableSourceTable = (TableSourceTable) table;
	assertThat(tableSourceTable.tableSource(), instanceOf(TestExternalTableSource.class));
	assertThat(tableSourceTable.isStreamingMode(), is(true));
}
 
Example #10
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws TableAlreadyExistException, DatabaseNotExistException {
	catalogManager.setCatalogTableSchemaResolver(new CatalogTableSchemaResolver(new ParserMock(), true));
	final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
	final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
	final TableSchema tableSchema = TableSchema.builder()
		.field("a", DataTypes.BIGINT())
		.field("b", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.field("c", DataTypes.INT())
		.field("d", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "COLLECTION");
	final CatalogTable catalogTable =  new CatalogTableImpl(tableSchema, properties, "");
	catalog.createTable(path1, catalogTable, true);
	catalog.createTable(path2, catalogTable, true);
}
 
Example #11
Source File: DatabaseCalciteSchemaTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCatalogTable() throws TableAlreadyExistException, DatabaseNotExistException {
	GenericInMemoryCatalog catalog = new GenericInMemoryCatalog(catalogName, databaseName);
	DatabaseCalciteSchema calciteSchema = new DatabaseCalciteSchema(true,
		databaseName,
		catalogName,
		catalog);

	catalog.createTable(new ObjectPath(databaseName, tableName), new TestCatalogBaseTable(), false);
	Table table = calciteSchema.getTable(tableName);

	assertThat(table, instanceOf(TableSourceTable.class));
	TableSourceTable tableSourceTable = (TableSourceTable) table;
	assertThat(tableSourceTable.tableSource(), instanceOf(TestExternalTableSource.class));
	assertThat(tableSourceTable.isStreamingMode(), is(true));
}
 
Example #12
Source File: HiveCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> listFunctions(String databaseName) throws DatabaseNotExistException, CatalogException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

	// client.getFunctions() returns empty list when the database doesn't exist
	// thus we need to explicitly check whether the database exists or not
	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}

	try {
		// hive-1.x requires the pattern not being null, so pass a pattern that matches any name
		return client.getFunctions(databaseName, ".*");
	} catch (TException e) {
		throw new CatalogException(
			String.format("Failed to list functions in database %s", databaseName), e);
	}
}
 
Example #13
Source File: HiveCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void alterDatabase(String databaseName, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
		throws DatabaseNotExistException, CatalogException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");
	checkNotNull(newDatabase, "newDatabase cannot be null");

	// client.alterDatabase doesn't throw any exception if there is no existing database
	if (!databaseExists(databaseName)) {
		if (!ignoreIfNotExists) {
			throw new DatabaseNotExistException(getName(), databaseName);
		}

		return;
	}

	Database newHiveDatabase = instantiateHiveDatabase(databaseName, newDatabase);

	try {
		client.alterDatabase(databaseName, newHiveDatabase);
	} catch (TException e) {
		throw new CatalogException(String.format("Failed to alter database %s", databaseName), e);
	}
}
 
Example #14
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
		throws TableAlreadyExistException, DatabaseNotExistException {
	checkNotNull(tablePath);
	checkNotNull(table);

	if (!databaseExists(tablePath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), tablePath.getDatabaseName());
	}

	if (tableExists(tablePath)) {
		if (!ignoreIfExists) {
			throw new TableAlreadyExistException(getName(), tablePath);
		}
	} else {
		tables.put(tablePath, table.copy());

		if (isPartitionedTable(tablePath)) {
			partitions.put(tablePath, new LinkedHashMap<>());
			partitionStats.put(tablePath, new LinkedHashMap<>());
			partitionColumnStats.put(tablePath, new LinkedHashMap<>());
		}
	}
}
 
Example #15
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws TableAlreadyExistException, DatabaseNotExistException {
	final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
	final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
	final TableSchema tableSchema = TableSchema.builder()
		.field("a", DataTypes.BIGINT())
		.field("b", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.field("c", DataTypes.INT())
		.field("d", DataTypes.VARCHAR(Integer.MAX_VALUE))
		.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("connector", "COLLECTION");
	final CatalogTable catalogTable =  new CatalogTableImpl(tableSchema, properties, "");
	catalog.createTable(path1, catalogTable, true);
	catalog.createTable(path2, catalogTable, true);
}
 
Example #16
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void alterDatabase(String databaseName, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
		throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName));
	checkNotNull(newDatabase);

	CatalogDatabase existingDatabase = databases.get(databaseName);

	if (existingDatabase != null) {
		if (existingDatabase.getClass() != newDatabase.getClass()) {
			throw new CatalogException(
				String.format("Database types don't match. Existing database is '%s' and new database is '%s'.",
					existingDatabase.getClass().getName(), newDatabase.getClass().getName())
			);
		}

		databases.put(databaseName, newDatabase.copy());
	} else if (!ignoreIfNotExists) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}
}
 
Example #17
Source File: KuduCatalog.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listTables(String databaseName) throws DatabaseNotExistException, CatalogException {
    checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

    if (!databaseExists(databaseName)) {
        throw new DatabaseNotExistException(getName(), databaseName);
    }

    try {
        return kuduClient.getTablesList().getTablesList();
    } catch (Throwable t) {
        throw new CatalogException("Could not list tables", t);
    }
}
 
Example #18
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTableWithWatermark() throws FunctionAlreadyExistException, DatabaseNotExistException {
	CatalogFunction cf = new CatalogFunctionImpl(
		JavaUserDefinedScalarFunctions.JavaFunc5.class.getName());
	catalog.createFunction(ObjectPath.fromString("default.myfunc"), cf, true);

	final String sql = "create table source_table(\n" +
		"  a int,\n" +
		"  b bigint,\n" +
		"  c timestamp(3),\n" +
		"  watermark for `c` as myfunc(c, 1) - interval '5' second\n" +
		") with (\n" +
		"  'connector.type' = 'kafka')\n";
	final FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
	final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
	SqlNode node = parser.parse(sql);
	assert node instanceof SqlCreateTable;
	Operation operation = SqlToOperationConverter.convert(planner, catalogManager, node).get();
	assert operation instanceof CreateTableOperation;
	CreateTableOperation op = (CreateTableOperation) operation;
	CatalogTable catalogTable = op.getCatalogTable();
	Map<String, String> properties = catalogTable.toProperties();
	Map<String, String> expected = new HashMap<>();
	expected.put("schema.0.name", "a");
	expected.put("schema.0.data-type", "INT");
	expected.put("schema.1.name", "b");
	expected.put("schema.1.data-type", "BIGINT");
	expected.put("schema.2.name", "c");
	expected.put("schema.2.data-type", "TIMESTAMP(3)");
	expected.put("schema.watermark.0.rowtime", "c");
	expected.put(
		"schema.watermark.0.strategy.expr",
		"`builtin`.`default`.`myfunc`(`c`, 1) - INTERVAL '5' SECOND");
	expected.put("schema.watermark.0.strategy.data-type", "TIMESTAMP(3)");
	expected.put("connector.type", "kafka");
	assertEquals(expected, properties);
}
 
Example #19
Source File: SqlToOperationConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Convert ALTER DATABASE statement. */
private Operation convertAlterDatabase(SqlAlterDatabase sqlAlterDatabase) {
	String[] fullDatabaseName = sqlAlterDatabase.fullDatabaseName();
	if (fullDatabaseName.length > 2) {
		throw new SqlConversionException("alter database identifier format error");
	}
	String catalogName = (fullDatabaseName.length == 1) ? catalogManager.getCurrentCatalog() : fullDatabaseName[0];
	String databaseName = (fullDatabaseName.length == 1) ? fullDatabaseName[0] : fullDatabaseName[1];
	Map<String, String> properties = new HashMap<>();
	CatalogDatabase originCatalogDatabase;
	Optional<Catalog> catalog = catalogManager.getCatalog(catalogName);
	if (catalog.isPresent()) {
		try {
			originCatalogDatabase = catalog.get().getDatabase(databaseName);
			properties.putAll(originCatalogDatabase.getProperties());
		} catch (DatabaseNotExistException e) {
			throw new SqlConversionException(String.format("Database %s not exists", databaseName), e);
		}
	} else {
		throw new SqlConversionException(String.format("Catalog %s not exists", catalogName));
	}
	// set with properties
	sqlAlterDatabase.getPropertyList().getList().forEach(p ->
		properties.put(((SqlTableOption) p).getKeyString(), ((SqlTableOption) p).getValueString()));
	CatalogDatabase catalogDatabase = new CatalogDatabaseImpl(properties, originCatalogDatabase.getComment());
	return new AlterDatabaseOperation(catalogName, databaseName, catalogDatabase);
}
 
Example #20
Source File: PostgresCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CatalogDatabase getDatabase(String databaseName) throws DatabaseNotExistException, CatalogException {
	if (listDatabases().contains(databaseName)) {
		return new CatalogDatabaseImpl(Collections.emptyMap(), null);
	} else {
		throw new DatabaseNotExistException(getName(), databaseName);
	}
}
 
Example #21
Source File: PostgresCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public boolean tableExists(ObjectPath tablePath) throws CatalogException {

	List<String> tables = null;
	try {
		tables = listTables(tablePath.getDatabaseName());
	} catch (DatabaseNotExistException e) {
		return false;
	}

	return tables.contains(PostgresTablePath.fromFlinkTableName(tablePath.getObjectName()).getFullPath());
}
 
Example #22
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CatalogDatabase getDatabase(String databaseName) throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName));

	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	} else {
		return databases.get(databaseName).copy();
	}
}
 
Example #23
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listTables(String databaseName) throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}

	return tables.keySet().stream()
		.filter(k -> k.getDatabaseName().equals(databaseName)).map(k -> k.getObjectName())
		.collect(Collectors.toList());
}
 
Example #24
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listViews(String databaseName) throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}

	return tables.keySet().stream()
		.filter(k -> k.getDatabaseName().equals(databaseName))
		.filter(k -> (tables.get(k) instanceof CatalogView)).map(k -> k.getObjectName())
		.collect(Collectors.toList());
}
 
Example #25
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listFunctions(String databaseName) throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}

	return functions.keySet().stream()
		.filter(k -> k.getDatabaseName().equals(databaseName)).map(k -> k.getObjectName())
		.collect(Collectors.toList());
}
 
Example #26
Source File: TableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public String[] listTables() {
	String currentCatalogName = catalogManager.getCurrentCatalog();
	Optional<Catalog> currentCatalog = catalogManager.getCatalog(currentCatalogName);

	return currentCatalog.map(catalog -> {
		try {
			return catalog.listTables(catalogManager.getCurrentDatabase()).toArray(new String[0]);
		} catch (DatabaseNotExistException e) {
			throw new ValidationException("Current database does not exist", e);
		}
	}).orElseThrow(() ->
		new TableException(String.format("The current catalog %s does not exist.", currentCatalogName)));
}
 
Example #27
Source File: DatabaseCalciteSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getTableNames() {
	try {
		return new HashSet<>(catalog.listTables(databaseName));
	} catch (DatabaseNotExistException e) {
		throw new CatalogException(e);
	}
}
 
Example #28
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listFunctions(String databaseName) throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}

	return functions.keySet().stream()
		.filter(k -> k.getDatabaseName().equals(databaseName))
		.map(k -> k.getObjectName())
		.collect(Collectors.toList());
}
 
Example #29
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 #30
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listTables(String databaseName) throws DatabaseNotExistException {
	checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");

	if (!databaseExists(databaseName)) {
		throw new DatabaseNotExistException(getName(), databaseName);
	}

	return tables.keySet().stream()
		.filter(k -> k.getDatabaseName().equals(databaseName)).map(k -> k.getObjectName())
		.collect(Collectors.toList());
}