FANNG1 commented on code in PR #6543:
URL: https://github.com/apache/gravitino/pull/6543#discussion_r1998672156


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConverter.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.flink.connector.jdbc;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.gravitino.flink.connector.PropertiesConverter;
+
+public abstract class JdbcPropertiesConverter implements PropertiesConverter {
+
+  private final Map<String, String> catalogOptions;
+
+  private static final Pattern jdbcUrlPattern = 
Pattern.compile("(jdbc:\\w+://[^:/]+(?::\\d+)?)");
+
+  protected JdbcPropertiesConverter(Map<String, String> catalogOptions) {
+    this.catalogOptions = catalogOptions;
+  }
+
+  @Override
+  public Map<String, String> toGravitinoCatalogProperties(Configuration 
flinkConf) {
+    Map<String, String> gravitinoCatalogProperties =
+        PropertiesConverter.super.toGravitinoCatalogProperties(flinkConf);
+    if 
(!gravitinoCatalogProperties.containsKey(JdbcPropertiesConstants.GRAVITINO_JDBC_DRIVER))
 {
+      gravitinoCatalogProperties.put(
+          JdbcPropertiesConstants.GRAVITINO_JDBC_DRIVER, defaultDriverName());
+    }
+    return gravitinoCatalogProperties;
+  }
+
+  @Override
+  public Map<String, String> toFlinkCatalogProperties(Map<String, String> 
gravitinoProperties) {
+    Map<String, String> flinkCatalogProperties =
+        
PropertiesConverter.super.toFlinkCatalogProperties(gravitinoProperties);
+    String gravitinoJdbcUrl = 
gravitinoProperties.get(JdbcPropertiesConstants.GRAVITINO_JDBC_URL);
+    // The URL in FlinkJdbcCatalog does not support database and other 
parameters.
+    flinkCatalogProperties.put(
+        JdbcPropertiesConstants.FLINK_JDBC_URL, 
getBaseUrlFromJdbcUrl(gravitinoJdbcUrl));
+    return flinkCatalogProperties;
+  }
+
+  private static String getBaseUrlFromJdbcUrl(String jdbcUrl) {

Review Comment:
   Could you place the private method to the last of the class?



##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalogFactory.java:
##########
@@ -43,9 +44,13 @@ public interface BaseCatalogFactory extends CatalogFactory {
   /**
    * Define properties converter {@link PropertiesConverter}.
    *
+   * @param catalogOptions Some catalogs (such as {@link
+   *     org.apache.gravitino.flink.connector.jdbc.GravitinoJdbcCatalog}) 
require the use of catalog
+   *     options when creating a table, as these options will not be returned 
by the
+   *     GravitinoServer.
    * @return The requested property converter.
    */
-  PropertiesConverter propertiesConverter();
+  PropertiesConverter propertiesConverter(Map<String, String> catalogOptions);

Review Comment:
   `catalogOptions` seems unclear and bugy, in 
`GravitinoJdbcCatalogFactory.createCatalog` context, it's the 
context.getOptions() from Flink, in `loadCatalog` context it's the catalog 
properties from Gravitino.  this may make other confusing.



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