You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by gi...@apache.org on 2026/08/26 14:50:42 UTC

(seatunnel) 01/01: [Improve][Connector-V2][HBase] Migrate timestamp validation to OptionRule (#11803)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/dev/pr-11803-13d3977f8e03869f0ba693d462f94ac786e00cc7
in repository https://gitbox.apache.org/repos/asf/seatunnel.git

commit 0a5708bf64bd891d55a872d308f0ee1227e91848
Author: Goutam Adwant <86...@users.noreply.github.com>
AuthorDate: Wed Aug 26 14:45:03 2026 +0000

    [Improve][Connector-V2][HBase] Migrate timestamp validation to OptionRule (#11803)
    
    Signed-off-by: goutamadwant <wo...@gmail.com>
---
 docs/en/connectors/source/Hbase.md                 |  2 +-
 docs/zh/connectors/source/Hbase.md                 |  2 +-
 .../seatunnel/hbase/source/HbaseSourceFactory.java | 11 +++-
 .../seatunnel/hbase/HbaseFactoryTest.java          | 58 ++++++++++++++++++++++
 4 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/docs/en/connectors/source/Hbase.md b/docs/en/connectors/source/Hbase.md
index 612bbde0bb..409829e709 100644
--- a/docs/en/connectors/source/Hbase.md
+++ b/docs/en/connectors/source/Hbase.md
@@ -117,7 +117,7 @@ End timestamp (exclusive) for scan time range. Unit: milliseconds since epoch. T
 
 **Notes:**
 
-- `start_timestamp` / `end_timestamp` must be >= 0. If both are set, `start_timestamp` must be < `end_timestamp` (time range is [start, end), so `start_timestamp == end_timestamp` produces an empty scan).
+- `start_timestamp` must be >= 0 and `end_timestamp` must be > 0. If both are set, `start_timestamp` must be < `end_timestamp` (time range is [start, end), so `start_timestamp == end_timestamp` produces an empty scan).
 - When `start_rowkey` / `end_rowkey` and `start_timestamp` / `end_timestamp` are configured together, both the rowkey range and the time range constraints are applied (intersection).
 
 ### common-options
diff --git a/docs/zh/connectors/source/Hbase.md b/docs/zh/connectors/source/Hbase.md
index 8b2d0c73b6..72c9475e15 100644
--- a/docs/zh/connectors/source/Hbase.md
+++ b/docs/zh/connectors/source/Hbase.md
@@ -115,7 +115,7 @@ HBase 的行键既可以是文本字符串,也可以是二进制数据。在 S
 
 **说明:**
 
-- `start_timestamp` / `end_timestamp` 必须大于等于 0;若两者同时配置,需要满足 `start_timestamp < end_timestamp`(遵循 [start, end) 约定,`start_timestamp == end_timestamp` 将导致空扫描)。
+- `start_timestamp` 必须大于等于 0,`end_timestamp` 必须大于 0;若两者同时配置,需要满足 `start_timestamp < end_timestamp`(遵循 [start, end) 约定,`start_timestamp == end_timestamp` 将导致空扫描)。
 - 当 `start_rowkey` / `end_rowkey` 与 `start_timestamp` / `end_timestamp` 同时配置时,会同时应用行键范围与时间范围限制,最终返回两者的交集。
 
 ### 常用选项
diff --git a/seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/source/HbaseSourceFactory.java b/seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/source/HbaseSourceFactory.java
index a43c4a7b74..d4899fd347 100644
--- a/seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/source/HbaseSourceFactory.java
+++ b/seatunnel-connectors-v2/connector-hbase/src/main/java/org/apache/seatunnel/connectors/seatunnel/hbase/source/HbaseSourceFactory.java
@@ -18,6 +18,7 @@
 
 package org.apache.seatunnel.connectors.seatunnel.hbase.source;
 
+import org.apache.seatunnel.api.configuration.util.Conditions;
 import org.apache.seatunnel.api.configuration.util.OptionRule;
 import org.apache.seatunnel.api.source.SeaTunnelSource;
 import org.apache.seatunnel.api.source.SourceSplit;
@@ -56,9 +57,15 @@ public class HbaseSourceFactory implements TableSourceFactory {
                         HbaseSourceOptions.START_ROW_KEY,
                         HbaseSourceOptions.END_ROW_KEY,
                         HbaseSourceOptions.START_ROW_INCLUSIVE,
-                        HbaseSourceOptions.END_ROW_INCLUSIVE,
+                        HbaseSourceOptions.END_ROW_INCLUSIVE)
+                .optional(
                         HbaseSourceOptions.START_TIMESTAMP,
-                        HbaseSourceOptions.END_TIMESTAMP)
+                        HbaseSourceOptions.END_TIMESTAMP,
+                        Conditions.greaterOrEqual(HbaseSourceOptions.START_TIMESTAMP, 0L),
+                        Conditions.greaterThan(HbaseSourceOptions.END_TIMESTAMP, 0L),
+                        Conditions.lessThanField(
+                                HbaseSourceOptions.START_TIMESTAMP,
+                                HbaseSourceOptions.END_TIMESTAMP))
                 .build();
     }
 
