Timm0 commented on code in PR #30166:
URL: https://github.com/apache/flink/pull/30166#discussion_r4718553342


##########
flink-table/flink-sql-jdbc-driver/src/test/java/org/apache/flink/table/jdbc/FlinkConnectionTest.java:
##########
@@ -26,72 +26,117 @@
 import java.sql.SQLException;
 import java.util.Properties;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 /** Tests for {@link FlinkConnection}. */
 public class FlinkConnectionTest extends FlinkJdbcDriverTestBase {
 
     @Test
-    public void testCatalogSchema() throws Exception {
+    void testCatalogSchema() throws Exception {
         try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
-            assertEquals("default_catalog", connection.getCatalog());
-            assertEquals("default_database", connection.getSchema());
-
-            assertThrowsExactly(
-                    SQLException.class,
-                    () -> connection.setCatalog("invalid_catalog"),
-                    "Set catalog[invalid_catalog] fail");
-            assertThrowsExactly(
-                    SQLException.class,
-                    () -> connection.setSchema("invalid_database"),
-                    "Set schema[invalid_database] fail");
-            assertEquals("default_catalog", connection.getCatalog());
-            assertEquals("default_database", connection.getSchema());
+            assertThat(connection.getCatalog()).isEqualTo("default_catalog");
+            assertThat(connection.getSchema()).isEqualTo("default_database");
+
+            assertThatThrownBy(() -> connection.setCatalog("invalid_catalog"))
+                    .as("Set catalog[invalid_catalog] fail")
+                    .isExactlyInstanceOf(SQLException.class);
+            assertThatThrownBy(() -> connection.setSchema("invalid_database"))
+                    .as("Set schema[invalid_database] fail")
+                    .isExactlyInstanceOf(SQLException.class);
+            assertThat(connection.getCatalog()).isEqualTo("default_catalog");
+            assertThat(connection.getSchema()).isEqualTo("default_database");
 
             // Create new catalog and database
             Executor executor = connection.getExecutor();
             StatementResult result =
                     executor.executeStatement(
                             "CREATE CATALOG test_catalog WITH 
('type'='generic_in_memory');");
-            assertTrue(result.hasNext());
-            assertEquals("OK", result.next().getString(0).toString());
+            assertThat(result.hasNext()).isTrue();
+            assertThat(result.next().getString(0).toString()).isEqualTo("OK");
             connection.setCatalog("test_catalog");
 
             result = executor.executeStatement("CREATE DATABASE 
test_database;");
-            assertTrue(result.hasNext());
-            assertEquals("OK", result.next().getString(0).toString());
+            assertThat(result.hasNext()).isTrue();
+            assertThat(result.next().getString(0).toString()).isEqualTo("OK");
             connection.setSchema("test_database");
 
-            assertEquals("test_catalog", connection.getCatalog());
-            assertEquals("test_database", connection.getSchema());
+            assertThat(connection.getCatalog()).isEqualTo("test_catalog");
+            assertThat(connection.getSchema()).isEqualTo("test_database");
+        }
+    }
+
+    @Test
+    void testSetCatalogWithQuotedName() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            Executor executor = connection.getExecutor();
+            StatementResult result =
+                    executor.executeStatement(
+                            "CREATE CATALOG `my catalog` WITH 
('type'='generic_in_memory');");
+            assertThat(result.hasNext()).isTrue();
+            assertThat(result.next().getString(0).toString()).isEqualTo("OK");
+
+            connection.setCatalog("my catalog");
+            assertThat(connection.getCatalog()).isEqualTo("my catalog");
+        }
+    }
+
+    @Test
+    void testSetClientInfoValueWithQuote() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            connection.setClientInfo("pipeline.name", "it's a job");
+            
assertThat(connection.getClientInfo("pipeline.name")).isEqualTo("it's a job");
+        }
+    }
+
+    @Test
+    void testSetClientInfoNullValue() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            assertThatCode(() -> connection.setClientInfo("pipeline.name", 
null))
+                    .doesNotThrowAnyException();
+        }
+    }
+
+    @Test
+    void testSetClientInfoNullName() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            assertThatCode(() -> connection.setClientInfo(null, 
"v")).doesNotThrowAnyException();
+        }
+    }
+
+    @Test
+    void testSetSchemaQualifiedName() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            connection.setSchema("default_catalog.default_database");

Review Comment:
   Could we maybe use schema here to validate that the individual escaping 
works like `default catalog.default database`?



##########
flink-table/flink-sql-jdbc-driver/src/main/java/org/apache/flink/table/jdbc/FlinkConnection.java:
##########
@@ -191,7 +197,11 @@ public void setClientInfo(String name, String value) 
throws SQLClientInfoExcepti
         } catch (SQLException e) {
             throw new SQLClientInfoException("Connection is closed", new 
HashMap<>(), e);
         }
