You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "zhenyue-xu (via GitHub)" <gi...@apache.org> on 2025/08/06 04:36:36 UTC

[PR] [IMPROVE][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

zhenyue-xu opened a new pull request, #9667:
URL: https://github.com/apache/seatunnel/pull/9667

   
   <!--
   
   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/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
   
   This pull request enhances the Doris connector with three key improvements:
   
   1. **Custom Driver Support**: Added the ability to specify a custom JDBC driver class through the `driver` configuration option, providing users with flexibility to choose their preferred MySQL driver version.
   
   2. **Automatic Driver Detection**: Implemented intelligent driver enumeration and fallback mechanism that automatically tries available JDBC drivers when the specified driver fails, improving connection reliability and user experience.
   
   3. **LDAP Authentication Support**: Added comprehensive LDAP authentication support for enterprise environments through the `enableLdap` configuration option. This is particularly important for large enterprises that require centralized authentication management and enhanced security compliance.
   
   The LDAP support includes:
   - Custom authentication plugin for MySQL 5.x drivers (`MySQL5LdapPlugin`)
   - Automatic configuration of required LDAP authentication properties
   - Support for both MySQL 5.x and 8.x drivers (with appropriate warnings for MySQL 8.x limitations)
   
   These enhancements address the growing need for enterprise-grade authentication in production environments where LDAP integration is mandatory for security and compliance requirements.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, this PR introduces the following user-facing changes:
   
   **New Configuration Options:**
   - `driver`: Optional string parameter to specify the JDBC driver class name
   - `enableLdap`: Optional boolean parameter (default: false) to enable LDAP authentication
   
   **Enhanced Connection Behavior:**
   - The connector now automatically attempts to use available JDBC drivers if the specified driver fails
   - When LDAP is enabled, the connector automatically configures the necessary authentication plugins for MySQL drivers
   
   **Documentation Updates:**
   - Added documentation for the new configuration options in both English and Chinese versions
   - Included notes about MySQL driver compatibility with LDAP authentication
   
   **Backward Compatibility:**
   - All existing configurations continue to work without changes
   
   ### How was this patch tested?
   
   This patch was tested through multiple approaches:
   
   1. **Unit Tests**: Added comprehensive test cases in `DorisCatalogConnectionTest.java` covering:
      - Basic driver connection functionality
      - Driver fallback mechanism when specified driver fails
      - LDAP authentication connection scenarios
   
   2. **Integration Testing**: Tested against real Doris clusters with:
      - Standard username/password authentication
      - LDAP-enabled environments using both MySQL 5.x and 8.x drivers
      - Various driver configurations and fallback scenarios
   
   ### Check list
   
   * [x] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [x] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
   
   Note: This is an enhancement to an existing connector, so steps 1-5 in the connector checklist are not applicable as no new connector is being added.


-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2258713114


##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalog.java:
##########
@@ -134,14 +157,164 @@ public void open() throws CatalogException {
                         queryPort,
                         defaultDatabase);
         try {
-            conn = DriverManager.getConnection(jdbcUrl, username, password);
+            // Prepare connection properties
+            Properties connectionInfo = new Properties();
+            if (username != null) {
+                connectionInfo.put("user", username);
+            }
+            if (password != null) {
+                connectionInfo.put("password", password);
+            }
+
+            // Attempt to connect using available drivers
+            conn = attemptConnectionWithDrivers(jdbcUrl, connectionInfo);
+
+            if (conn == null) {
+                LOG.warn(
+                        "Failed to connect using driver enumeration, falling back to DriverManager.getConnection");
+                conn = DriverManager.getConnection(jdbcUrl, username, password);
+            }
+
+            // Validate connection and initialize catalog
             conn.getCatalog();
             dorisVersion = getDorisVersion();
             typeConverter = DorisTypeConverterFactory.getTypeConverter(dorisVersion);
+
         } catch (SQLException e) {
-            throw new CatalogException(String.format("Failed to connect url %s", jdbcUrl), e);
+            throw new CatalogException(String.format("Failed to connect to URL: %s", jdbcUrl), e);
+        }
+
+        LOG.info("Catalog [{}] successfully established connection to [{}]", catalogName, jdbcUrl);
+    }
+
+    /**
+     * Attempt to establish connection by iterating through available JDBC drivers. This method
+     * prioritizes the specified driver class if provided, otherwise tries all available drivers.
+     *
+     * @param jdbcUrl The JDBC URL to connect to
+     * @param connectionInfo Connection properties including user credentials and LDAP settings
+     * @return A valid database connection, or null if all attempts failed
+     */
+    private Connection attemptConnectionWithDrivers(String jdbcUrl, Properties connectionInfo) {
+        Enumeration<Driver> drivers = DriverManager.getDrivers();
+
+        // If a specific driver class is specified, try it first
+        if (StringUtils.isNotBlank(driverClass)) {
+            LOG.debug("Attempting connection with specified driver class: {}", driverClass);
+
+            while (drivers.hasMoreElements()) {
+                Driver driver = drivers.nextElement();
+                if (StringUtils.equals(driver.getClass().getName(), driverClass)) {
+                    Connection connection = tryConnectWithDriver(driver, jdbcUrl, connectionInfo);
+                    if (connection != null) {
+                        LOG.info("Successfully connected using specified driver: {}", driverClass);
+                        return connection;
+                    }
+                }
+            }
+
+            LOG.warn(
+                    "Failed to connect using specified driver class: {}, trying other available drivers",
+                    driverClass);
+
+            // Reset enumeration for fallback attempt
+            drivers = DriverManager.getDrivers();
+        }
+
+        // Try all available drivers
+        LOG.debug("Attempting connection with all available drivers");

Review Comment:
   > No driver specified
   
   We can use default driver value when enable ldap if no driver specified.
   
   > Specified driver fails to connect
   
   We should thrown exception when specified driver fails to connect



-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2258788385


##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalog.java:
##########
@@ -134,14 +157,198 @@ public void open() throws CatalogException {
                         queryPort,
                         defaultDatabase);
         try {
-            conn = DriverManager.getConnection(jdbcUrl, username, password);
+            // Prepare connection properties
+            Properties connectionInfo = new Properties();
+            if (username != null) {
+                connectionInfo.put("user", username);
+            }
+            if (password != null) {
+                connectionInfo.put("password", password);
+            }
+
+            // Attempt to connect using appropriate driver strategy
+            conn = attemptConnectionWithDrivers(jdbcUrl, connectionInfo);
+
+            // Validate connection and initialize catalog
             conn.getCatalog();
             dorisVersion = getDorisVersion();
             typeConverter = DorisTypeConverterFactory.getTypeConverter(dorisVersion);
+
         } catch (SQLException e) {
-            throw new CatalogException(String.format("Failed to connect url %s", jdbcUrl), e);
+            throw new CatalogException(String.format("Failed to connect to URL: %s", jdbcUrl), e);
+        }
+
+        LOG.info("Catalog [{}] successfully established connection to [{}]", catalogName, jdbcUrl);
+    }
+
+    /**
+     * Attempt to establish connection using the appropriate driver strategy. If LDAP is enabled and
+     * no driver is specified, use MySQL 5.x driver as default. If a specific driver is specified
+     * and fails, throw an exception.
+     *
+     * @param jdbcUrl The JDBC URL to connect to
+     * @param connectionInfo Connection properties including user credentials
+     * @return A valid database connection
+     * @throws SQLException if connection fails
+     */
+    private Connection attemptConnectionWithDrivers(String jdbcUrl, Properties connectionInfo)
+            throws SQLException {
+
+        // Determine the driver to use
+        String targetDriver = determineTargetDriver();
+
+        if (StringUtils.isNotBlank(targetDriver)) {
+            // Use specific driver (either specified or default for LDAP)
+            return connectWithSpecificDriver(targetDriver, jdbcUrl, connectionInfo);
+        } else {
+            // No driver specified and LDAP disabled, try all available drivers
+            return connectWithAnyAvailableDriver(jdbcUrl, connectionInfo);
+        }
+    }
+
+    /** Determine which driver to use based on configuration */
+    private String determineTargetDriver() {
+        if (StringUtils.isNotBlank(driverClass)) {
+            // Use explicitly specified driver
+            return driverClass;
+        } else if (enableLdap) {
+            // Use MySQL 5.x driver as default when LDAP is enabled
+            return "com.mysql.jdbc.Driver";
+        }
+        return null;
+    }
+
+    /** Connect using a specific driver class. Throws exception if fails. */
+    private Connection connectWithSpecificDriver(
+            String targetDriverClass, String jdbcUrl, Properties connectionInfo)
+            throws SQLException {
+
+        LOG.debug("Attempting connection with specific driver: {}", targetDriverClass);
+
+        Enumeration<Driver> drivers = DriverManager.getDrivers();
+        while (drivers.hasMoreElements()) {
+            Driver driver = drivers.nextElement();
+            if (StringUtils.equals(driver.getClass().getName(), targetDriverClass)) {
+                Connection connection = tryConnectWithDriver(driver, jdbcUrl, connectionInfo);
+                if (connection != null) {
+                    LOG.info("Successfully connected using driver: {}", targetDriverClass);
+                    return connection;
+                }
+            }
+        }
+
+        // If we reach here, the specified driver failed or wasn't found
+        throw new SQLException(
+                String.format(
+                        "Failed to connect using specified driver: %s. "
+                                + "Please check if the driver is available in classpath and configuration is correct.",
+                        targetDriverClass));
+    }
+
+    /**
+     * Try connecting with any available driver (fallback when no driver specified and LDAP
+     * disabled)
+     */
+    private Connection connectWithAnyAvailableDriver(String jdbcUrl, Properties connectionInfo)

