SEPURI-SAI-KRISHNA opened a new pull request, #13674:
URL: https://github.com/apache/seatunnel/pull/13674
Yes, glad to contribute to Apache SeaTunnel.
### Purpose of this pull request
Fixes the BINARY part of #13022. #13023 fixed the DECIMAL part and left
BINARY for a follow-up, because the values needed converting too and the
`DatabendIT` image could not test it. This PR does both, so it closes #13022.
**The source.** `DatabendCatalog.convertDatabendType` mapped `BINARY` and
`VARBINARY` to `BYTE_TYPE` (TINYINT), while the docs say BYTES. The reader then
called `getObject`, which in databend-jdbc 0.3.7 returns the hex text the
server sends, such as `00FF10`, so a TINYINT field carried a String. `getBytes`
is no way out: it throws for any non null value. Now both types map to
`PrimitiveByteArrayType`, and `DatabendUtil.readBinary` decodes the hex text
(either case) into the bytes. Text that is not hex fails the row with
`PARSE_RESPONSE_FAILED` instead of becoming NULL.
**The sink.** `DatabendSinkWriter` bound a `byte[]` with `setObject`. The
driver sends it as the raw bytes, and a `BINARY` column parses them as hex.
Measured on Databend v1.2.970 (nightly) with databend-jdbc 0.3.7, in the sink's
batch insert path:
- bytes `01 02 FE`: the insert fails with `Illegal hex string`
- the four bytes of the text `CAFE`: no error, stored as the two bytes `CA
FE`
- `setString` with the hex text: stored correctly, in either case
The writer now sends the hex text of a `byte[]`. The same batch insert
stores an empty string as NULL, so an empty byte array is written as NULL; the
docs say so. CDC mode is not changed: it writes through the JSON staging table,
where `BYTES` is Base64 text.
**Two format settings can still change the bytes, so both are checked when
the job starts.**
- The server setting `binary_output_format` (default `hex`) controls the
text the source receives. Measured on v1.2.970: under `base64` the bytes `00 00
00` arrive as `AAAA`, which is also valid hex and would decode to `AA AA`
without an error. `DatabendUtil.checkBinaryOutputFormat` runs once when the
reader opens, only if a field is BYTES. If the value is not `hex`, the job
stops and the message says to add `session_settings=binary_output_format=hex`
to the `url`, which I measured overrides a global `base64`. On v1.2.71, which
has no such setting, the query returns no row and nothing is checked.
- The driver's own `url` property `binary_format` is added to the file
format of the batch insert. Measured: with `binary_format=base64` the text
`CAFE` is stored as `08 01 44`. The server settings did not change the stored
bytes: `binary_input_format` as `base64`, `hex` or `utf-8` per session and
`base64` globally, and `binary_output_format` as `base64` globally.
`DatabendUtil.checkSinkBinaryFormat` stops a non CDC sink job that writes BYTES
when `binary_format` is set to anything other than `hex`.
### Does this PR introduce any user facing change?
Yes, recorded in `incompatible-changes.md` in en and zh with migration steps:
- A `BINARY` or `VARBINARY` column is `BYTES` in the job, with the bytes as
values, instead of hex text in a TINYINT field. A table SeaTunnel creates from
such a source gets a bytes column.
- The sink stores the bytes it is given. An empty byte array is stored as
NULL.
- A source job stops before reading a row when `binary_output_format` is not
`hex`. A non CDC sink job that writes BYTES stops when its `url` sets
`binary_format` to anything other than `hex`. With the defaults neither check
fires.
The source docs get a `VARBINARY | BYTES` row and a section on the check.
The sink docs explain how BYTES values are written and the `binary_format`
check. No option, default or SPI signature changed, and no dependency was added.
### How was this patch tested?
**Unit tests**, `connector-databend`, 41 tests, 0 failures:
- `DatabendCatalogTest.aBinaryColumnIsBytesNotTinyint`
- `DatabendSinkWriterTest.testWriteBindsBytesAsHexText`
- `DatabendUtilTest`, new, 13 tests: hex round trip of every byte value,
decoding either case, rejecting text that is not hex, reading a binary column
and a row, failing the row on bad text, and both checks (accepted values,
rejected values, a server without the setting, rows without BYTES).
With `DatabendCatalog` and `DatabendSinkWriter` reverted to `dev`, 3 fail:
`aBinaryColumnIsBytesNotTinyint` and
`theMappingIsIndependentOfTheDefaultLocale` (`expected: <BYTES> but was:
<TINYINT>`), and `testWriteBindsBytesAsHexText`. Turning both checks into
no-ops makes exactly `otherBinaryOutputFormatsFailBeforeAnyRowIsRead` and
`theSinkRejectsABinaryFormatThatWouldStoreOtherBytes` fail.
**E2E.** The tests are in `DatabendCDCSinkIT` because it runs
`datafuselabs/databend:nightly`, where `BINARY` is a real type; the v1.2.71
image of `DatabendIT` parses it as `STRING`. Four new tests:
- `testDatabendSinkWritesBinaryBytes`: FakeSource to a table the sink
creates. It checks the columns are `binary` and that `HEX()` reads back
`00ff10`, `43414645` (the bytes of `CAFE`), and NULL for the empty value and
for nulls.
- `testDatabendSourceReadsBinaryBytes`: reads `00 FF 10` and `43 41 46 45`
into an Assert sink with `field_type = bytes` and the expected values.
- `testDatabendSinkRejectsNonHexBinaryFormat` and
`testDatabendSourceRejectsNonHexBinaryOutput`: the job exits non zero, and its
message appears in the job output or the server logs. On Flink 1.18 the message
stays in the task manager log: after the reader fails, the task is reset and
`SingleSplitEnumerator.addSplitsBack` throws `IndexOutOfBoundsException` on an
empty list, which the client reports instead. That is existing behavior on
`dev`, not changed here.
Run locally with `RUN_ALL_CONTAINER=false`: 16 tests (4 tests on Zeta, Flink
1.18, Flink 1.20 and Spark 3.3), 0 failures.
**Build checks**, JDK 17: `spotless:check` on `connector-databend` and
`connector-databend-e2e` clean; `MarkdownTest` and
`AllFileSpecificationCheckTest` in `seatunnel-ci-tools` pass.
### Check list
* [X] Code changed are covered with tests, or it does not need tests for
reason
* [X] If any new Jar binary package adding in your PR, please add License
Notice according to
[License
Notice](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md):
none added.
* [X] If necessary, please update the documentation to describe the new
feature: source and sink Databend docs and `incompatible-changes.md`, en and zh.
* [X] 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):
not needed, no new connector.
2. Update the pom file of
[seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml):
not needed, no new module.
3. Add ci label in
[label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml):
not needed, connector-databend is already labelled.
4. Add e2e test for your connector: done, four tests in
`DatabendCDCSinkIT`.
5. Update [connector-v2
doc](https://github.com/apache/seatunnel/tree/dev/docs/en/connectors): done.
* [X] Update the `release-note`: not applicable, the file was removed from
`dev` in #9304.
--
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]