-        executor.configureSession(String.format("SET '%s'='%s';", name, 
value));
+        executor.configureSession(

Review Comment:
   Based on the docs of `java.sql.Connection` shouldn't a `null` value here 
clear the option, but with this change it will change it to `"null"`?



##########
flink-table/flink-sql-jdbc-driver/src/test/java/org/apache/flink/table/jdbc/FlinkConnectionTest.java:
##########
@@ -26,72 +26,117 @@
 import java.sql.SQLException;
 import java.util.Properties;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 /** Tests for {@link FlinkConnection}. */
 public class FlinkConnectionTest extends FlinkJdbcDriverTestBase {
 
     @Test
-    public void testCatalogSchema() throws Exception {
+    void testCatalogSchema() throws Exception {
         try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
-            assertEquals("default_catalog", connection.getCatalog());
-            assertEquals("default_database", connection.getSchema());
-
-            assertThrowsExactly(
-                    SQLException.class,
-                    () -> connection.setCatalog("invalid_catalog"),
-                    "Set catalog[invalid_catalog] fail");
-            assertThrowsExactly(
-                    SQLException.class,
-                    () -> connection.setSchema("invalid_database"),
-                    "Set schema[invalid_database] fail");
-            assertEquals("default_catalog", connection.getCatalog());
-            assertEquals("default_database", connection.getSchema());
+            assertThat(connection.getCatalog()).isEqualTo("default_catalog");
+            assertThat(connection.getSchema()).isEqualTo("default_database");
+
+            assertThatThrownBy(() -> connection.setCatalog("invalid_catalog"))
+                    .as("Set catalog[invalid_catalog] fail")
+                    .isExactlyInstanceOf(SQLException.class);
+            assertThatThrownBy(() -> connection.setSchema("invalid_database"))
+                    .as("Set schema[invalid_database] fail")
+                    .isExactlyInstanceOf(SQLException.class);
+            assertThat(connection.getCatalog()).isEqualTo("default_catalog");
+            assertThat(connection.getSchema()).isEqualTo("default_database");
 
             // Create new catalog and database
             Executor executor = connection.getExecutor();
             StatementResult result =
                     executor.executeStatement(
                             "CREATE CATALOG test_catalog WITH 
('type'='generic_in_memory');");
-            assertTrue(result.hasNext());
-            assertEquals("OK", result.next().getString(0).toString());
+            assertThat(result.hasNext()).isTrue();
+            assertThat(result.next().getString(0).toString()).isEqualTo("OK");
             connection.setCatalog("test_catalog");
 
             result = executor.executeStatement("CREATE DATABASE 
test_database;");
-            assertTrue(result.hasNext());
-            assertEquals("OK", result.next().getString(0).toString());
+            assertThat(result.hasNext()).isTrue();
+            assertThat(result.next().getString(0).toString()).isEqualTo("OK");
             connection.setSchema("test_database");
 
-            assertEquals("test_catalog", connection.getCatalog());
-            assertEquals("test_database", connection.getSchema());
+            assertThat(connection.getCatalog()).isEqualTo("test_catalog");
+            assertThat(connection.getSchema()).isEqualTo("test_database");
+        }
+    }
+
+    @Test
+    void testSetCatalogWithQuotedName() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            Executor executor = connection.getExecutor();
+            StatementResult result =
+                    executor.executeStatement(
+                            "CREATE CATALOG `my catalog` WITH 
('type'='generic_in_memory');");
+            assertThat(result.hasNext()).isTrue();
+            assertThat(result.next().getString(0).toString()).isEqualTo("OK");
+
+            connection.setCatalog("my catalog");
+            assertThat(connection.getCatalog()).isEqualTo("my catalog");
+        }
+    }
+
+    @Test
+    void testSetClientInfoValueWithQuote() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            connection.setClientInfo("pipeline.name", "it's a job");
+            
assertThat(connection.getClientInfo("pipeline.name")).isEqualTo("it's a job");
+        }
+    }
+
+    @Test
+    void testSetClientInfoNullValue() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            assertThatCode(() -> connection.setClientInfo("pipeline.name", 
null))
+                    .doesNotThrowAnyException();
+        }
+    }
+
+    @Test
+    void testSetClientInfoNullName() throws Exception {
+        try (FlinkConnection connection = new FlinkConnection(getDriverUri())) 
{
+            assertThatCode(() -> connection.setClientInfo(null, 
"v")).doesNotThrowAnyException();

Review Comment:
   Shouldn't this throw an exception since `null` should not be valid value for 
a key?



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