Review Comment:
   why not direct use DriverManager.getConnection when no driver meaning ldap not enabled?



-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#issuecomment-3621423743

   This pull request has been automatically marked as stale because it has not had recent activity for 120 days. It will be closed in 7 days if no further activity occurs.


-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "zhenyue-xu (via GitHub)" <gi...@apache.org>.
zhenyue-xu commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2257324005


##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalog.java:
##########
@@ -134,14 +157,164 @@ public void open() throws CatalogException {
                         queryPort,
                         defaultDatabase);
         try {
-            conn = DriverManager.getConnection(jdbcUrl, username, password);
+            // Prepare connection properties
+            Properties connectionInfo = new Properties();
+            if (username != null) {
+                connectionInfo.put("user", username);
+            }
+            if (password != null) {
+                connectionInfo.put("password", password);
+            }
+
+            // Attempt to connect using available drivers
+            conn = attemptConnectionWithDrivers(jdbcUrl, connectionInfo);
+
+            if (conn == null) {
+                LOG.warn(
+                        "Failed to connect using driver enumeration, falling back to DriverManager.getConnection");
+                conn = DriverManager.getConnection(jdbcUrl, username, password);
+            }
+
+            // Validate connection and initialize catalog
             conn.getCatalog();
             dorisVersion = getDorisVersion();
             typeConverter = DorisTypeConverterFactory.getTypeConverter(dorisVersion);
+
         } catch (SQLException e) {
-            throw new CatalogException(String.format("Failed to connect url %s", jdbcUrl), e);
+            throw new CatalogException(String.format("Failed to connect to URL: %s", jdbcUrl), e);
+        }
+
+        LOG.info("Catalog [{}] successfully established connection to [{}]", catalogName, jdbcUrl);
+    }
+
+    /**
+     * Attempt to establish connection by iterating through available JDBC drivers. This method
+     * prioritizes the specified driver class if provided, otherwise tries all available drivers.
+     *
+     * @param jdbcUrl The JDBC URL to connect to
+     * @param connectionInfo Connection properties including user credentials and LDAP settings
+     * @return A valid database connection, or null if all attempts failed
+     */
+    private Connection attemptConnectionWithDrivers(String jdbcUrl, Properties connectionInfo) {
+        Enumeration<Driver> drivers = DriverManager.getDrivers();
+
+        // If a specific driver class is specified, try it first
+        if (StringUtils.isNotBlank(driverClass)) {
+            LOG.debug("Attempting connection with specified driver class: {}", driverClass);
+
+            while (drivers.hasMoreElements()) {
+                Driver driver = drivers.nextElement();
+                if (StringUtils.equals(driver.getClass().getName(), driverClass)) {
+                    Connection connection = tryConnectWithDriver(driver, jdbcUrl, connectionInfo);
+                    if (connection != null) {
+                        LOG.info("Successfully connected using specified driver: {}", driverClass);
+                        return connection;
+                    }
+                }
+            }
+
+            LOG.warn(
+                    "Failed to connect using specified driver class: {}, trying other available drivers",
+                    driverClass);
+
+            // Reset enumeration for fallback attempt
+            drivers = DriverManager.getDrivers();
+        }
+
+        // Try all available drivers
+        LOG.debug("Attempting connection with all available drivers");

Review Comment:
   You're right, it does look weird at first glance. But this only happens as fallback when:
   1. No driver specified, or
   2. Specified driver fails to connect
   
   I can't just use DriverManager.getConnection() directly because I need to configure LDAP differently for MySQL 5.x vs 8.x drivers. DriverManager actually does the same driver iteration under the hood, I just need more control over the connection properties.
   
   Got any better ideas for 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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "zhenyue-xu (via GitHub)" <gi...@apache.org>.
zhenyue-xu commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2258761858


##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalog.java:
##########
@@ -134,14 +157,164 @@ public void open() throws CatalogException {
                         queryPort,
                         defaultDatabase);
         try {
-            conn = DriverManager.getConnection(jdbcUrl, username, password);
+            // Prepare connection properties
+            Properties connectionInfo = new Properties();
+            if (username != null) {
+                connectionInfo.put("user", username);
+            }
+            if (password != null) {
+                connectionInfo.put("password", password);
+            }
+
+            // Attempt to connect using available drivers
+            conn = attemptConnectionWithDrivers(jdbcUrl, connectionInfo);
+
+            if (conn == null) {
+                LOG.warn(
+                        "Failed to connect using driver enumeration, falling back to DriverManager.getConnection");
+                conn = DriverManager.getConnection(jdbcUrl, username, password);
+            }
+
+            // Validate connection and initialize catalog
             conn.getCatalog();
             dorisVersion = getDorisVersion();
             typeConverter = DorisTypeConverterFactory.getTypeConverter(dorisVersion);
+
         } catch (SQLException e) {
-            throw new CatalogException(String.format("Failed to connect url %s", jdbcUrl), e);
+            throw new CatalogException(String.format("Failed to connect to URL: %s", jdbcUrl), e);
+        }
+
+        LOG.info("Catalog [{}] successfully established connection to [{}]", catalogName, jdbcUrl);
+    }
+
+    /**
+     * Attempt to establish connection by iterating through available JDBC drivers. This method
+     * prioritizes the specified driver class if provided, otherwise tries all available drivers.
+     *
+     * @param jdbcUrl The JDBC URL to connect to
+     * @param connectionInfo Connection properties including user credentials and LDAP settings
+     * @return A valid database connection, or null if all attempts failed
+     */
+    private Connection attemptConnectionWithDrivers(String jdbcUrl, Properties connectionInfo) {
+        Enumeration<Driver> drivers = DriverManager.getDrivers();
+
+        // If a specific driver class is specified, try it first
+        if (StringUtils.isNotBlank(driverClass)) {
+            LOG.debug("Attempting connection with specified driver class: {}", driverClass);
+
+            while (drivers.hasMoreElements()) {
+                Driver driver = drivers.nextElement();
+                if (StringUtils.equals(driver.getClass().getName(), driverClass)) {
+                    Connection connection = tryConnectWithDriver(driver, jdbcUrl, connectionInfo);
+                    if (connection != null) {
+                        LOG.info("Successfully connected using specified driver: {}", driverClass);
+                        return connection;
+                    }
+                }
+            }
+
+            LOG.warn(
+                    "Failed to connect using specified driver class: {}, trying other available drivers",
+                    driverClass);
+
+            // Reset enumeration for fallback attempt
+            drivers = DriverManager.getDrivers();
+        }
+
+        // Try all available drivers
+        LOG.debug("Attempting connection with all available drivers");

Review Comment:
   > > No driver specified
   > 
   > We can use default driver value when enable ldap if no driver specified.
   > 
   > > Specified driver fails to connect
   > 
   > We should thrown exception when specified driver fails to connect
   
   Thanks for the guidance!  I've already updated the code accordingly.



-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2257123704


##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalog.java:
##########
@@ -134,14 +157,164 @@ public void open() throws CatalogException {
                         queryPort,
                         defaultDatabase);
         try {
-            conn = DriverManager.getConnection(jdbcUrl, username, password);
+            // Prepare connection properties
+            Properties connectionInfo = new Properties();
+            if (username != null) {
+                connectionInfo.put("user", username);
+            }
+            if (password != null) {
+                connectionInfo.put("password", password);
+            }
+
+            // Attempt to connect using available drivers
+            conn = attemptConnectionWithDrivers(jdbcUrl, connectionInfo);
+
+            if (conn == null) {
+                LOG.warn(
+                        "Failed to connect using driver enumeration, falling back to DriverManager.getConnection");
+                conn = DriverManager.getConnection(jdbcUrl, username, password);
+            }
+
+            // Validate connection and initialize catalog
             conn.getCatalog();
             dorisVersion = getDorisVersion();
             typeConverter = DorisTypeConverterFactory.getTypeConverter(dorisVersion);
+
         } catch (SQLException e) {
-            throw new CatalogException(String.format("Failed to connect url %s", jdbcUrl), e);
+            throw new CatalogException(String.format("Failed to connect to URL: %s", jdbcUrl), e);
+        }
+
+        LOG.info("Catalog [{}] successfully established connection to [{}]", catalogName, jdbcUrl);
+    }
+
+    /**
+     * Attempt to establish connection by iterating through available JDBC drivers. This method
+     * prioritizes the specified driver class if provided, otherwise tries all available drivers.
+     *
+     * @param jdbcUrl The JDBC URL to connect to
+     * @param connectionInfo Connection properties including user credentials and LDAP settings
+     * @return A valid database connection, or null if all attempts failed
+     */
+    private Connection attemptConnectionWithDrivers(String jdbcUrl, Properties connectionInfo) {
+        Enumeration<Driver> drivers = DriverManager.getDrivers();
+
+        // If a specific driver class is specified, try it first
+        if (StringUtils.isNotBlank(driverClass)) {
+            LOG.debug("Attempting connection with specified driver class: {}", driverClass);
+
+            while (drivers.hasMoreElements()) {
+                Driver driver = drivers.nextElement();
+                if (StringUtils.equals(driver.getClass().getName(), driverClass)) {
+                    Connection connection = tryConnectWithDriver(driver, jdbcUrl, connectionInfo);
+                    if (connection != null) {
+                        LOG.info("Successfully connected using specified driver: {}", driverClass);
+                        return connection;
+                    }
+                }
+            }
+
+            LOG.warn(
+                    "Failed to connect using specified driver class: {}, trying other available drivers",
+                    driverClass);
+
+            // Reset enumeration for fallback attempt
+            drivers = DriverManager.getDrivers();
+        }
+
+        // Try all available drivers
+        LOG.debug("Attempting connection with all available drivers");

Review Comment:
   why we should try all drivers? It's weird.



-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2258859957


##########
seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalogConnectionTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.doris.catalog;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+
+public class DorisCatalogConnectionTest {

Review Comment:
   The DorisCatalog in test case not call `open()`. So all code you added not be tested.



-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #9667: [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support
URL: https://github.com/apache/seatunnel/pull/9667


-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#issuecomment-3649991112

   This pull request has been closed because it has not had recent activity. You could reopen it if you try to continue your work, and anyone who are interested in it are encouraged to continue work on this pull request.


-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "zhenyue-xu (via GitHub)" <gi...@apache.org>.
zhenyue-xu commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2262220524


##########
seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalogConnectionTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.doris.catalog;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+
+public class DorisCatalogConnectionTest {

Review Comment:
   > The DorisCatalog in test case not call `open()`. So all code you added not be tested.
   
   You're right, unit tests have no value here. I'll add e2e tests next week (mainly need to research how to set up Doris with LDAP using Docker).



-- 
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


Re: [PR] [Feature][Connector-Doris] Enhance JDBC connection with custom driver, auto-detection and LDAP support [seatunnel]

Posted by "zhenyue-xu (via GitHub)" <gi...@apache.org>.
zhenyue-xu commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2258839542


##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalog.java:
##########
@@ -134,14 +157,198 @@ public void open() throws CatalogException {
                         queryPort,
                         defaultDatabase);
         try {
-            conn = DriverManager.getConnection(jdbcUrl, username, password);
+            // Prepare connection properties
+            Properties connectionInfo = new Properties();
+            if (username != null) {
+                connectionInfo.put("user", username);
+            }
+            if (password != null) {
+                connectionInfo.put("password", password);
+            }
+
+            // Attempt to connect using appropriate driver strategy
+            conn = attemptConnectionWithDrivers(jdbcUrl, connectionInfo);
+
+            // Validate connection and initialize catalog
             conn.getCatalog();
             dorisVersion = getDorisVersion();
             typeConverter = DorisTypeConverterFactory.getTypeConverter(dorisVersion);
+
         } catch (SQLException e) {
-            throw new CatalogException(String.format("Failed to connect url %s", jdbcUrl), e);
+            throw new CatalogException(String.format("Failed to connect to URL: %s", jdbcUrl), e);
+        }
+
+        LOG.info("Catalog [{}] successfully established connection to [{}]", catalogName, jdbcUrl);
+    }
+
+    /**
+     * Attempt to establish connection using the appropriate driver strategy. If LDAP is enabled and
+     * no driver is specified, use MySQL 5.x driver as default. If a specific driver is specified
+     * and fails, throw an exception.
+     *
+     * @param jdbcUrl The JDBC URL to connect to
+     * @param connectionInfo Connection properties including user credentials
+     * @return A valid database connection
+     * @throws SQLException if connection fails
+     */
+    private Connection attemptConnectionWithDrivers(String jdbcUrl, Properties connectionInfo)
+            throws SQLException {
+
+        // Determine the driver to use
+        String targetDriver = determineTargetDriver();
+
+        if (StringUtils.isNotBlank(targetDriver)) {
+            // Use specific driver (either specified or default for LDAP)
+            return connectWithSpecificDriver(targetDriver, jdbcUrl, connectionInfo);
+        } else {
+            // No driver specified and LDAP disabled, try all available drivers
+            return connectWithAnyAvailableDriver(jdbcUrl, connectionInfo);
+        }
+    }
+
+    /** Determine which driver to use based on configuration */
+    private String determineTargetDriver() {
+        if (StringUtils.isNotBlank(driverClass)) {
+            // Use explicitly specified driver
+            return driverClass;
+        } else if (enableLdap) {
+            // Use MySQL 5.x driver as default when LDAP is enabled
+            return "com.mysql.jdbc.Driver";
+        }
+        return null;
+    }
+
+    /** Connect using a specific driver class. Throws exception if fails. */
+    private Connection connectWithSpecificDriver(
+            String targetDriverClass, String jdbcUrl, Properties connectionInfo)
+            throws SQLException {
+
+        LOG.debug("Attempting connection with specific driver: {}", targetDriverClass);
+
+        Enumeration<Driver> drivers = DriverManager.getDrivers();
+        while (drivers.hasMoreElements()) {
+            Driver driver = drivers.nextElement();
+            if (StringUtils.equals(driver.getClass().getName(), targetDriverClass)) {
+                Connection connection = tryConnectWithDriver(driver, jdbcUrl, connectionInfo);
+                if (connection != null) {
+                    LOG.info("Successfully connected using driver: {}", targetDriverClass);
+                    return connection;
+                }
+            }
+        }
+
+        // If we reach here, the specified driver failed or wasn't found
+        throw new SQLException(
+                String.format(
+                        "Failed to connect using specified driver: %s. "
+                                + "Please check if the driver is available in classpath and configuration is correct.",
+                        targetDriverClass));
+    }
+
+    /**
+     * Try connecting with any available driver (fallback when no driver specified and LDAP
+     * disabled)
+     */
+    private Connection connectWithAnyAvailableDriver(String jdbcUrl, Properties connectionInfo)

Review Comment:
   you are right, Fixed 



-- 
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