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

frank wang commented on FLINK-22525:
------------------------------------

i check the code, maybe we should remove some validate code 

 
{code:java}
//flink code
Instant instant = null;
if (timestampField instanceof java.time.Instant) {
    instant = ((Instant) timestampField);
} else if (timestampField instanceof java.sql.Timestamp) {
    Timestamp timestamp = ((Timestamp) timestampField);
    // conversion between java.sql.Timestamp and TIMESTAMP_WITH_LOCAL_TIME_ZONE
    instant =
            TimestampData.fromEpochMillis(
                            timestamp.getTime(), timestamp.getNanos() % 
1000_000)
                    .toInstant();
} else if (timestampField instanceof TimestampData) {
    instant = ((TimestampData) timestampField).toInstant();
} else if (timestampField instanceof Integer) {
    instant = Instant.ofEpochSecond((Integer) timestampField);
} else if (timestampField instanceof Long) {
    instant = Instant.ofEpochMilli((Long) timestampField);
}
if (instant != null) {
    return timestampToString(
            instant.atZone(sessionTimeZone).toLocalDateTime(),
            getPrecision(fieldType));
} else {
    return timestampField;
}{code}
and i test this code, i found it can print the right time that i need
{code:java}
//test code
Instant instant=Instant.now();
System.out.println(instant.atZone(ZoneId.of("UTC+8")).toLocalDateTime().toString());
{code}
so can we remove some of code as follow
{code:java}
//flink validate time zone code
private void validateTimeZone(String zone) {
    final String zoneId = zone.toUpperCase();
    if (zoneId.startsWith("UTC+")
            || zoneId.startsWith("UTC-")
            || SHORT_IDS.containsKey(zoneId)) {
        throw new IllegalArgumentException(
                String.format(
                        "The supported Zone ID is either a full name such as 
'America/Los_Angeles',"
                                + " or a custom timezone id such as 'GMT-8:00', 
but configured Zone ID is '%s'.",
                        zone));
    }
}
{code}
 

> The zone id in exception message should be GMT+08:00 instead of GMT+8:00
> ------------------------------------------------------------------------
>
>                 Key: FLINK-22525
>                 URL: https://issues.apache.org/jira/browse/FLINK-22525
>             Project: Flink
>          Issue Type: Bug
>          Components: Documentation, Table SQL / API
>    Affects Versions: 1.13.0
>            Reporter: Leonard Xu
>            Priority: Minor
>             Fix For: 1.14.0, 1.13.1
>
>
> {code:java}
> Flink SQL> SET table.local-time-zone=UTC+3;
> Flink SQL> select current_row_timestamp();
> [ERROR] Could not execute SQL statement. Reason:
> java.lang.IllegalArgumentException: The supported Zone ID is either a full 
> name such as 'America/Los_Angeles', or a custom timezone id such as 
> 'GMT-8:00', but configured Zone ID is 'UTC+3'.
> {code}
> The valid zoned should  be 'GMT-08:00'



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to