gustavodemorais commented on code in PR #25704:
URL: https://github.com/apache/flink/pull/25704#discussion_r1861751435


##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/api/TableEnvironmentTest.java:
##########
@@ -100,6 +101,55 @@ void testCreateTableFromDescriptor() throws Exception {
                 .contains(entry("connector", "fake"), entry("a", "Test"));
     }
 
+    @Test
+    void testCreateTableIfNotExistsFromDescriptor() throws Exception {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+        final String catalog = tEnv.getCurrentCatalog();
+        final String database = tEnv.getCurrentDatabase();
+
+        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"));
+
+        assertThatNoException()
+                .isThrownBy(
+                        () ->
+                                tEnv.createTable(
+                                        "T",
+                                        TableDescriptor.forConnector("fake")
+                                                .schema(schema)
+                                                .option("a", "Test")
+                                                .build(),
+                                        true));
+
+        assertThatThrownBy(
+                        () ->
+                                tEnv.createTable(
+                                        "T",
+                                        TableDescriptor.forConnector("fake")
+                                                .schema(schema)
+                                                .option("a", "Test")
+                                                .build(),
+                                        false))
+                .isInstanceOf(ValidationException.class);

Review Comment:
   Yes, that works



-- 
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]

Reply via email to