Hisoka-X commented on code in PR #7484:
URL: https://github.com/apache/seatunnel/pull/7484#discussion_r1729797033
##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/utils/CatalogUtils.java:
##########
@@ -272,6 +272,16 @@ public static CatalogTable getCatalogTable(
throws SQLException {
TableSchema.Builder schemaBuilder = TableSchema.builder();
Map<String, String> unsupported = new LinkedHashMap<>();
+ String tableName = null;
+ String databaseName = null;
+ String schemaName = null;
+ try {
+ int columnCount = metadata.getColumnCount();
+ tableName = metadata.getTableName(columnCount);
+ databaseName = metadata.getCatalogName(columnCount);
+ schemaName = metadata.getSchemaName(columnCount);
Review Comment:
Why we need `getTableName` with `columnCount`? Is this way of api design?
##########
seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/JdbcCatalogUtilsTest.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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
org.apache.seatunnel.connectors.seatunnel.jdbc.config.JdbcConnectionConfig;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.config.JdbcSourceTableConfig;
+import org.apache.seatunnel.connectors.seatunnel.jdbc.utils.JdbcCatalogUtils;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+@Disabled("Configure your own environment")
+public class JdbcCatalogUtilsTest {
+
+ @Test
+ public void test() throws SQLException, ClassNotFoundException {
+ List<JdbcSourceTableConfig> tablesConfig = new ArrayList<>();
+ // JdbcSourceTableConfig(tablePath=null, query=select age, name,gender
from `dbs`.`user`,
+ // partitionColumn=null, partitionNumber=10, partitionStart=null,
partitionEnd=null,
+ // useSelectCount=false, skipAnalyze=false)
+ JdbcSourceTableConfig tableConfig =
+ JdbcSourceTableConfig.builder()
+ .query("SELECT age, user1.name AS name1, gender FROM
user1 ; ")
+ .useSelectCount(false)
+ .build();
+ tablesConfig.add(tableConfig);
+ JdbcCatalogUtils.getTables(
+ JdbcConnectionConfig.builder()
+ .url(
+
"jdbc:mysql://xxxx:3306/xxx?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true")
+ .username("root")
+ .password("xxxxxx")
+ .build(),
+ tablesConfig);
Review Comment:
Please put this test case into
https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e
and enable it.
##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/utils/CatalogUtils.java:
##########
@@ -290,7 +300,11 @@ public static CatalogTable getCatalogTable(
}
String catalogName = "jdbc_catalog";
return CatalogTable.of(
- TableIdentifier.of(catalogName, "default", "default",
"default"),
+ TableIdentifier.of(
+ catalogName,
+ StringUtils.isBlank(databaseName) ? null :
databaseName,
+ StringUtils.isBlank(schemaName) ? null : schemaName,
+ StringUtils.isBlank(tableName) ? "default" :
tableName),
Review Comment:
Please keep the old logic. The default TablePath should be
`default.default.default`.
--
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]