Skip to content

Microseconds not preserved in sink connector #1532

@hassan-chughtai

Description

Environment

  • Kafka Connect version: 7.6.0-ce
  • JdbcSinkConnector version: 10.8.3
  • Database is Postgres version: PostgreSQL 17.4 (Debian 17.4-1.pgdg120+2) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

Issue

If I have a record with a string timestamp such as 2025-08-28 15:01:00.123456, then it appears that there is no way of preserving the microseconds when using TimestampConverter to convert this into a Timestamp type. This appears to be because TimestampConverter uses SimpleDateFormat to do the conversion, which does not support microseconds.

I have tried to preserve microseconds by writing a custom SMT that uses DateTimeFormatter for parsing the string instead, and then calls the .setNanos(int n) method on the Timestamp object: https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html#setNanos-int-

But this does not work and microseconds are still truncated off - i.e. the timestamp inserted into the database will actually be 2025-08-28 15:01:00.123000. However, within the SMT itself, it appears that the nanos property is set as expected to a value of 456000, so is there something that is happening in the connector pipeline that is truncating these microseconds?

Additionally, are there any plans to move away from SimpleDateFormat and use the more modern DateTimeFormatter to perform date parsing logic? This would support microseconds and avoid pitfalls such as that seen in #1497.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions