[英]How to convert a TZ Datetime to Timestamp(3) in Flink SQL
How do you convert a DateTime with the TZ
to Timestamp(3) in Flink SQL v1.13?如何在 Flink SQL v1.13 中将带有
TZ
的 DateTime 转换为 Timestamp(3)?
TO_TIMESTAMP('2021-12-16T20:29:37Z', 'yyyy-MM-dd HH:mm:ss') //returns NULL
TO_TIMESTAMP('2021-12-16 20:29:37', 'yyyy-MM-dd HH:mm:ss') //returns 2021-12-16T20:29:37
TO_TIMESTAMP('2021-12-16T20:29:37', 'yyyy-MM-dd HH:mm:ss') //returns NULL, which is silly because this was the result from the 2nd example
It does not accept the T and Z
, however the conversion result for a "clean" date has the T
.它不接受
T and Z
,但是“干净”日期的转换结果具有T
。 But if I try the reverse operation, it returns null.但是如果我尝试反向操作,它会返回 null。
Flink knows two representations of timestamps in string format: SQL
and ISO-8601
. Flink 知道两种字符串格式的时间戳表示:
SQL
和ISO-8601
。
The SQL one follows 2021-12-16 20:29:37
and is accepted by TO_TIMESTAMP
. SQL 一个跟随
2021-12-16 20:29:37
TO_TIMESTAMP
。 It is also the result of a CAST(ts AS STRING)
.它也是
CAST(ts AS STRING)
的结果。
The ISO-8601 follows 2021-12-16T20:29:37
and might be accepted by future built-in utility functions. ISO-8601 遵循
2021-12-16T20:29:37
并且可能会被未来的内置实用程序函数所接受。
The questions is: How do you "leave the SQL world" by printing?问题是:如何通过打印“离开 SQL 世界”? If you stay in the table ecosystem and call
table.execute().print()
future Flink versions will print the SQL format.如果你留在 table 生态系统中并调用
table.execute().print()
未来的 Flink 版本将打印 SQL 格式。 Also the SQL Client will do this. SQL 客户端也将执行此操作。 At least this will be the behavior in Flink 1.15 and might already be the case in Flink 1.14.
至少这将是 Flink 1.15 中的行为,并且可能已经是 Flink 1.14 中的情况。
If you do table.execute().collect().forEach(println)
you print "via the Java world" which means that java.time.LocalDateTime.toString
is called which uses ISO-8601 format.如果您执行
table.execute().collect().forEach(println)
您打印“通过 Java 世界”,这意味着java.time.LocalDateTime.toString
被调用,它使用 ISO-8601 格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.