You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Yao Zhang (Jira)" <ji...@apache.org> on 2022/07/04 07:15:00 UTC

[jira] [Commented] (FLINK-28365) TO_TIMESTAMP lose precision beyond seconds

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

Yao Zhang commented on FLINK-28365:
-----------------------------------

Hi [~qingwei91] ,

Which version of Flink did you use? I tested it with Flink 1.14.3 and the result was cast to Timestamp(3).

The generated execution plan is as below:
{code:java}
== Abstract Syntax Tree ==
LogicalProject(EXPR$0=[TO_TIMESTAMP(_UTF-16LE'2020-01-01 15:35:00.123456', _UTF-16LE'yyyy-MM-dd HH:mm:ss.SSSSSS')])
+- LogicalValues(tuples=[[{ 0 }]])

== Optimized Physical Plan ==
Calc(select=[CAST(2020-01-01 15:35:00.123:TIMESTAMP(3)) AS EXPR$0])
+- Values(type=[RecordType(INTEGER ZERO)], tuples=[[{ 0 }]])

== Optimized Execution Plan ==
Calc(select=[CAST(2020-01-01 15:35:00.123:TIMESTAMP(3)) AS EXPR$0])
+- Values(tuples=[[{ 0 }]]) {code}
We can see a cast to Timestamp(3) was added.

Also we can find some clues in flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/FlinkSqlOperatorTable.java:
{code:java}
// TODO: the return type of TO_TIMESTAMP should be TIMESTAMP(9),
//  but we keep TIMESTAMP(3) now because we did not support TIMESTAMP(9) as time attribute.
//  See: https://issues.apache.org/jira/browse/FLINK-14925
public static final SqlFunction TO_TIMESTAMP =
        new SqlFunction(
                "TO_TIMESTAMP",
                SqlKind.OTHER_FUNCTION,
                ReturnTypes.cascade(
                        ReturnTypes.explicit(SqlTypeName.TIMESTAMP, 3),
                        SqlTypeTransforms.FORCE_NULLABLE),
                null,
                OperandTypes.or(
                        OperandTypes.family(SqlTypeFamily.CHARACTER),
                        OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)),
                SqlFunctionCategory.TIMEDATE); {code}
The return type of TO_TIMESTAMP function is always TIMESTAMP(3).

> TO_TIMESTAMP lose precision beyond seconds
> ------------------------------------------
>
>                 Key: FLINK-28365
>                 URL: https://issues.apache.org/jira/browse/FLINK-28365
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>    Affects Versions: 1.16.0, 1.15
>            Reporter: Lim Qing Wei
>            Priority: Major
>             Fix For: 1.16.0, 1.15
>
>
> The TO_TIMESTAMP function in Flink SQL seems to have a regression.
>  
> It loses the precision after seconds, for example
>  
> {code:java}
> TO_TIMESTAMP('2020-01-01 15:35:00.123456'){code}
> returns 2020-01-01 15:35:00.123 in the resulting SQL AST, note that the last 3 digit are missing.
>  
> I think this started in 1.15.x, because I have code in 1.14 that preserve the precision as I expect.
>  
> Do you agree this is a bug?
> PS: The documentation isn't very comprehensive: [https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/functions/systemfunctions/]
>  
> I've added a few assertions to illustrate the issue: [https://github.com/apache/flink/pull/20139]
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)