diff --git a/seatunnel-connectors-v2/connector-hbase/src/test/java/org/apache/seatunnel/connectors/seatunnel/hbase/HbaseFactoryTest.java b/seatunnel-connectors-v2/connector-hbase/src/test/java/org/apache/seatunnel/connectors/seatunnel/hbase/HbaseFactoryTest.java
index 2d9042f6dd..1bda5774ab 100644
--- a/seatunnel-connectors-v2/connector-hbase/src/test/java/org/apache/seatunnel/connectors/seatunnel/hbase/HbaseFactoryTest.java
+++ b/seatunnel-connectors-v2/connector-hbase/src/test/java/org/apache/seatunnel/connectors/seatunnel/hbase/HbaseFactoryTest.java
@@ -17,15 +17,73 @@
 
 package org.apache.seatunnel.connectors.seatunnel.hbase;
 
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.configuration.util.ConfigValidator;
+import org.apache.seatunnel.api.configuration.util.OptionValidationException;
+import org.apache.seatunnel.connectors.seatunnel.hbase.config.HbaseBaseOptions;
+import org.apache.seatunnel.connectors.seatunnel.hbase.config.HbaseSourceOptions;
 import org.apache.seatunnel.connectors.seatunnel.hbase.sink.HbaseSinkFactory;
+import org.apache.seatunnel.connectors.seatunnel.hbase.source.HbaseSourceFactory;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests factory option rules, including the half-open {@code [start_timestamp, end_timestamp)}
+ * range.
+ */
 public class HbaseFactoryTest {
 
     @Test
     public void optionRuleTest() {
         Assertions.assertNotNull((new HbaseSinkFactory()).optionRule());
+        Assertions.assertNotNull((new HbaseSourceFactory()).optionRule());
+    }
+
+    @Test
+    void testValidTimestampRanges() {
+        Assertions.assertDoesNotThrow(() -> validateTimestampRange(null, null));
+        Assertions.assertDoesNotThrow(() -> validateTimestampRange(0L, null));
+        Assertions.assertDoesNotThrow(() -> validateTimestampRange(null, 1000L));
+        Assertions.assertDoesNotThrow(() -> validateTimestampRange(0L, 1L));
+        Assertions.assertDoesNotThrow(() -> validateTimestampRange(0L, 1000L));
+    }
+
+    @Test
+    void testNegativeTimestampFails() {
+        assertInvalidTimestampRange(-1L, null);
+        assertInvalidTimestampRange(null, -1L);
+        assertInvalidTimestampRange(null, 0L);
+    }
+
+    @Test
+    void testInvalidTimestampRangeFails() {
+        // Equal bounds describe an empty half-open range and are rejected before source creation.
+        assertInvalidTimestampRange(1000L, 1000L);
+        assertInvalidTimestampRange(2000L, 1000L);
+    }
+
+    private void assertInvalidTimestampRange(Long startTimestamp, Long endTimestamp) {
+        Assertions.assertThrows(
+                OptionValidationException.class,
+                () -> validateTimestampRange(startTimestamp, endTimestamp));
+    }
+
+    private void validateTimestampRange(Long startTimestamp, Long endTimestamp) {
+        Map<String, Object> config = new HashMap<>();
+        config.put(HbaseBaseOptions.ZOOKEEPER_QUORUM.key(), "127.0.0.1:2181");
+        config.put(HbaseBaseOptions.TABLE.key(), "test_table");
+        if (startTimestamp != null) {
+            config.put(HbaseSourceOptions.START_TIMESTAMP.key(), startTimestamp);
+        }
+        if (endTimestamp != null) {
+            config.put(HbaseSourceOptions.END_TIMESTAMP.key(), endTimestamp);
+        }
+
+        ConfigValidator.of(ReadonlyConfig.fromMap(config))
+                .validate(new HbaseSourceFactory().optionRule());
     }
 }