[ 
https://issues.apache.org/jira/browse/FLINK-27018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17520966#comment-17520966
 ] 

Yao Zhang commented on FLINK-27018:
-----------------------------------

Hi all,

The root cause is the different behaviour of converting LocalDateTime to string 
literal.

 
{code:java}
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
        .appendPattern("HH:mm:ss")
        .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)
        .toFormatter();
dateTimeFormatter.format(localDataTime){code}
The code above will erase the trailing zeros for nano second part. For example 
"2022-04-02 03:34:21.260" will be converted to "2022-04-02 03:34:21.26" and 
"2022-04-02 03:34:21.200" will be converted to "2022-04-02 03:34:21.2". Both 
CSV and JSON format take use of this converter.

 

However, the comment of `LocalTime.toString()` says it will convert to string 
literal. The precision of fraction can only be 0, 3, 6 or 9.
{code:java}
/**
 * Outputs this time as a {@code String}, such as {@code 10:15}.
 * <p>
 * The output will be one of the following ISO-8601 formats:
 * <ul>
 * <li>{@code HH:mm}</li>
 * <li>{@code HH:mm:ss}</li>
 * <li>{@code HH:mm:ss.SSS}</li>
 * <li>{@code HH:mm:ss.SSSSSS}</li>
 * <li>{@code HH:mm:ss.SSSSSSSSS}</li>
 * </ul>
 * The format used will be the shortest that outputs the full value of
 * the time where the omitted parts are implied to be zero.
 *
 * @return a string representation of this time, not null
 */ {code}
Those two ways of converting LocalDateTime to string literal are quite 
different.

Thus, there are 2 questions we might need to discuss:
 * Should we make it consistent in converting LocalDateTime? I think we should.
 * It seems that it is difficult to build a DateTimeFormatter with the exactly 
same behavior as `LocalTime.toString`. We might need another way.

 

 

> timestamp missing end  zero when outputing to kafka
> ---------------------------------------------------
>
>                 Key: FLINK-27018
>                 URL: https://issues.apache.org/jira/browse/FLINK-27018
>             Project: Flink
>          Issue Type: Bug
>          Components: Connectors / Kafka
>    Affects Versions: 1.13.5
>            Reporter: jeff-zou
>            Priority: Major
>         Attachments: kafka.png
>
>
> the bug is described as follows:
>  
> {code:java}
> data in source:
>  2022-04-02 03:34:21.260
> but after sink by sql, data in kafka:
>  2022-04-02 03:34:21.26
> {code}
>  
> data miss end zero in kafka.
>  
> sql:
> {code:java}
> create kafka_table(stime stimestamp) with ('connector'='kafka','format' = 
> 'json');
> insert into kafka_table select stime from (values(timestamp '2022-04-02 
> 03:34:21.260')){code}
> the value in kafka is : \{"stime":"2022-04-02 03:34:21.26"}, missed end zero.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to