debezium / debezium/dbz

PostgreSQL JDBC sink cannot bind Connect ARRAY<BYTES> values to bytea[]

Open
#2,571 0 comments 0 reactions 0 assignees View on GitHub
component/jdbc-connector type/bug
Dominant language
HTML
Stars
6
Forks
8
Avg merge
2d 19h
Merged PRs (30d)
1

Description

## Problem

The PostgreSQL JDBC sink resolves a Kafka Connect `ARRAY` field to a PostgreSQL `bytea[]` column, but fails while binding the value.

The resulting exception is:

```text
java.lang.UnsupportedOperationException: byte[] nested inside Object[]
```

PostgreSQL supports `bytea[]`, and the JDBC sink already selects the correct destination column type. The failure occurs while converting the Connect collection into a value accepted by the PostgreSQL JDBC driver.

## Environment

* Debezium JDBC Sink 3.7.0-SNAPSHOT
* PostgreSQL 18.6
* PostgreSQL JDBC driver included in the Debezium nightly image
* Kafka 3.8.0

The same result was reproduced with PostgreSQL 16.14 and Debezium 3.6.1.Final.

The test record was generated by:

* Percona Server for MongoDB 8.0.29-13
* Debezium MongoDB Source 3.7.0-SNAPSHOT
* `ExtractNewDocumentState`
* `array.encoding=array`

The JDBC problem is not MongoDB-specific. Any producer emitting `ARRAY` can trigger it.

## Reproduction

Create a Connect record whose value contains:

```text
Schema: ARRAY
Value: [byte[]{0x01, 0x02, 0x03}, byte[]{0x04, 0x05, 0x06}]
```

One way to generate it through MongoDB is:

```javascript
db.binary_arrays.insertOne({
_id: "binary-arrays-1",
binary_array: [
BinData(0, "AQID"),
BinData(0, "BAUG")
]
});
```

Use a PostgreSQL JDBC sink with:

```properties
insert.mode=upsert
primary.key.mode=record_key
schema.evolution=basic
flush.max.retries=0
```

## Actual behavior

The sink creates a `bytea[]` column, then fails:

```text
ConnectException: Failed to flush records for table 'binary_arrays'
Caused by: java.lang.UnsupportedOperationException: byte[] nested inside Object[]
```

## Expected behavior

The JDBC sink should store both elements in the PostgreSQL `bytea[]` column.

For the sample input:

```sql
SELECT
encode(binary_array[1], 'hex'),
encode(binary_array[2], 'hex')
FROM binary_arrays;
```

should return:

```text
010203
040506
```

## Suggested improvement

Normalize Connect `ARRAY` values into the representation expected by the PostgreSQL JDBC driver before calling `Connection.createArrayOf()`.

For example, the binder might need to create a typed binary array rather than an `Object[]` containing individual `byte[]` values.

Regression tests should cover:

* multiple binary elements
* null binary elements
* empty arrays
* row-wise writes
* batched writes

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.