corgy-w opened a new pull request, #13370:
URL: https://github.com/apache/seatunnel/pull/13370

   ### What changes
   
   Fix two timestamp call sites in the InfluxDB sink serializer so the point 
timestamp is declared in the unit it is actually measured in.
   
   - Processing time (`key_time` not configured), in 
`DefaultSerializer#createTimestampExtractor`:
     `builder.time(System.currentTimeMillis(), precision)` -> 
`builder.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)`
   - The `TIMESTAMP` `key_time` branch:
     
`builder.time(localDateTime.atZone(ZoneOffset.UTC).toInstant().toEpochMilli(), 
precision)` -> `builder.time(..., TimeUnit.MILLISECONDS)`
   
   Nothing else in the serializer changes. The `en`/`zh` `key_time` 
documentation is corrected accordingly.
   
   ### Why
   
   `System.currentTimeMillis()` and `toEpochMilli()` produce epoch 
**milliseconds**, but the value was handed to `Point.Builder#time(Number, 
TimeUnit)` together with the `epoch` sink option's unit, which defaults to `n` 
-> `TimeUnit.NANOSECONDS`.
   
   influxdb-java's `Point.formatedTime` converts the stored value from the 
precision declared on the point to the output precision. `InfluxDBSinkWriter` 
builds its `BatchPoints` without setting a precision, so `BatchPoints` defaults 
to `NANOSECONDS`; the conversion factor becomes 1 and the raw millisecond value 
is written verbatim into the line protocol as if it were nanoseconds:
   
   - buggy: `cpu value=1.0 1795146588629` -> InfluxDB reads `1795146588629` ns 
-> **1970-01-01T00:29:55.146Z**
   - fixed: `cpu value=1.0 1795146588629000000` -> **2026-11-20T03:49:48.629Z**
   
   The `TIMESTAMP` branch had the same offset: a row value of 
`2024-01-01T00:00:00` (UTC) is `1704067200000` ms but was emitted as 
`1704067200000` ns -> `1970-01-01T00:28:24.067Z`; it was only correct when 
`epoch` happened to be `MS`.
   
   The null-value fallback a few lines above already used 
`TimeUnit.MILLISECONDS`, which confirms the two changed sites were oversights 
rather than design.
   
   ### Why `STRING` / `BIGINT` keep `precision`
   
   `epoch` is a user-facing declaration for numeric timestamps supplied by the 
user: a `STRING` or `BIGINT` `key_time` value is documented as already being 
expressed in the configured `epoch` precision, so those branches must keep 
declaring `precision`. Only the two branches that **generate** the value as 
epoch milliseconds are changed.
   
   ### Docs
   
   - `docs/en/connectors/sink/InfluxDB.md` and 
`docs/zh/connectors/sink/InfluxDB.md`, `key_time` section: removed the "only 
matches the point precision when `epoch` is `MS`" limitation, documented that 
`TIMESTAMP` values are converted with UTC to epoch milliseconds and written 
with millisecond precision (so they are correct for any `epoch` value), and 
documented that the processing time used when `key_time` is omitted is written 
with millisecond precision.
   - The `STRING` / `BIGINT` wording (values are in the `epoch` precision) is 
unchanged.
   
   ### Tests
   
   `DefaultSerializerTest` (existing class, strengthened; no new test class):
   
   - `shouldUseProcessingTimeWhenTimeKeyNotConfigured` previously only asserted 
that the point was non-null, which is why this bug survived. It now serializes 
with the default `epoch` (`NS`) and asserts the emitted line-protocol 
timestamp, interpreted as nanoseconds, equals the current time in milliseconds 
(inside the `[before, after]` window of the call) and is after 2020.
   - `shouldSerializeLocalDateTimeTimeColumn` now asserts the emitted timestamp 
is exactly the UTC epoch-millisecond value of the `LocalDateTime` 
(`1704067200000000000` ns for `2024-01-01T00:00:00Z`) with the default `NS` 
epoch.
   - Added `shouldSerializeLocalDateTimeTimeColumnWithMillisecondEpoch` to 
prove the `TIMESTAMP` result is identical for `epoch=MS`.
   
   RED (fix reverted, strengthened tests in place) - `Tests run: 8, Failures: 
2, Errors: 0, Skipped: 0`:
   
   ```
   shouldUseProcessingTimeWhenTimeKeyNotConfigured: processing time timestamp 
should be the current time in milliseconds but was 1795146 
(1970-01-01T00:29:55.146Z)
   shouldSerializeLocalDateTimeTimeColumn: TIMESTAMP key_time must be written 
as epoch milliseconds ==> expected: <1704067200000000000> but was: 
<1704067200000>
   ```
   
   GREEN (with the fix) - `Tests run: 8, Failures: 0, Errors: 0, Skipped: 0`; 
full module - `Tests run: 50, Failures: 0, Errors: 0, Skipped: 0`.
   
   Commands:
   
   ```
   ./mvnw -o -q -pl seatunnel-connectors-v2/connector-influxdb spotless:apply
   ./mvnw -o -pl seatunnel-connectors-v2/connector-influxdb test 
-Dtest=DefaultSerializerTest -DfailIfNoTests=false -Dskip.spotless=true
   ```
   
   ### Compatibility
   
   - No configuration option is added, removed or renamed, and the default 
`epoch` value stays `n`.
   - This is a bug fix for the default configuration: with `epoch=n` (and with 
any other `epoch` value) processing-time and `TIMESTAMP` `key_time` points now 
carry the correct timestamp instead of a 1970 timestamp.
   - `STRING` / `BIGINT` `key_time` semantics are unchanged.
   


-- 
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]

Reply via email to