You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/06/21 02:33:40 UTC

[GitHub] [incubator-seatunnel] ashulin opened a new pull request, #2042: [api-draft][catalog] jdbc catalog

ashulin opened a new pull request, #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042

   # Conflicts:
   #	seatunnel-connectors/seatunnel-connectors-seatunnel/pom.xml
   
   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   add jdbc catalog
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r905742087


##########
pom.xml:
##########
@@ -514,6 +515,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>

Review Comment:
   I added some parameterized test cases.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
Hisoka-X commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r905745475


##########
pom.xml:
##########
@@ -514,6 +515,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>

Review Comment:
   If we use junit5, can we remove older version from pom?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r905695206


##########
pom.xml:
##########
@@ -514,6 +515,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>

Review Comment:
   This is added in `dependencyManagement`.
   I expect the new module to be tested using junit5, using @parameterizedtest, @enabledonos, etc



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r906249665


##########
pom.xml:
##########
@@ -514,6 +515,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>

Review Comment:
   If we remove junit4, we need to modify the code of the old API. Are we going to do this?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] Hisoka-X merged pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
Hisoka-X merged PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
Hisoka-X commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r906611078


##########
pom.xml:
##########
@@ -514,6 +515,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>

Review Comment:
   @CalvinKirs @ruanwenjun 



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r905695206


##########
pom.xml:
##########
@@ -514,6 +515,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>

Review Comment:
   This is added in `dependencyManagement`.
   I expect the new module to be tested using junit5, using @ParameterizedTest, @EnabledOnOs, etc



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r905717564


##########
seatunnel-connectors/seatunnel-connectors-seatunnel/seatunnel-connector-seatunnel-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.jdbc.catalog;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import org.apache.seatunnel.api.table.catalog.Catalog;
+import org.apache.seatunnel.api.table.catalog.TablePath;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.catalog.exception.CatalogException;
+import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public abstract class AbstractJdbcCatalog implements Catalog {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractJdbcCatalog.class);
+
+    protected final String catalogName;
+    protected final String defaultDatabase;
+    protected final String username;
+    protected final String pwd;
+    protected final String baseUrl;
+    protected final String defaultUrl;
+
+    public AbstractJdbcCatalog(
+        String catalogName,
+        String defaultDatabase,
+        String username,
+        String pwd,
+        String baseUrl) {
+
+        checkArgument(StringUtils.isNotBlank(username));
+        checkArgument(StringUtils.isNotBlank(pwd));
+        checkArgument(StringUtils.isNotBlank(baseUrl));
+
+        validateJdbcUrl(baseUrl);
+        this.catalogName = catalogName;
+        this.defaultDatabase = defaultDatabase;
+        this.username = username;
+        this.pwd = pwd;
+        this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
+        this.defaultUrl = this.baseUrl + defaultDatabase;
+    }
+
+    /**
+     * URL has to be without database, like "jdbc:postgresql://localhost:5432/" or
+     * "jdbc:postgresql://localhost:5432" rather than "jdbc:postgresql://localhost:5432/db".
+     */
+    public static void validateJdbcUrl(String url) {
+        String[] parts = url.trim().split("\\/+");
+
+        checkArgument(parts.length == 2);
+    }
+
+    @Override
+    public String getDefaultDatabase() {
+        return defaultDatabase;
+    }
+
+    public String getCatalogName() {
+        return catalogName;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return pwd;
+    }
+
+    public String getBaseUrl() {
+        return baseUrl;
+    }
+
+    @SuppressWarnings("EmptyBlock")

Review Comment:
   I'll give it a try.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
Hisoka-X commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r905662890


##########
pom.xml:
##########
@@ -514,6 +515,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>

Review Comment:
   Hi, I didn't find the reason about add this dependency



