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/24 03:25:00 UTC

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

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