You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "yzeng1618 (via GitHub)" <gi...@apache.org> on 2026/01/08 01:11:55 UTC

[PR] [Fix] [connector-hbase] Fix namespace handling for HBase source [seatunnel]

yzeng1618 opened a new pull request, #10295:
URL: https://github.com/apache/seatunnel/pull/10295

   <!--
   
   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
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   When table is configured as namespace:table, source split enumeration and scan previously used only the table name, effectively querying the default namespace and returning empty results. This PR makes namespace handling consistent across source components and fails fast when table/regions are missing.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Reading from non-default namespace tables now returns data correctly instead of 0 rows. The docs also clarify that table accepts namespace:table and defaults to default.
   
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
   If no, write 'No'.
   If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
   -->
   
   
   ### How was this patch tested?
   Added/updated unit tests for namespace defaulting and source split enumeration; added an e2e case for namespace source config
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
   -->
   
   
   ### Check list
   
   * [ ] 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)
   * [* ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If necessary, please update `incompatible-changes.md` to describe the incompatibility caused by this PR.
   * [ ] 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)


-- 
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] [Fix] [connector-hbase] Fix namespace handling for HBase source [seatunnel]

Posted by "yzeng1618 (via GitHub)" <gi...@apache.org>.
yzeng1618 commented on PR #10295:
URL: https://github.com/apache/seatunnel/pull/10295#issuecomment-3798014270

   > ### Issue 1: The old `getRegionLocator(String)` method still exists and has inconsistent behavior
   > **Location**: `HbaseClient.java:393-395`
   > 
   > ```java
   > public RegionLocator getRegionLocator(String tableName) throws IOException {
   >     return this.connection.getRegionLocator(TableName.valueOf(tableName));
   > }
   > ```
   > 
   > **Related Context**:
   > 
   > * Caller: Has been changed by `HbaseSourceSplitEnumerator` to use the two-parameter version
   > * Potential callers: Other code that may call this method (if any)
   > 
   > **Problem Description**: The old `getRegionLocator(String tableName)` method is still retained, and it will parse the passed `tableName` as `default:tableName` (HBase's default behavior). This is inconsistent with the new `getRegionLocator(String namespace, String tableName)` method.
   > 
   > Although in the current PR, `HbaseSourceSplitEnumerator` has been changed to use the new two-parameter method, the existence of the old method may lead to:
   > 
   > 1. Future maintainers misusing the old method, causing the same bug
   > 2. If other code paths use this method, they will have the same problem
   > 
   > **Potential Risks**:
   > 
   > * Risk 1: Future code may incorrectly use the old method, reintroducing the namespace bug
   > * Risk 2: API confusion, developers won't know which method to use
   > 
   > **Scope of Impact**:
   > 
   > * Direct impact: Public API of `HbaseClient`
   > * Indirect impact: Any code that calls `getRegionLocator(String)` (if any)
   > * Impact area: HBase Connector
   > 
   > **Severity**: MINOR
   > 
   > **Improvement Suggestion**:
   > 
   > ```java
   > /**
   >  * @deprecated Use {@link #getRegionLocator(String, String)} instead.
   >  * This method does not properly handle custom namespaces.
   >  */
   > @Deprecated
   > public RegionLocator getRegionLocator(String tableName) throws IOException {
   >     return this.connection.getRegionLocator(TableName.valueOf(tableName));
   > }
   > ```
   > 
   > **Rationale**:
   > 
   > 1. Marking as `@Deprecated` can warn developers not to use it
   > 2. Keeping the method is for backward compatibility (if external code uses it)
   > 3. JavaDoc clearly indicates the alternative method
   > 4. If it's certain there are no external callers, consider removing it in the next major version
   > 
   > ### Issue 2: Wrapping `IOException` as `RuntimeException` loses error context
   > **Location**: `HbaseSourceSplitEnumerator.java:311-313`
   > 
   > ```java
   > } catch (IOException e) {
   >     throw new RuntimeException(e);
   > }
   > ```
   > 
   > **Related Context**:
   > 
   > * Parent interface: `SourceSplitEnumerator` - does not specify exception types
   > * Other exception handling in the same class: uses `HbaseConnectorException`
   > * Callers: `HbaseSource.createEnumerator()` and `restoreEnumerator()`
   > 
   > **Problem Description**: At the outermost layer of the `getTableSplits()` method, after catching `IOException`, it is directly wrapped as `RuntimeException`. This is inconsistent with the preceding code style (which used `HbaseConnectorException`), and loses HBase-specific error context.
   > 
   > Although the code before modification was handled this way, since `HbaseConnectorException` is used in other places, consistency should be maintained here as well.
   > 
   > **Potential Risks**:
   > 
   > * Risk 1: Inconsistent error handling, increasing maintenance costs
   > * Risk 2: Upper-layer callers cannot distinguish between HBase errors and other runtime errors
   > * Risk 3: Error logs may not be clear enough, making troubleshooting difficult
   > 
   > **Scope of Impact**:
   > 
   > * Direct impact: `HbaseSourceSplitEnumerator.getTableSplits()`
   > * Indirect impact: Creation and recovery process of `HbaseSource`
   > * Impact area: HBase Source Connector
   > 
   > **Severity**: MINOR
   > 
   > **Improvement Suggestion**:
   > 
   > ```java
   > } catch (IOException e) {
   >     String errorMsg = String.format(
   >         "Failed to enumerate splits for HBase table [%s]",
   >         tableName.getNameAsString());
   >     log.error(errorMsg, e);
   >     throw new HbaseConnectorException(
   >         HbaseConnectorErrorCode.TABLE_QUERY_EXCEPTION, 
   >         errorMsg, 
   >         e);
   > }
   > ```
   > 
   > **Rationale**:
   > 
   > 1. Consistent with preceding exception handling
   > 2. Provides clearer error messages
   > 3. Preserves the original exception as cause
   > 4. Uses the correct error code
   > 5. Facilitates specific error handling by upper-layer code
   > 
   > ### Issue 3: Missing test coverage for extreme inputs
   > **Location**: `HbaseParametersTest.java` and `HbaseSourceSplitEnumeratorTest.java`
   > 
   > **Related Context**:
   > 
   > * Test class: `HbaseParametersTest` - newly added unit tests
   > * Test class: `HbaseSourceSplitEnumeratorTest` - updated unit tests
   > * Configuration parsing logic: `HbaseParameters.buildWithSourceConfig()` - lines 88-133
   > 
   > **Problem Description**: Current tests cover normal scenarios and basic boundary conditions, but are missing tests for some extreme inputs:
   > 
   > 1. **When namespace is `null`**: Although the `getNamespace()` method handles `null`, there is no test verification
   > 2. **table parameter contains multiple colons**: For example `ns:table:extra`, current parsing logic will take the part after the last colon as table
   > 3. **namespace or table contains spaces**: For example `ns : table`, may cause parsing errors
   > 4. **Only colon without table**: For example `test:`, current logic will take empty string as table
   > 5. **Only table without colon but with spaces before and after**: For example `table`, current logic will not handle spaces
   > 
   > **Potential Risks**:
   > 
   > * Risk 1: Extreme user input may cause undefined behavior
   > * Risk 2: Bugs not covered by tests may appear in production environment
   > * Risk 3: Future code modifications may break handling of these extreme cases
   > 
   > **Scope of Impact**:
   > 
   > * Direct impact: Configuration parsing logic
   > * Indirect impact: Stability of the entire HBase Connector
   > * Impact area: HBase Connector
   > 
   > **Severity**: MINOR
   > 
   > **Improvement Suggestion**:
   > 
   > ```java
   > // Added in HbaseParametersTest.java
   > @Test
   > public void testBuildWithSourceConfigWithNullNamespace() {
   >     HbaseParameters parameters = HbaseParameters.builder()
   >         .table("tbl")
   >         .zookeeperQuorum("127.0.0.1:2181")
   >         .build();
   >     Assertions.assertEquals(HbaseParameters.DEFAULT_NAMESPACE, parameters.getNamespace());
   > }
   > 
   > @Test
   > public void testBuildWithSourceConfigWithEmptyStringNamespace() {
   >     Map<String, Object> configMap = new HashMap<>();
   >     configMap.put(HbaseBaseOptions.ZOOKEEPER_QUORUM.key(), "127.0.0.1:2181");
   >     configMap.put(HbaseBaseOptions.TABLE.key(), ":tbl");  // Only colon
   >     ReadonlyConfig readonlyConfig = ReadonlyConfig.fromMap(configMap);
   >     
   >     HbaseParameters parameters = HbaseParameters.buildWithSourceConfig(readonlyConfig);
   >     Assertions.assertEquals("", parameters.getNamespace());  // Empty string
   >     Assertions.assertEquals("tbl", parameters.getTable());
   > }
   > 
   > @Test
   > public void testBuildWithSourceConfigWithMultipleColons() {
   >     Map<String, Object> configMap = new HashMap<>();
   >     configMap.put(HbaseBaseOptions.ZOOKEEPER_QUORUM.key(), "127.0.0.1:2181");
   >     configMap.put(HbaseBaseOptions.TABLE.key(), "ns:tbl:extra");  // Multiple colons
   >     ReadonlyConfig readonlyConfig = ReadonlyConfig.fromMap(configMap);
   >     
   >     HbaseParameters parameters = HbaseParameters.buildWithSourceConfig(readonlyConfig);
   >     // Current logic: take the part before the first colon as namespace, the part after as table (including the colon)
   >     Assertions.assertEquals("ns", parameters.getNamespace());
   >     Assertions.assertEquals("tbl:extra", parameters.getTable());
   > }
   > 
   > @Test
   > public void testBuildWithSourceConfigWithSpaces() {
   >     Map<String, Object> configMap = new HashMap<>();
   >     configMap.put(HbaseBaseOptions.ZOOKEEPER_QUORUM.key(), "127.0.0.1:2181");
   >     configMap.put(HbaseBaseOptions.TABLE.key(), " ns : tbl ");  // With spaces
   >     ReadonlyConfig readonlyConfig = ReadonlyConfig.fromMap(configMap);
   >     
   >     HbaseParameters parameters = HbaseParameters.buildWithSourceConfig(readonlyConfig);
   >     // Current logic: does not handle spaces
   >     Assertions.assertEquals(" ns ", parameters.getNamespace());
   >     Assertions.assertEquals(" tbl ", parameters.getTable());
   > }
   > ```
   > 
   > **Rationale**:
   > 
   > 1. Enhances test coverage
   > 2. Clarifies current code behavior for extreme inputs
   > 3. Provides baseline for future input validation improvements
   > 4. These tests will not block the current PR's merge, but should be supplemented in subsequent PRs
   > 
   > ### Issue 4: Creating HbaseClient immediately in constructor may lead to early failure
   > **Location**: `HbaseSourceSplitEnumerator.java:63-80`
   > 
   > **Related Context**:
   > 
   > * Call chain: `HbaseSource.createEnumerator()` → `new HbaseSourceSplitEnumerator(...)`
   > * Resource creation: `HbaseClient.createInstance(hbaseParameters)` will establish HBase connection
   > * Resource management: `Enumerator`'s `close()` method will close the connection
   > 
   > **Problem Description**: The modified code immediately creates `HbaseClient` instances in all constructors, including scenarios where `getTableSplits()` may not be used immediately. This means:
   > 
   > 1. Even if just creating an Enumerator object (without enumerating splits), an HBase connection will be established
   > 2. If the HBase connection fails, an exception will be thrown at the Enumerator creation stage rather than on first use
   > 3. In some cases (e.g., recovering from checkpoint but not needing to re-enumerate splits), this connection may be unnecessary
   > 
   > **Potential Risks**:
   > 
   > * Risk 1: Connection failure timing is advanced, which may affect error recovery logic
   > * Risk 2: Unnecessary connections may be created in certain initialization scenarios
   > * Risk 3: If connection creation is slow, it will block Enumerator creation
   > 
   > **Scope of Impact**:
   > 
   > * Direct impact: All constructors of `HbaseSourceSplitEnumerator`
   > * Indirect impact: Creation process of `HbaseSource`
   > * Impact area: HBase Source Connector
   > 
   > **Severity**: MINOR
   > 
   > **Improvement Suggestion**: Consider lazy initialization of `HbaseClient`:
   > 
   > ```java
   > private HbaseClient getHbaseClient() {
   >     if (hbaseClient == null) {
   >         this.hbaseClient = HbaseClient.createInstance(hbaseParameters);
   >     }
   >     return hbaseClient;
   > }
   > 
   > // Used in getTableSplits()
   > HbaseClient client = getHbaseClient();
   > try (RegionLocator regionLocator = client.getRegionLocator(...)) {
   >     ...
   > }
   > ```
   > 
   > Or, if connection validation is indeed needed at construction time, this should be clearly documented and error handling should be ensured correct.
   > 
   > **Rationale**:
   > 
   > 1. Lazy initialization can avoid unnecessary connection creation
   > 2. However, the current design (immediate initialization) is also reasonable, as it can detect configuration errors early
   > 3. This is more of a design trade-off than a clear bug
   > 4. If maintaining current design, it's recommended to explain in JavaDoc
   
   The above suggestions have been implemented.


-- 
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] [Fix] [connector-hbase] Fix namespace handling for HBase source [seatunnel]

Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN merged PR #10295:
URL: https://github.com/apache/seatunnel/pull/10295


