This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 2a019dd2a416a8a4edbfc5f80fef0b543ce5754e Author: Qi Chen <[email protected]> AuthorDate: Fri May 26 21:35:38 2023 +0800 [Fix](multi-catalog) Fix db name is not lower case when jdbc catalog configuration `lower_case_table_names` is `true`. (#20021) Fix db name is not lower case when jdbc catalog configuration lower_case_table_names is true. Fix regression-test test_oracle_jdbc_catalog. --- .../org/apache/doris/external/jdbc/JdbcClient.java | 18 +++++++++++++++++- .../data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out | 6 +++--- .../jdbc_catalog_p0/test_oracle_jdbc_catalog.groovy | 5 +++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java index cd835f4162..3f635fc762 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java @@ -65,6 +65,9 @@ public class JdbcClient { // only used when isLowerCaseTableNames = true. private Map<String, String> lowerTableToRealTable = Maps.newHashMap(); + // only used when isLowerCaseTableNames = true. + private Map<String, String> lowerDBToRealDB = Maps.newHashMap(); + public JdbcClient(String user, String password, String jdbcUrl, String driverUrl, String driverClass, String onlySpecifiedDatabase, String isLowerCaseTableNames) { this.jdbcUser = user; @@ -204,7 +207,12 @@ public class JdbcClient { } while (rs.next()) { - databaseNames.add(rs.getString(1)); + String databaseName = rs.getString(1); + if (isLowerCaseTableNames) { + lowerDBToRealDB.put(databaseName.toLowerCase(), databaseName); + databaseName = databaseName.toLowerCase(); + } + databaseNames.add(databaseName); } } catch (SQLException e) { throw new JdbcClientException("failed to get database name list from jdbc", e); @@ -246,6 +254,9 @@ public class JdbcClient { public List<String> getTablesNameList(String dbName) { Connection conn = getConnection(); ResultSet rs = null; + if (isLowerCaseTableNames) { + dbName = lowerDBToRealDB.get(dbName); + } List<String> tablesName = Lists.newArrayList(); String[] types = {"TABLE", "VIEW"}; String[] hanaTypes = {"TABLE", "VIEW", "OLAP VIEW", "JOIN VIEW", "HIERARCHY VIEW", "CALC VIEW"}; @@ -290,6 +301,10 @@ public class JdbcClient { public boolean isTableExist(String dbName, String tableName) { Connection conn = getConnection(); ResultSet rs = null; + if (isLowerCaseTableNames) { + dbName = lowerDBToRealDB.get(dbName); + tableName = lowerTableToRealTable.get(tableName); + } String[] types = {"TABLE", "VIEW"}; String[] hanaTypes = {"TABLE", "VIEW", "OLAP VIEW", "JOIN VIEW", "HIERARCHY VIEW", "CALC VIEW"}; try { @@ -358,6 +373,7 @@ public class JdbcClient { // if isLowerCaseTableNames == true, tableName is lower case // but databaseMetaData.getColumns() is case sensitive if (isLowerCaseTableNames) { + dbName = lowerDBToRealDB.get(dbName); tableName = lowerTableToRealTable.get(tableName); } try { diff --git a/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out b/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out index fdfda85e67..89607848a5 100644 --- a/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out +++ b/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out @@ -34,9 +34,9 @@ -- !test6 -- 1 2013-01-21T05:23:01 \N \N \N \N \N 2 2013-11-12T20:32:56 \N \N \N \N \N -3 \N 2019-11-12T20:33:57 \N \N \N \N -4 \N \N 2019-11-12T20:33:57 \N \N \N -5 \N \N \N 2019-11-12T20:33:57 \N \N +3 \N 2019-11-12T20:33:57.999998 \N \N \N \N +4 \N \N 2019-11-12T20:33:57.999996 \N \N \N +5 \N \N \N 2019-11-12T20:33:57.999997 \N \N 6 \N \N \N \N 11-0 \N 7 \N \N \N \N 223-9 \N 8 \N \N \N \N \N 12 10:23:1.123457 diff --git a/regression-test/suites/jdbc_catalog_p0/test_oracle_jdbc_catalog.groovy b/regression-test/suites/jdbc_catalog_p0/test_oracle_jdbc_catalog.groovy index ee20b76706..00b03994f3 100644 --- a/regression-test/suites/jdbc_catalog_p0/test_oracle_jdbc_catalog.groovy +++ b/regression-test/suites/jdbc_catalog_p0/test_oracle_jdbc_catalog.groovy @@ -22,6 +22,7 @@ suite("test_oracle_jdbc_catalog", "p0") { String catalog_name = "oracle_catalog"; String internal_db_name = "regression_test_jdbc_catalog_p0"; String ex_db_name = "DORIS_TEST"; + String ex_db_name_lower_case = ex_db_name.toLowerCase(); String oracle_port = context.config.otherConfigs.get("oracle_11_port"); String SID = "XE"; String test_insert = "TEST_INSERT"; @@ -36,7 +37,7 @@ suite("test_oracle_jdbc_catalog", "p0") { "user"="doris_test", "password"="123456", "jdbc_url" = "jdbc:oracle:thin:@127.0.0.1:${oracle_port}:${SID}", - "driver_url" = "https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/jdbc_driver/ojdbc6.jar", + "driver_url" = "https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/jdbc_driver/ojdbc8.jar", "driver_class" = "oracle.jdbc.driver.OracleDriver" );""" @@ -117,7 +118,7 @@ suite("test_oracle_jdbc_catalog", "p0") { );""" sql """ CREATE CATALOG ${catalog_name} WITH RESOURCE ${resource_name} """ sql """ switch ${catalog_name} """ - sql """ use ${ex_db_name}""" + sql """ use ${ex_db_name_lower_case}""" qt_lower_case_table_names1 """ select * from test_num order by ID; """ qt_lower_case_table_names2 """ select * from test_char order by ID; """ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
