zhangshenghang opened a new pull request, #13778: URL: https://github.com/apache/seatunnel/pull/13778
Yes, I am contributing this change to Apache SeaTunnel. ## Problem The HBase source rebuilds data that never changes inside its per-row read loop: - **Column references.** `HbaseSourceReader.convertRawRow` resolved every declared column with `namesMap.get(columnName)`, a `ConcurrentHashMap<String, byte[][]>` lookup keyed by the column name, for every column of every row, and split the `"columnFamily:column"` string lazily on the first hit. A 20-column row therefore did 19 concurrent map lookups with string hashing per record, although the mapping only depends on the declared row type. - **Time parsers.** `HBaseDeserializationFormat.deserializeValue` compiled a fresh `DateTimeFormatter` with `DateTimeFormatter.ofPattern(...)` for every `DATE`, `TIME` and `TIMESTAMP` cell. `ofPattern` parses the pattern and builds a new formatter object graph per call, and the three patterns are fixed per format instance. Both are per-cell costs in the hot scan loop (`HbaseSourceReader.pollNext` -> `convertRawRow` -> `deserialize`), which is the dominant CPU path of a bounded HBase scan once the scanner caching has been configured. ## Change - Resolve the family and qualifier bytes for every declared column once in the `HbaseSourceReader` constructor into two `byte[][]` arrays indexed by field position; a `null` family marks the row key field. `convertRawRow` then reads the precomputed arrays instead of the map. - Deserialize `DATE`/`TIME`/`TIMESTAMP` cells through `DateUtils.parse`, `TimeUtils.parse` and `DateTimeUtils.parse`, which reuse the `DateTimeFormatter` instances those utilities already cache. They build the formatters with `DateTimeFormatter.ofPattern(Formatter.value)`, i.e. exactly the same patterns and same resolver style as before, so parsing behaviour is unchanged. No public API, configuration option, default value, serialization format or SPI change. Column names are validated in the constructor before the arrays are built (the existing `Preconditions` check already requires every non-rowkey column to be `columnFamily:column`), so invalid declarations still fail at construction time. For a given `Result` the produced `SeaTunnelRow` is identical. **Acceptance criteria:** the deserialized rows are unchanged, and the per-row read-path cost and the per-call allocation of deserializing time-typed cells drop measurably. Both are checked below. ## Modules - `seatunnel-connectors-v2/connector-hbase` only: `HbaseSourceReader`, `HBaseDeserializationFormat` and `HbaseSourceReaderTest`. ## Verification Run locally with JDK 17: ``` ./mvnw -o -q -pl seatunnel-connectors-v2/connector-hbase spotless:apply ./mvnw -o -pl seatunnel-connectors-v2/connector-hbase -DskipTests -Dspotless.check.skip=true -Dcheckstyle.skip=true compile ./mvnw -o -pl seatunnel-connectors-v2/connector-hbase test ``` Result: `spotless` and `compile` pass; 61 tests, 0 failures, 0 errors. One test is added to `HbaseSourceReaderTest`: - `testPollNextResolvesDeclaredColumnsAndTypedCells`: a real `Result` (built from `KeyValue` cells) is read through `pollNext` with a row type whose fields are not in row-key-first order and mix two column families. It asserts that the row key, a string column and DATE/TIME/TIMESTAMP cells all map to the declared fields with the expected values, which covers both the precomputed column references and the cached parsers. ### Measurement A temporary harness (not committed, to keep the diff minimal) drives the read path with a mocked `HbaseClient` and reports the median of 7 measured rounds after warmup. Two independent runs per side are listed to show the spread. - Typed cells: one `deserialize` call over 3 cells (`DATE`, `TIME`, `TIMESTAMP`), 300k iterations per round. - Read path: `HbaseSourceReader.pollNext` over 4,000 distinct `Result`s x 5 splits (20,000 rows) per round, 1 row key + 19 payload `STRING` columns. | metric | before (run 1 / run 2) | after (run 1 / run 2) | delta | | --- | --- | --- | --- | | 3 typed cells per `deserialize` | 703.4 / 622.7 ns | 521.2 / 514.6 ns | about **-17% to -26%** | | allocation per `deserialize` (`ThreadMXBean.getThreadAllocatedBytes`) | 3168 / 3168 B | 1816 / 1816 B | **-1352 B (-42.7%)** | | read path, 20 columns | 1770.6 / 1793.9 ns/row | 1342.3 / 1355.8 ns/row | about **-23% to -25%** | The read-path numbers include the mocked scanner iteration and `Result.getValue` work, which are identical on both sides; the difference is the removed per-column map lookup. The real source spends additional time in the HBase client and in `Result.getValue` cloning, so the relative gain on a real cluster is smaller than this isolated measurement. ## Remaining risk and follow-up - The HBase E2E suite (`connector-hbase-e2e`) was not run because it needs Docker and an HBase container. The changed branches are covered by the unit test above; the deserializer already had round-trip coverage in `HbaseSinkWriterTypeConvertTest`. - `HbaseSourceReader` still turns every `Result` into a `byte[][]` before decoding it, and `Result.getValue` clones the value bytes per column. Changing that would touch the `Result` consumption contract and is deliberately left out. - Follow-up, not part of this change: `BigtableDeserializationFormat` uses the same per-cell `DateTimeFormatter.ofPattern` pattern in its DATE/TIME/TIMESTAMP branches. There is no tracking issue for this change; it is a self-contained improvement to the connector's read path. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