-- 
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] [Fix] [connector-hbase] Fix namespace handling for HBase source [seatunnel]

Posted by "yzeng1618 (via GitHub)" <gi...@apache.org>.
yzeng1618 commented on code in PR #10295:
URL: https://github.com/apache/seatunnel/pull/10295#discussion_r2674519014


##########
seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/source/HbaseSourceSplitEnumerator.java:
##########
@@ -176,59 +187,88 @@ private void assignSplit(int taskId) {
     public Set<HbaseSourceSplit> getTableSplits() {
 
         try {
-            RegionLocator regionLocator = hbaseClient.getRegionLocator(hbaseParameters.getTable());
-            byte[][] startKeys = regionLocator.getStartKeys();
-            byte[][] endKeys = regionLocator.getEndKeys();
-            List<HbaseSourceSplit> splits = new ArrayList<>();
-            boolean isBinaryRowkey = hbaseParameters.isBinaryRowkey();
-            byte[] userStartRowkey =
-                    HBaseUtil.convertRowKey(hbaseParameters.getStartRowkey(), isBinaryRowkey);
-            byte[] userEndRowkey =
-                    HBaseUtil.convertRowKey(hbaseParameters.getEndRowkey(), isBinaryRowkey);
-            HBaseUtil.validateRowKeyRange(userStartRowkey, userEndRowkey);
-
-            int i = 0;
-            while (i < startKeys.length) {
-                byte[] regionStartKey = startKeys[i];
-                byte[] regionEndKey = endKeys[i];
-                if (userEndRowkey.length > 0
-                        && Bytes.compareTo(userEndRowkey, regionStartKey) <= 0
-                        && Bytes.compareTo(regionStartKey, HConstants.EMPTY_BYTE_ARRAY) != 0) {
-                    i++;
-                    continue;
-                }
+            String namespace = hbaseParameters.getNamespace();
+            if (namespace == null || namespace.isEmpty()) {

Review Comment:
    Have modified



##########
seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/client/HbaseClient.java:
##########
@@ -392,4 +396,10 @@ public ResultScanner scan(
     public RegionLocator getRegionLocator(String tableName) throws IOException {
         return this.connection.getRegionLocator(TableName.valueOf(tableName));
     }
+
+    public RegionLocator getRegionLocator(String namespace, String tableName) throws IOException {
+        String actualNamespace =
+                StringUtils.isBlank(namespace) ? HbaseParameters.DEFAULT_NAMESPACE : namespace;

Review Comment:
    Have modified



-- 
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] [Fix] [connector-hbase] Fix namespace handling for HBase source [seatunnel]

Posted by "DanielCarter-stack (via GitHub)" <gi...@apache.org>.
DanielCarter-stack commented on PR #10295:
URL: https://github.com/apache/seatunnel/pull/10295#issuecomment-3796500338

   <!-- code-pr-reviewer -->
   <!-- cpr:pr_reply_v2_parts {"group": "apache/seatunnel#10295", "part": 1, "total": 1} -->
   ### Issue 1: The old `getRegionLocator(String)` method still exists and has inconsistent behavior
   
   **Location**: `HbaseClient.java:393-395`
   
   ```java
   public RegionLocator getRegionLocator(String tableName) throws IOException {
       return this.connection.getRegionLocator(TableName.valueOf(tableName));
   }
   ```
   
   **Related Context**:
   - Caller: Has been changed by `HbaseSourceSplitEnumerator` to use the two-parameter version
   - Potential callers: Other code that may call this method (if any)
   
   **Problem Description**:
   The old `getRegionLocator(String tableName)` method is still retained, and it will parse the passed `tableName` as `default:tableName` (HBase's default behavior). This is inconsistent with the new `getRegionLocator(String namespace, String tableName)` method.
   
   Although in the current PR, `HbaseSourceSplitEnumerator` has been changed to use the new two-parameter method, the existence of the old method may lead to:
   1. Future maintainers misusing the old method, causing the same bug
   2. If other code paths use this method, they will have the same problem
   
   **Potential Risks**:
   - Risk 1: Future code may incorrectly use the old method, reintroducing the namespace bug
   - Risk 2: API confusion, developers won't know which method to use
   
   **Scope of Impact**:
   - Direct impact: Public API of `HbaseClient`
   - Indirect impact: Any code that calls `getRegionLocator(String)` (if any)
   - Impact area: HBase Connector
   
   **Severity**: MINOR
   
   **Improvement Suggestion**:
   ```java
   /**
    * @deprecated Use {@link #getRegionLocator(String, String)} instead.
    * This method does not properly handle custom namespaces.
    */
   @Deprecated
   public RegionLocator getRegionLocator(String tableName) throws IOException {
       return this.connection.getRegionLocator(TableName.valueOf(tableName));
   }
   ```
   
   **Rationale**:
   1. Marking as `@Deprecated` can warn developers not to use it
   2. Keeping the method is for backward compatibility (if external code uses it)
   3. JavaDoc clearly indicates the alternative method
   4. If it's certain there are no external callers, consider removing it in the next major version
   
   ---
   
   ### Issue 2: Wrapping `IOException` as `RuntimeException` loses error context
   
   **Location**: `HbaseSourceSplitEnumerator.java:311-313`
   
   ```java
   } catch (IOException e) {
       throw new RuntimeException(e);
   }
   ```
   
   **Related Context**:
   - Parent interface: `SourceSplitEnumerator` - does not specify exception types
   - Other exception handling in the same class: uses `HbaseConnectorException`
   - Callers: `HbaseSource.createEnumerator()` and `restoreEnumerator()`
   
   **Problem Description**:
   At the outermost layer of the `getTableSplits()` method, after catching `IOException`, it is directly wrapped as `RuntimeException`. This is inconsistent with the preceding code style (which used `HbaseConnectorException`), and loses HBase-specific error context.
   
   Although the code before modification was handled this way, since `HbaseConnectorException` is used in other places, consistency should be maintained here as well.
   
   **Potential Risks**:
   - Risk 1: Inconsistent error handling, increasing maintenance costs
   - Risk 2: Upper-layer callers cannot distinguish between HBase errors and other runtime errors
   - Risk 3: Error logs may not be clear enough, making troubleshooting difficult
   
   **Scope of Impact**:
   - Direct impact: `HbaseSourceSplitEnumerator.getTableSplits()`
   - Indirect impact: Creation and recovery process of `HbaseSource`
   - Impact area: HBase Source Connector
   
   **Severity**: MINOR
   
   **Improvement Suggestion**:
   ```java
   } catch (IOException e) {
       String errorMsg = String.format(
           "Failed to enumerate splits for HBase table [%s]",
           tableName.getNameAsString());
       log.error(errorMsg, e);
       throw new HbaseConnectorException(
           HbaseConnectorErrorCode.TABLE_QUERY_EXCEPTION, 
           errorMsg, 
           e);
   }
   ```
   
   **Rationale**:
   1. Consistent with preceding exception handling
   2. Provides clearer error messages
   3. Preserves the original exception as cause
   4. Uses the correct error code
   5. Facilitates specific error handling by upper-layer code
   
   ---
   
   ### Issue 3: Missing test coverage for extreme inputs
   
   **Location**: `HbaseParametersTest.java` and `HbaseSourceSplitEnumeratorTest.java`
   
   **Related Context**:
   - Test class: `HbaseParametersTest` - newly added unit tests
   - Test class: `HbaseSourceSplitEnumeratorTest` - updated unit tests
   - Configuration parsing logic: `HbaseParameters.buildWithSourceConfig()` - lines 88-133
   
   **Problem Description**:
   Current tests cover normal scenarios and basic boundary conditions, but are missing tests for some extreme inputs:
   
   1. **When namespace is `null`**: Although the `getNamespace()` method handles `null`, there is no test verification
   2. **table parameter contains multiple colons**: For example `ns:table:extra`, current parsing logic will take the part after the last colon as table
   3. **namespace or table contains spaces**: For example ` ns : table `, may cause parsing errors
   4. **Only colon without table**: For example `test:`, current logic will take empty string as table
   5. **Only table without colon but with spaces before and after**: For example ` table `, current logic will not handle spaces
   
   **Potential Risks**:
   - Risk 1: Extreme user input may cause undefined behavior
   - Risk 2: Bugs not covered by tests may appear in production environment
   - Risk 3: Future code modifications may break handling of these extreme cases
   
   **Scope of Impact**:
   - Direct impact: Configuration parsing logic
   - Indirect impact: Stability of the entire HBase Connector
   - Impact area: HBase Connector
   
   **Severity**: MINOR
   
   **Improvement Suggestion**:
   ```java
   // Added in HbaseParametersTest.java
   @Test
   public void testBuildWithSourceConfigWithNullNamespace() {
       HbaseParameters parameters = HbaseParameters.builder()
           .table("tbl")
           .zookeeperQuorum("127.0.0.1:2181")
           .build();
       Assertions.assertEquals(HbaseParameters.DEFAULT_NAMESPACE, parameters.getNamespace());
   }
   
   @Test
   public void testBuildWithSourceConfigWithEmptyStringNamespace() {
       Map<String, Object> configMap = new HashMap<>();
       configMap.put(HbaseBaseOptions.ZOOKEEPER_QUORUM.key(), "127.0.0.1:2181");
       configMap.put(HbaseBaseOptions.TABLE.key(), ":tbl");  // Only colon
       ReadonlyConfig readonlyConfig = ReadonlyConfig.fromMap(configMap);
       
       HbaseParameters parameters = HbaseParameters.buildWithSourceConfig(readonlyConfig);
       Assertions.assertEquals("", parameters.getNamespace());  // Empty string
       Assertions.assertEquals("tbl", parameters.getTable());
   }
   
   @Test
   public void testBuildWithSourceConfigWithMultipleColons() {
       Map<String, Object> configMap = new HashMap<>();
       configMap.put(HbaseBaseOptions.ZOOKEEPER_QUORUM.key(), "127.0.0.1:2181");
       configMap.put(HbaseBaseOptions.TABLE.key(), "ns:tbl:extra");  // Multiple colons
       ReadonlyConfig readonlyConfig = ReadonlyConfig.fromMap(configMap);
       
       HbaseParameters parameters = HbaseParameters.buildWithSourceConfig(readonlyConfig);
       // Current logic: take the part before the first colon as namespace, the part after as table (including the colon)
       Assertions.assertEquals("ns", parameters.getNamespace());
       Assertions.assertEquals("tbl:extra", parameters.getTable());
   }
   
   @Test
   public void testBuildWithSourceConfigWithSpaces() {
       Map<String, Object> configMap = new HashMap<>();
       configMap.put(HbaseBaseOptions.ZOOKEEPER_QUORUM.key(), "127.0.0.1:2181");
       configMap.put(HbaseBaseOptions.TABLE.key(), " ns : tbl ");  // With spaces
       ReadonlyConfig readonlyConfig = ReadonlyConfig.fromMap(configMap);
       
       HbaseParameters parameters = HbaseParameters.buildWithSourceConfig(readonlyConfig);
       // Current logic: does not handle spaces
       Assertions.assertEquals(" ns ", parameters.getNamespace());
       Assertions.assertEquals(" tbl ", parameters.getTable());
   }
   ```
   
   **Rationale**:
   1. Enhances test coverage
   2. Clarifies current code behavior for extreme inputs
   3. Provides baseline for future input validation improvements
   4. These tests will not block the current PR's merge, but should be supplemented in subsequent PRs
   
   ---
   
   ### Issue 4: Creating HbaseClient immediately in constructor may lead to early failure
   
   **Location**: `HbaseSourceSplitEnumerator.java:63-80`
   
   **Related Context**:
   - Call chain: `HbaseSource.createEnumerator()` → `new HbaseSourceSplitEnumerator(...)`
   - Resource creation: `HbaseClient.createInstance(hbaseParameters)` will establish HBase connection
   - Resource management: `Enumerator`'s `close()` method will close the connection
   
   **Problem Description**:
   The modified code immediately creates `HbaseClient` instances in all constructors, including scenarios where `getTableSplits()` may not be used immediately. This means:
   
   1. Even if just creating an Enumerator object (without enumerating splits), an HBase connection will be established
   2. If the HBase connection fails, an exception will be thrown at the Enumerator creation stage rather than on first use
   3. In some cases (e.g., recovering from checkpoint but not needing to re-enumerate splits), this connection may be unnecessary
   
   **Potential Risks**:
   - Risk 1: Connection failure timing is advanced, which may affect error recovery logic
   - Risk 2: Unnecessary connections may be created in certain initialization scenarios
   - Risk 3: If connection creation is slow, it will block Enumerator creation
   
   **Scope of Impact**:
   - Direct impact: All constructors of `HbaseSourceSplitEnumerator`
   - Indirect impact: Creation process of `HbaseSource`
   - Impact area: HBase Source Connector
   
   **Severity**: MINOR
   
   **Improvement Suggestion**:
   Consider lazy initialization of `HbaseClient`:
   ```java
   private HbaseClient getHbaseClient() {
       if (hbaseClient == null) {
           this.hbaseClient = HbaseClient.createInstance(hbaseParameters);
       }
       return hbaseClient;
   }
   
   // Used in getTableSplits()
   HbaseClient client = getHbaseClient();
   try (RegionLocator regionLocator = client.getRegionLocator(...)) {
       ...
   }
   ```
   
   Or, if connection validation is indeed needed at construction time, this should be clearly documented and error handling should be ensured correct.
   
   **Rationale**:
   1. Lazy initialization can avoid unnecessary connection creation
   2. However, the current design (immediate initialization) is also reasonable, as it can detect configuration errors early
   3. This is more of a design trade-off than a clear bug
   4. If maintaining current design, it's recommended to explain in JavaDoc
   
   ---


-- 
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] [Fix] [connector-hbase] Fix namespace handling for HBase source [seatunnel]

Posted by "yzeng1618 (via GitHub)" <gi...@apache.org>.
yzeng1618 commented on code in PR #10295:
URL: https://github.com/apache/seatunnel/pull/10295#discussion_r2674518087


##########
seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/client/HbaseClient.java:
##########
@@ -377,8 +377,12 @@ public ResultScanner scan(
             String[] columnNameSplit = columnName.split(":");
             scan.addColumn(Bytes.toBytes(columnNameSplit[0]), Bytes.toBytes(columnNameSplit[1]));
         }
+        String namespace =
+                StringUtils.isBlank(hbaseParameters.getNamespace())

Review Comment:
   Thanks for pointing this out. I centralized the fallback in HbaseParameters#getNamespace() (returns DEFAULT_NAMESPACE when null/blank, also safe for direct builder usage), so I removed the redundant null/blank checks in HbaseClient/HbaseSourceSplitEnumerator. 



-- 
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] [Fix] [connector-hbase] Fix namespace handling for HBase source [seatunnel]

Posted by "LiJie20190102 (via GitHub)" <gi...@apache.org>.
LiJie20190102 commented on code in PR #10295:
URL: https://github.com/apache/seatunnel/pull/10295#discussion_r2671927967


##########
seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/client/HbaseClient.java:
##########
@@ -392,4 +396,10 @@ public ResultScanner scan(
     public RegionLocator getRegionLocator(String tableName) throws IOException {
         return this.connection.getRegionLocator(TableName.valueOf(tableName));
     }
+
+    public RegionLocator getRegionLocator(String namespace, String tableName) throws IOException {
+        String actualNamespace =
+                StringUtils.isBlank(namespace) ? HbaseParameters.DEFAULT_NAMESPACE : namespace;

Review Comment:
   ditto



##########
seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/source/HbaseSourceSplitEnumerator.java:
##########
@@ -176,59 +187,88 @@ private void assignSplit(int taskId) {
     public Set<HbaseSourceSplit> getTableSplits() {
 
         try {
-            RegionLocator regionLocator = hbaseClient.getRegionLocator(hbaseParameters.getTable());
-            byte[][] startKeys = regionLocator.getStartKeys();
-            byte[][] endKeys = regionLocator.getEndKeys();
-            List<HbaseSourceSplit> splits = new ArrayList<>();
-            boolean isBinaryRowkey = hbaseParameters.isBinaryRowkey();
-            byte[] userStartRowkey =
-                    HBaseUtil.convertRowKey(hbaseParameters.getStartRowkey(), isBinaryRowkey);
-            byte[] userEndRowkey =
-                    HBaseUtil.convertRowKey(hbaseParameters.getEndRowkey(), isBinaryRowkey);
-            HBaseUtil.validateRowKeyRange(userStartRowkey, userEndRowkey);
-
-            int i = 0;
-            while (i < startKeys.length) {
-                byte[] regionStartKey = startKeys[i];
-                byte[] regionEndKey = endKeys[i];
-                if (userEndRowkey.length > 0
-                        && Bytes.compareTo(userEndRowkey, regionStartKey) <= 0
-                        && Bytes.compareTo(regionStartKey, HConstants.EMPTY_BYTE_ARRAY) != 0) {
-                    i++;
-                    continue;
-                }
+            String namespace = hbaseParameters.getNamespace();
+            if (namespace == null || namespace.isEmpty()) {

Review Comment:
   ditto



##########
seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/client/HbaseClient.java:
##########
@@ -377,8 +377,12 @@ public ResultScanner scan(
             String[] columnNameSplit = columnName.split(":");
             scan.addColumn(Bytes.toBytes(columnNameSplit[0]), Bytes.toBytes(columnNameSplit[1]));
         }
+        String namespace =
+                StringUtils.isBlank(hbaseParameters.getNamespace())

Review Comment:
   After obtaining the namespace using `hbaseParameters.getNamespace()`, is it unnecessary to check for nullity, since it has already been set to non-null when constructing `hbaseParameters`



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