【问题标题】:Filtering Flink Table based on field of type Date根据 Date 类型的字段过滤 Flink Table
【发布时间】:2019-02-24 15:44:31
【问题描述】:

我创建了一个表,其中有一个日期类型的字段,即 f_date。我想要的查询的一部分基于 f_date 字段过滤表行。所以我做了以下事情:

mytable.filter("f_date <= '1998-10-02'")

mytable.filter("f_date <= '1998/10/02'")

然后我在所有两种情况下都得到了以下相同的错误:

Expression 'f_date <= 1998/10/02 failed on input check: Comparison is only supported for numeric types and comparable types of the same type, got Date and String

我什至删除了单引号并尝试了:

mytable.filter("f_date <= 1998/10/02")

我得到了错误:

Expression 'f_date <= ((1998 / 10) / 2) failed on input check: Comparison is only supported for numeric types and comparable types of same type, got Date and Integer

最后我创建了一个 Date 对象并尝试:

mytable.filter("f_date <=" + Java.sql.Date.valueOf("1998-10-22"))

我得到了错误:

Expression 'f_date <= ((1998 - 10) - 2) failed on input check: Comparison is only supported for numeric types and comparable types of the same type, got Date and Integer

在上述情况下,Flink 将日期识别为 String 或 Integer。我怎样才能以正确的格式给出日期!?

【问题讨论】:

    标签: apache-flink flink-sql


    【解决方案1】:

    我应该使用 toDate 方法将 String 转换为 Date

    filter("f_date <= '1998-10-02'.toDate")
    

    【讨论】:

      猜你喜欢
      • 2019-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      相关资源
      最近更新 更多