This is an automated email from the ASF dual-hosted git repository.
zykkk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d18d272ac2 [improvement](jdbc catalog) Added create jdbc catalog
properties validation (#23764)
d18d272ac2 is described below
commit d18d272ac2f26586de26ccbb45035f193ff4d562
Author: zy-kkk <[email protected]>
AuthorDate: Mon Sep 11 10:38:53 2023 +0800
[improvement](jdbc catalog) Added create jdbc catalog properties validation
(#23764)
---
.../doris/datasource/jdbc/JdbcExternalCatalog.java | 17 ++++++
.../datasource/jdbc/JdbcExternalCatalogTest.java | 63 ++++++++++++++++++++++
2 files changed, 80 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalCatalog.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalCatalog.java
index 7617ad7180..9b2d9b00f8 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalCatalog.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalCatalog.java
@@ -177,5 +177,22 @@ public class JdbcExternalCatalog extends ExternalCatalog {
properties.put(JdbcResource.CHECK_SUM,
JdbcResource.computeObjectChecksum(properties.get(JdbcResource.DRIVER_URL)));
}
+ String onlySpecifiedDatabase = getOnlySpecifiedDatabase();
+ if (!onlySpecifiedDatabase.equalsIgnoreCase("true") &&
!onlySpecifiedDatabase.equalsIgnoreCase("false")) {
+ throw new DdlException("only_specified_database must be true or
false");
+ }
+ String lowerCaseTableNames = getLowerCaseTableNames();
+ if (!lowerCaseTableNames.equalsIgnoreCase("true") &&
!lowerCaseTableNames.equalsIgnoreCase("false")) {
+ throw new DdlException("lower_case_table_names must be true or
false");
+ }
+ if (!onlySpecifiedDatabase.equalsIgnoreCase("true")) {
+ Map<String, Boolean> includeDatabaseList = getIncludeDatabaseMap();
+ Map<String, Boolean> excludeDatabaseList = getExcludeDatabaseMap();
+ if ((includeDatabaseList != null && !includeDatabaseList.isEmpty())
+ || (excludeDatabaseList != null &&
!excludeDatabaseList.isEmpty())) {
+ throw new DdlException("include_database_list and
exclude_database_list can not be set when "
+ + "only_specified_database is false");
+ }
+ }
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/jdbc/JdbcExternalCatalogTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/jdbc/JdbcExternalCatalogTest.java
new file mode 100644
index 0000000000..0f2977a988
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/jdbc/JdbcExternalCatalogTest.java
@@ -0,0 +1,63 @@
+// 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.doris.datasource.jdbc;
+
+import org.apache.doris.catalog.JdbcResource;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.FeConstants;
+
+import org.junit.Assert;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class JdbcExternalCatalogTest {
+ private JdbcExternalCatalog jdbcExternalCatalog;
+
+ @BeforeEach
+ public void setUp() throws DdlException {
+ FeConstants.runningUnitTest = true;
+ Map<String, String> properties = new HashMap<>();
+ properties.put(JdbcResource.DRIVER_URL, "ojdbc8.jar");
+ properties.put(JdbcResource.JDBC_URL,
"jdbc:oracle:thin:@127.0.0.1:1521:XE");
+ properties.put(JdbcResource.DRIVER_CLASS,
"oracle.jdbc.driver.OracleDriver");
+ jdbcExternalCatalog = new JdbcExternalCatalog(1L, "testCatalog",
"testResource", properties, "testComment");
+ }
+
+ @Test
+ public void setDefaultPropsWhenCreatingTest() {
+
jdbcExternalCatalog.getCatalogProperty().addProperty(JdbcResource.ONLY_SPECIFIED_DATABASE,
"1");
+ Exception exception1 = Assert.assertThrows(DdlException.class, () ->
jdbcExternalCatalog.setDefaultPropsWhenCreating(false));
+ Assert.assertEquals("errCode = 2, detailMessage =
only_specified_database must be true or false", exception1.getMessage());
+
+
jdbcExternalCatalog.getCatalogProperty().addProperty(JdbcResource.ONLY_SPECIFIED_DATABASE,
"true");
+
jdbcExternalCatalog.getCatalogProperty().addProperty(JdbcResource.LOWER_CASE_TABLE_NAMES,
"1");
+ Exception exception2 = Assert.assertThrows(DdlException.class, () ->
jdbcExternalCatalog.setDefaultPropsWhenCreating(false));
+ Assert.assertEquals("errCode = 2, detailMessage =
lower_case_table_names must be true or false", exception2.getMessage());
+
+
jdbcExternalCatalog.getCatalogProperty().addProperty(JdbcResource.ONLY_SPECIFIED_DATABASE,
"false");
+
jdbcExternalCatalog.getCatalogProperty().addProperty(JdbcResource.LOWER_CASE_TABLE_NAMES,
"false");
+
jdbcExternalCatalog.getCatalogProperty().addProperty(JdbcResource.INCLUDE_DATABASE_LIST,
"db1,db2");
+ DdlException exceptione3 = Assert.assertThrows(DdlException.class, ()
-> jdbcExternalCatalog.setDefaultPropsWhenCreating(false));
+ Assert.assertEquals("errCode = 2, detailMessage =
include_database_list and exclude_database_list can not be set when
only_specified_database is false", exceptione3.getMessage());
+
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]