FANNG1 commented on code in PR #6543: URL: https://github.com/apache/gravitino/pull/6543#discussion_r1994566286
########## flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/jdbc/AbstractJdbcPropertiesConverter.java: ########## @@ -0,0 +1,87 @@ +/* + * 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 com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.apache.flink.configuration.Configuration; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** Test for {@link JdbcPropertiesConverter} */ +public abstract class AbstractJdbcPropertiesConverter { + + String username = "testUser"; + String password = "testPassword"; + String url = "testUrl"; + String defaultDatabase = "test"; + + Map<String, String> catalogProperties = + ImmutableMap.of( + JdbcPropertiesConstants.GRAVITINO_JDBC_USER, + username, + JdbcPropertiesConstants.GRAVITINO_JDBC_PASSWORD, + password, + JdbcPropertiesConstants.GRAVITINO_JDBC_URL, + url, + JdbcPropertiesConstants.GRAVITINO_JDBC_DEFAULT_DATABASE, + defaultDatabase); + + protected abstract JdbcPropertiesConverter getConverter(Map<String, String> catalogOptions); + + @Test + public void testToPaimonFileSystemCatalog() { Review Comment: `testToPaimonFileSystemCatalog` wrong name? ########## flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConverter.java: ########## @@ -0,0 +1,82 @@ +/* + * 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 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; + + 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) { + return PropertiesConverter.super.toFlinkCatalogProperties(gravitinoProperties); + } + + @Override + public String transformPropertyToGravitinoCatalog(String configKey) { + return JdbcPropertiesConstants.flinkToGravitinoMap.get(configKey); + } + + @Override + public String transformPropertyToFlinkCatalog(String configKey) { + return JdbcPropertiesConstants.gravitinoToFlinkMap.get(configKey); + } + + @Override + public Map<String, String> toFlinkTableProperties( + Map<String, String> gravitinoProperties, ObjectPath tablePath) { + Map<String, String> tableOptions = new HashMap<>(); + tableOptions.put( + "url", + catalogOptions.get(JdbcPropertiesConstants.FLINK_JDBC_URL) + + "/" + + tablePath.getDatabaseName()); + tableOptions.put("table-name", tablePath.getObjectName()); + tableOptions.put("username", catalogOptions.get(JdbcPropertiesConstants.FLINK_JDBC_USER)); Review Comment: how about reuse the properties defined in `JdbcPropertiesConstants` or define new properties ? ########## flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/jdbc/AbstractJdbcPropertiesConverter.java: ########## @@ -0,0 +1,87 @@ +/* + * 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 com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.apache.flink.configuration.Configuration; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** Test for {@link JdbcPropertiesConverter} */ +public abstract class AbstractJdbcPropertiesConverter { Review Comment: How about rename to `AbstractJdbcPropertiesConverterTestSuite`? ########## flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/jdbc/AbstractJdbcPropertiesConverter.java: ########## @@ -0,0 +1,87 @@ +/* + * 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 com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.apache.flink.configuration.Configuration; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** Test for {@link JdbcPropertiesConverter} */ +public abstract class AbstractJdbcPropertiesConverter { Review Comment: Could you add sepcific test for driver? as the transform logic is complicated. ########## flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConstants.java: ########## @@ -0,0 +1,54 @@ +/* + * 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; + +public class JdbcPropertiesConstants { + + private JdbcPropertiesConstants() {} + + public static final String GRAVITINO_JDBC_USER = "jdbc-user"; + public static final String GRAVITINO_JDBC_PASSWORD = "jdbc-password"; + public static final String GRAVITINO_JDBC_URL = "jdbc-url"; + public static final String GRAVITINO_JDBC_DRIVER = "jdbc-driver"; + public static final String GRAVITINO_JDBC_DEFAULT_DATABASE = "flink.bypass.default-database"; Review Comment: It's odd to place `GRAVITINO_JDBC_DEFAULT_DATABASE` here, could you remove it? ########## flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConverter.java: ########## @@ -0,0 +1,82 @@ +/* + * 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 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; + + 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) { + return PropertiesConverter.super.toFlinkCatalogProperties(gravitinoProperties); + } + + @Override + public String transformPropertyToGravitinoCatalog(String configKey) { + return JdbcPropertiesConstants.flinkToGravitinoMap.get(configKey); + } + + @Override + public String transformPropertyToFlinkCatalog(String configKey) { + return JdbcPropertiesConstants.gravitinoToFlinkMap.get(configKey); + } + + @Override + public Map<String, String> toFlinkTableProperties( + Map<String, String> gravitinoProperties, ObjectPath tablePath) { + Map<String, String> tableOptions = new HashMap<>(); Review Comment: If gravitinoProperties doesn't contain `driver`, should we return the driver from catalog properties? ########## flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/jdbc/GravitinoJdbcCatalogFactory.java: ########## @@ -0,0 +1,72 @@ +/* + * 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.Collections; +import java.util.Set; +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.table.factories.FactoryUtil; +import org.apache.flink.util.Preconditions; +import org.apache.gravitino.Catalog; +import org.apache.gravitino.flink.connector.PartitionConverter; +import org.apache.gravitino.flink.connector.UnsupportPartitionConverter; +import org.apache.gravitino.flink.connector.catalog.BaseCatalogFactory; +import org.apache.gravitino.flink.connector.utils.FactoryUtils; + +/** + * Factory for creating instances of {@link GravitinoJdbcCatalog}. It will be created by SPI + * discovery in Flink. + */ +public abstract class GravitinoJdbcCatalogFactory implements BaseCatalogFactory { + + @Override + public org.apache.flink.table.catalog.Catalog createCatalog(Context context) { + context.getOptions().remove(JdbcPropertiesConstants.FLINK_DRIVER); Review Comment: why removing FLINK_DRIVER ? -- 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]
