代码之家  ›  专栏  ›  技术社区  ›  Soheil Pourbafrani

基于数据类型字段的Flink表过滤

  •  0
  • Soheil Pourbafrani  · 技术社区  · 7 年前

    我创建了一个表,其中有一个日期类型的字段,即 飞行日期 . 我所需的查询筛选表行的一部分基于 飞行日期 字段。所以我做了如下工作:

    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
    

    我甚至删除了一个quation并尝试:

    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
    

    最后,我创建一个日期对象并尝试:

    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将日期识别为字符串或整数。我怎样才能用正确的格式给出日期!?

    0 回复  |  直到 7 年前
        1
  •  0
  •   Soheil Pourbafrani    7 年前

    我应该改邪归正 字符串 日期 使用 toDate 方法。

    filter("f_date <= '1998-10-02'.toDate")
    
    推荐文章