zhangshenghang opened a new pull request, #13785:
URL: https://github.com/apache/seatunnel/pull/13785
## Acknowledgement
Yes, I acknowledge that this change is contributed to **Apache SeaTunnel**.
## Background
The Bigtable source converts every row returned by `readRows()` into a
`SeaTunnelRow`
in `BigtableSourceReader.convertRow()` and
`BigtableDeserializationFormat.deserialize()`.
Both steps redo work that only depends on the declared row type, so the cost
is paid
once per row and once per cell:
1. `convertRow()` allocated a `HashMap` for every row and, for every cell,
built a
`"family:qualifier"` key with string concatenation plus a UTF-8 decode of
the
qualifier, only to look the value up again by field name. With 20 columns
that is
20 key strings and 20 hash-map insertions per row, all of which are pure
overhead.
2. `deserializeCell()` called `DateTimeFormatter.ofPattern()` for every
`DATE`/`TIME`/`TIMESTAMP` cell, although the three patterns are constants
of the
format, and it materialized a `byte[]` copy of every cell value before
decoding it.
Neither of these depends on the data, so both belong to the reader/format
setup, not
to the row loop.
### Acceptance criteria
* The emitted `SeaTunnelRow` is byte-for-byte identical for every supported
field type.
* The cell -> field mapping is still resolved from the same
`family:qualifier` field
names and the same `rowkey_column` configuration, including the "latest
version wins"
rule for a column that has several versions in one `Row`.
* The row conversion step gets measurably cheaper in both CPU time and
allocation.
## Change
* `BigtableSourceReader`: resolve the cell -> field mapping once in the
constructor
(`family -> qualifier -> field indexes`) and mark the row-key fields once.
The per-row
loop now only looks up the cell's family and qualifier; no per-row map, no
per-cell
string building. Declaring the same `family:qualifier` twice still feeds
both fields,
and a field whose cell is absent still stays `null`.
* `BigtableDeserializationFormat`: build the three `DateTimeFormatter`s once
per format
instance, read numeric cells directly (`byteAt` / `asReadOnlyByteBuffer`)
and decode
text cells with `ByteString.toStringUtf8()`. `BYTES` still returns its own
array
because the row owns it.
### Modules and compatibility
* Only `connector-google-bigtable` is touched: two main classes and its
existing unit
test class.
* No configuration option, default value, public API, SPI or serialized
state changes.
The connector options and the row schema semantics are untouched.
## Verification
Executed locally with JDK 17:
```
./mvnw -o -q -pl seatunnel-connectors-v2/connector-google-bigtable
spotless:apply
./mvnw -o -pl seatunnel-connectors-v2/connector-google-bigtable -DskipTests
-Dspotless.check.skip=true -Dcheckstyle.skip=true compile
./mvnw -o -pl seatunnel-connectors-v2/connector-google-bigtable
-Dspotless.check.skip=true -Dcheckstyle.skip=true test
```
Results: `BUILD SUCCESS`, `Tests run: 43, Failures: 0, Errors: 0, Skipped:
0`.
Two unit tests were added to the existing `BigtableSourceReaderTest`:
* `testConvertRowMapsDeclaredColumnsPerFamily` — one qualifier name in two
families,
two versions of the same column, an undeclared cell and an absent column.
* `testConvertRowDecodesAllSupportedFieldTypes` — every supported field type
(`TINYINT`..`DOUBLE`, `BOOLEAN`, `BYTES`, `DECIMAL`, `DATE`, `TIME`,
`TIMESTAMP`,
`STRING`).
### Quantified result
Micro-benchmark of `convertRow()` on a 20-column row (1 row key + 19 columns
across two
families, one column with two versions), 200k rows per round, 5 rounds,
median, after
warm-up:
| | ns / row | allocated bytes / row |
| --- | --- | --- |
| before | 2195 | 9487 |
| after | 1341 | 3495 |
That is roughly **-39% CPU time** and **-63% allocation** on the row
conversion step.
The benchmark drives the real `convertRow()` through the connector's own
fixtures and
excludes the Bigtable network scan, which is unchanged.
## Remaining risks and follow-up
* The change relies on the existing assumption that `Row.getCells()` returns
cells in
timestamp-descending order, which the previous `putIfAbsent` logic already
relied on.
* Duplicate declarations of the same `family:qualifier` column keep working;
a field
name without `family:` separator is still always `null`, as before.
* Not covered here: the sink write path rebuilds the same kind of per-row
metadata
(column indexes, qualifier `ByteString`s). That is a separate change and
is left out
of this PR.
* No end-to-end test against a real Bigtable instance was run; the change is
covered by
unit tests with real `Row`/`RowCell` objects.
--
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]