Tartarus0zm commented on code in PR #22995:
URL: https://github.com/apache/flink/pull/22995#discussion_r1266118841
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java:
##########
@@ -833,79 +832,106 @@ public TableResultInternal
executeInternal(List<ModifyOperation> operations) {
return executeInternal(transformations, sinkIdentifierNames,
jobStatusHookList);
}
- private ModifyOperation getOperation(ReplaceTableAsOperation
rtasOperation) {
- // rtas drop table first, then create
+ private ModifyOperation getModifyOperation(
+ ReplaceTableAsOperation rtasOperation, List<JobStatusHook>
jobStatusHookList) {
CreateTableOperation createTableOperation =
rtasOperation.getCreateTableOperation();
ObjectIdentifier tableIdentifier =
createTableOperation.getTableIdentifier();
- try {
- catalogManager.dropTable(tableIdentifier,
rtasOperation.isCreateOrReplace());
- } catch (ValidationException e) {
- if (String.format(
- "Table with identifier '%s' does not exist.",
- tableIdentifier.asSummaryString())
- .equals(e.getMessage())) {
- throw new TableException(
- String.format(
- "The table %s to be replaced doesn't exist. "
- + "You can try to use CREATE TABLE AS
statement or "
- + "CREATE OR REPLACE TABLE AS
statement.",
- tableIdentifier));
- } else {
- throw e;
- }
+ // First check if the replacedTable exists
+ Optional<ContextResolvedTable> replacedTable =
catalogManager.getTable(tableIdentifier);
+ if (!rtasOperation.isCreateOrReplace() && !replacedTable.isPresent()) {
+ throw new TableException(
+ String.format(
+ "The table %s to be replaced doesn't exist. "
+ + "You can try to use CREATE TABLE AS
statement or "
+ + "CREATE OR REPLACE TABLE AS statement.",
+ tableIdentifier));
}
+ Catalog catalog =
catalogManager.getCatalog(tableIdentifier.getCatalogName()).orElse(null);
Review Comment:
good catch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]