-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
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")); |
There was a problem hiding this comment.
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)
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
Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: yesDocumentation