Java Code Examples for org.apache.flink.table.catalog.CatalogManager#TableLookupResult

The following examples show how to use org.apache.flink.table.catalog.CatalogManager#TableLookupResult . 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: SqlCreateTableConverter.java    From flink with Apache License 2.0 6 votes vote down vote up
private CatalogTable lookupLikeSourceTable(SqlTableLike sqlTableLike) {
	UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlTableLike.getSourceTable()
		.toString());
	ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
	CatalogManager.TableLookupResult lookupResult = catalogManager.getTable(identifier)
		.orElseThrow(() -> new ValidationException(String.format(
			"Source table '%s' of the LIKE clause not found in the catalog, at %s",
			identifier,
			sqlTableLike.getSourceTable().getParserPosition())));
	if (!(lookupResult.getTable() instanceof CatalogTable)) {
		throw new ValidationException(String.format(
			"Source table '%s' of the LIKE clause can not be a VIEW, at %s",
			identifier,
			sqlTableLike.getSourceTable().getParserPosition()));
	}
	return (CatalogTable) lookupResult.getTable();
}
 
Example 2
Source File: SqlToOperationConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
/** convert ALTER TABLE statement. */
private Operation convertAlterTable(SqlAlterTable sqlAlterTable) {
	UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlAlterTable.fullTableName());
	ObjectIdentifier tableIdentifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
	if (sqlAlterTable instanceof SqlAlterTableRename) {
		UnresolvedIdentifier newUnresolvedIdentifier =
			UnresolvedIdentifier.of(((SqlAlterTableRename) sqlAlterTable).fullNewTableName());
		ObjectIdentifier newTableIdentifier = catalogManager.qualifyIdentifier(newUnresolvedIdentifier);
		return new AlterTableRenameOperation(tableIdentifier, newTableIdentifier);
	} else if (sqlAlterTable instanceof SqlAlterTableProperties) {
		Optional<CatalogManager.TableLookupResult> optionalCatalogTable = catalogManager.getTable(tableIdentifier);
		if (optionalCatalogTable.isPresent() && !optionalCatalogTable.get().isTemporary()) {
			CatalogTable originalCatalogTable = (CatalogTable) optionalCatalogTable.get().getTable();
			Map<String, String> properties = new HashMap<>();
			properties.putAll(originalCatalogTable.getProperties());
			((SqlAlterTableProperties) sqlAlterTable).getPropertyList().getList().forEach(p ->
				properties.put(((SqlTableOption) p).getKeyString(), ((SqlTableOption) p).getValueString()));
			CatalogTable catalogTable = new CatalogTableImpl(
				originalCatalogTable.getSchema(),
				originalCatalogTable.getPartitionKeys(),
				properties,
				originalCatalogTable.getComment());
			return new AlterTablePropertiesOperation(tableIdentifier, catalogTable);
		} else {
			throw new ValidationException(String.format("Table %s doesn't exist or is a temporary table.",
				tableIdentifier.toString()));
		}
	} else {
		throw new ValidationException(
				String.format("[%s] needs to implement",
						sqlAlterTable.toSqlString(CalciteSqlDialect.DEFAULT)));
	}
}
 
Example 3
Source File: TableEnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConnect() {
	final TableEnvironmentMock tableEnv = TableEnvironmentMock.getStreamingInstance();

	tableEnv
		.connect(new ConnectorDescriptorMock(TableSourceFactoryMock.CONNECTOR_TYPE_VALUE, 1, true))
		.withFormat(new FormatDescriptorMock("my_format", 1))
		.withSchema(new Schema()
			.field("my_field_0", "INT")
			.field("my_field_1", "BOOLEAN")
			.field("my_part_1", "BIGINT")
			.field("my_part_2", "STRING"))
		.withPartitionKeys(Arrays.asList("my_part_1", "my_part_2"))
		.inAppendMode()
		.createTemporaryTable("my_table");

	CatalogManager.TableLookupResult lookupResult = tableEnv.catalogManager.getTable(ObjectIdentifier.of(
		EnvironmentSettings.DEFAULT_BUILTIN_CATALOG,
		EnvironmentSettings.DEFAULT_BUILTIN_DATABASE,
		"my_table"))
		.orElseThrow(AssertionError::new);

	assertThat(lookupResult.isTemporary(), equalTo(true));

	CatalogBaseTable catalogBaseTable = lookupResult.getTable();
	assertTrue(catalogBaseTable instanceof CatalogTable);
	CatalogTable table = (CatalogTable) catalogBaseTable;
	assertCatalogTable(table);
	assertCatalogTable(CatalogTableImpl.fromProperties(table.toProperties()));
}