如何将带窗口的GroupBy聚合表转换为DataStream

时间:2019-11-30 04:03:42

标签: apache-flink flink-streaming flink-sql

使用不加入Join的Window / GroupBy / Aggregate

        final Table idTable = (tableEnv
                .scan("ids")
                .select("id, created_at"))
                .window(Session.withGap("2000.milli").on("created_at").as("w"))
                .groupBy("w, id")
                .aggregate("id.count as count")
                .select("id, count");
        tableEnv.toRetractStream(idTable, Row.class).print();

->有效

通过窗口使用Join

        final Table idTable = (tableEnv
                .scan("ids")
                .select("id, created_at"))
                .leftOuterJoin(peopleTable.select("id as people_id, name as people_name"),"id = people_name")
                .select("id, people_name");

->这也可以

但是当我尝试同时使用两者时:

        final Table idTable = (tableEnv
                .scan("ids")
                .select("id, created_at"))
                .leftOuterJoin(termTable.select("id as term_id, name as term_name"),"id = term_id")
                .window(Session.withGap("2000.milli").on("created_at").as("w"))
                .groupBy("w, id")
                .select("id");
        tableEnv.toRetractStream(idTable, Row.class).print();

错误:

Exception in thread "main" org.apache.flink.table.api.TableException: Group Window Agg: Retraction on windowed GroupBy aggregation is not supported yet. 
please re-check sql grammar. 
Note: Windowed GroupBy aggregation should not follow anon-windowed GroupBy aggregation.
    at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecGroupWindowAggregate.translateToPlanInternal(StreamExecGroupWindowAggregate.scala:149)
    at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecGroupWindowAggregate.translateToPlanInternal(StreamExecGroupWindowAggregate.scala:55)
    at org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:54)
    at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecGroupWindowAggregate.translateToPlan(StreamExecGroupWindowAggregate.scala:55)
    at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToTransformation(StreamExecSink.scala:185)

还有其他解决方法吗?

0 个答案:

没有答案