Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-36809][table] Support ignoreIfExists param for createTable #25704

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gustavodemorais
Copy link

What is the purpose of the change

Support ignoreIfExists for createTable. Works exactly the same way for other resources, like createFunction. Similar to SQL's IF NOT EXISTS.

Brief change log

  • Added one more signature for TableEnvironment's createTable supporting ignoreIfExists
  • Added testCreateTableIfNotExistsFromDescriptor

Verifying this change

This change added tests and can be verified as follows:

  • Added test that validates that running createTable, with ignoreIfExists set to true, for an existing table leads to a no op. Also checks it doing the same ignoreIfExists set to false throws an exception.

Does this pull request potentially affect one of the following parts:

  • The public API, i.e., is any changed class annotated with @Public(Evolving): yes
  • Dependencies (does it add or upgrade a dependency): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? JavaDocs

@flinkbot
Copy link
Collaborator

flinkbot commented Nov 27, 2024

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

Copy link
Contributor

@twalthr twalthr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to the Flink community!

* in the catalog.
*
* <p>If the table should not be permanently stored in a catalog, use {@link
* #createTemporaryTable(String, TableDescriptor)} instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also support the boolean flag for createTemporaryTable and link it here

* @param ignoreIfExists If a table exists under the given path and this flag is set, no
* operation is executed. An exception is thrown otherwise.
*/
void createTable(String path, TableDescriptor descriptor, boolean ignoreIfExists);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check whether Python already supports createTable with TableDescriptors. if yes, we should also add the method there. check flink/flink-python/pyflink/table/table_environment.py

.option("a", "Test")
.build(),
false))
.isInstanceOf(ValidationException.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally, we should also check the error message. at least parts of it. hasMessageContaining could do the job?

Comment on lines +110 to +128
final Schema schema = Schema.newBuilder().column("f0", DataTypes.INT()).build();
tEnv.createTable(
"T",
TableDescriptor.forConnector("fake").schema(schema).option("a", "Test").build(),
true);

final ObjectPath objectPath = new ObjectPath(database, "T");
assertThat(
tEnv.getCatalog(catalog)
.orElseThrow(AssertionError::new)
.tableExists(objectPath))
.isTrue();

final CatalogBaseTable catalogTable =
tEnv.getCatalog(catalog).orElseThrow(AssertionError::new).getTable(objectPath);
assertThat(catalogTable).isInstanceOf(CatalogTable.class);
assertThat(catalogTable.getUnresolvedSchema()).isEqualTo(schema);
assertThat(catalogTable.getOptions())
.contains(entry("connector", "fake"), entry("a", "Test"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is duplicated with the test above. create a private helper method e.g. assertTableFromDescriptor(String name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants