当前位置:   article > 正文

org.apache.flink.table.api.ValidationException: Expected LocalReferenceExpression. Got: timestamp_expected localreferenceexpression. got: duration

expected localreferenceexpression. got: duration

在这里插入图片描述
情景:在设置滑动窗口时遇到的问题:Expected LocalReferenceExpression. Got: timestamp,详细代码如下:

Table table = tableEnv.fromDataStream(stream);
table
.window(Slide.over(lit(1).hours()).every(lit(5).minutes()).on(($("timestamp").rowtime()).as("ts")).as("w"))
.groupBy($("w"), $("itemId"))
.select($("itemId"), $("itemId").count().as("itemCount"), $("w").end().as("windowEnd"))
.window(Over.partitionBy($("windowEnd")).orderBy($("itemCount").desc()).as("row_num"))
.select($("itemId"), $("itemCount"), $("windowEnd"))
.where($("row_num").between(0, 3));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

原因是:需要在定义表设置事件时间,在表API中不能设置事件时间。
原来代码修改为:

Table table = tableEnv.fromDataStream(stream,$("itemId"),$("timestamp").rowtime().as("ts"));
Table tableResult =
       table
       .window(Slide.over(lit(1).hours())
               .every(lit(5).minutes())
               .on($("ts"))
               .as("w"))
       .groupBy($("w"), $("itemId"))
       .select($("itemId"), $("itemId").count().as("itemCount"), $("w").end().as("windowEnd"))
       .window(Over.partitionBy($("windowEnd"))
               .orderBy($("itemCount").desc())
               .as("rank"))
       .select($("itemId"), $("itemCount"), $("windowEnd"))
       .where($("row_num").between(0, 3));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/795342
推荐阅读
相关标签
  

闽ICP备14008679号