vnayakg opened a new pull request, #23992: URL: https://github.com/apache/kafka/pull/23992
`Values.convertToString(schema, value)` accepted a schema but never used it when serializing `java.util.Date` values. `dateFormatFor(Date)` picked the format purely from the millisecond value, so any `Timestamp` falling exactly on midnight UTC (`getTime() % MILLIS_PER_DAY == 0`) was emitted as `yyyy-MM-dd`, silently dropping the time component. Connectors producing timestamp headers (e.g. MongoDB source) hit this via `SimpleHeaderConverter`; on the way back, `parseString` then yielded a `Date` schema instead of `Timestamp`. This change makes date formatting schema-aware: - Adds `Values.dateFormatFor(Schema, Date)`, which selects the ISO-8601 pattern from the logical type name (`Time`, `Date`, `Timestamp`) and falls back to the existing millisecond heuristic when the schema is null or not a logical type. - Threads the schema through `append`/`appendIterable` so dates nested in `Struct` fields, array elements and map keys/values are formatted according to their element schema. Key/value schemas are only consulted when the schema type is actually `MAP`/`ARRAY`, since `ConnectSchema` throws otherwise. - `Cast` SMT passes the field schema into `castToString`, so casting a midnight `Timestamp` field to `STRING` keeps the time component. Schemaless casts are unchanged. The existing `dateFormatFor(Date)` and the `append`/`appendIterable` overloads are retained and delegate with a null schema, so schemaless callers and subclasses see no change. Behaviour change: when a schema *is* present, it is now authoritative. A `Date` schema value carrying non-zero millis within the day is emitted as `yyyy-MM-dd`, and a `Time` schema value is emitted as `HH:mm:ss.SSS'Z'` regardless of magnitude. Previously both would have been guessed from the millisecond value. -- 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]