##########
seatunnel-connectors/seatunnel-connectors-seatunnel/seatunnel-connector-seatunnel-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.jdbc.catalog;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import org.apache.seatunnel.api.table.catalog.Catalog;
+import org.apache.seatunnel.api.table.catalog.TablePath;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.catalog.exception.CatalogException;
+import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public abstract class AbstractJdbcCatalog implements Catalog {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractJdbcCatalog.class);
+
+    protected final String catalogName;
+    protected final String defaultDatabase;
+    protected final String username;
+    protected final String pwd;
+    protected final String baseUrl;
+    protected final String defaultUrl;
+
+    public AbstractJdbcCatalog(
+        String catalogName,
+        String defaultDatabase,
+        String username,
+        String pwd,
+        String baseUrl) {
+
+        checkArgument(StringUtils.isNotBlank(username));
+        checkArgument(StringUtils.isNotBlank(pwd));
+        checkArgument(StringUtils.isNotBlank(baseUrl));
+
+        validateJdbcUrl(baseUrl);
+        this.catalogName = catalogName;
+        this.defaultDatabase = defaultDatabase;
+        this.username = username;
+        this.pwd = pwd;
+        this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
+        this.defaultUrl = this.baseUrl + defaultDatabase;
+    }
+
+    /**
+     * URL has to be without database, like "jdbc:postgresql://localhost:5432/" or
+     * "jdbc:postgresql://localhost:5432" rather than "jdbc:postgresql://localhost:5432/db".
+     */
+    public static void validateJdbcUrl(String url) {

Review Comment:
   Maybe can create another constructor, use jdbcurl but no `defaultDatabase` parameter, the defaultDatabase set by jdbcurl. then user can set `defaultDatabase` just use url.



##########
seatunnel-connectors/seatunnel-connectors-seatunnel/seatunnel-connector-seatunnel-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.jdbc.catalog;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import org.apache.seatunnel.api.table.catalog.Catalog;
+import org.apache.seatunnel.api.table.catalog.TablePath;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.catalog.exception.CatalogException;
+import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public abstract class AbstractJdbcCatalog implements Catalog {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractJdbcCatalog.class);
+
+    protected final String catalogName;
+    protected final String defaultDatabase;
+    protected final String username;
+    protected final String pwd;
+    protected final String baseUrl;
+    protected final String defaultUrl;
+
+    public AbstractJdbcCatalog(
+        String catalogName,
+        String defaultDatabase,
+        String username,
+        String pwd,
+        String baseUrl) {
+
+        checkArgument(StringUtils.isNotBlank(username));
+        checkArgument(StringUtils.isNotBlank(pwd));
+        checkArgument(StringUtils.isNotBlank(baseUrl));
+
+        validateJdbcUrl(baseUrl);
+        this.catalogName = catalogName;
+        this.defaultDatabase = defaultDatabase;
+        this.username = username;
+        this.pwd = pwd;
+        this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
+        this.defaultUrl = this.baseUrl + defaultDatabase;
+    }
+
+    /**
+     * URL has to be without database, like "jdbc:postgresql://localhost:5432/" or
+     * "jdbc:postgresql://localhost:5432" rather than "jdbc:postgresql://localhost:5432/db".
+     */
+    public static void validateJdbcUrl(String url) {
+        String[] parts = url.trim().split("\\/+");
+
+        checkArgument(parts.length == 2);
+    }
+
+    @Override
+    public String getDefaultDatabase() {
+        return defaultDatabase;
+    }
+
+    public String getCatalogName() {
+        return catalogName;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return pwd;
+    }
+
+    public String getBaseUrl() {
+        return baseUrl;
+    }
+
+    @SuppressWarnings("EmptyBlock")

Review Comment:
   add a comment in try statement can avoid `EmptyBolck`



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2042: [api-draft][catalog] jdbc catalog

Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2042:
URL: https://github.com/apache/incubator-seatunnel/pull/2042#discussion_r905697135


##########
seatunnel-connectors/seatunnel-connectors-seatunnel/seatunnel-connector-seatunnel-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.jdbc.catalog;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import org.apache.seatunnel.api.table.catalog.Catalog;
+import org.apache.seatunnel.api.table.catalog.TablePath;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.catalog.exception.CatalogException;
+import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public abstract class AbstractJdbcCatalog implements Catalog {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractJdbcCatalog.class);
+
+    protected final String catalogName;
+    protected final String defaultDatabase;
+    protected final String username;
+    protected final String pwd;
+    protected final String baseUrl;
+    protected final String defaultUrl;
+
+    public AbstractJdbcCatalog(
+        String catalogName,
+        String defaultDatabase,
+        String username,
+        String pwd,
+        String baseUrl) {
+
+        checkArgument(StringUtils.isNotBlank(username));
+        checkArgument(StringUtils.isNotBlank(pwd));
+        checkArgument(StringUtils.isNotBlank(baseUrl));
+
+        validateJdbcUrl(baseUrl);
+        this.catalogName = catalogName;
+        this.defaultDatabase = defaultDatabase;
+        this.username = username;
+        this.pwd = pwd;
+        this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
+        this.defaultUrl = this.baseUrl + defaultDatabase;
+    }
+
+    /**
+     * URL has to be without database, like "jdbc:postgresql://localhost:5432/" or
+     * "jdbc:postgresql://localhost:5432" rather than "jdbc:postgresql://localhost:5432/db".
+     */
+    public static void validateJdbcUrl(String url) {

Review Comment:
   You have a point there.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org