Interface GroupedTable


@PublicEvolving public interface GroupedTable
A table that has been grouped on a set of grouping keys.
  • Method Summary

    Modifier and Type
    Method
    Description
    aggregate(org.apache.flink.table.expressions.Expression aggregateFunction)
    Performs an aggregate operation with an aggregate function.
    flatAggregate(org.apache.flink.table.expressions.Expression tableAggFunction)
    Performs a flatAggregate operation on a grouped table.
    select(org.apache.flink.table.expressions.Expression... fields)
    Performs a selection operation on a grouped table.
  • Method Details

    • select

      Table select(org.apache.flink.table.expressions.Expression... fields)
      Performs a selection operation on a grouped table. Similar to an SQL SELECT statement. The field expressions can contain complex expressions and aggregations.

      Example:

      
       tab.groupBy($("key")).select($("key"), $("value").avg().plus(" The average").as("average"));
       

      Scala Example:

      
       tab.groupBy($"key").select($"key", $"value".avg + " The average" as "average")
       
    • aggregate

      AggregatedTable aggregate(org.apache.flink.table.expressions.Expression aggregateFunction)
      Performs an aggregate operation with an aggregate function. You have to close the aggregate(Expression) with a select statement. The output will be flattened if the output type is a composite type.

      Example:

      
       tableEnv.createTemporarySystemFunction("aggFunc", MyAggregateFunction.class);
       tab.groupBy($("key"))
         .aggregate(call("aggFunc", $("a"), $("b")).as("f0", "f1", "f2"))
         .select($("key"), $("f0"), $("f1"));
       

      Scala Example:

      
       val aggFunc = new MyAggregateFunction
       table.groupBy($"key")
         .aggregate(aggFunc($"a", $"b") as ("f0", "f1", "f2"))
         .select($"key", $"f0", $"f1")
       
    • flatAggregate

      FlatAggregateTable flatAggregate(org.apache.flink.table.expressions.Expression tableAggFunction)
      Performs a flatAggregate operation on a grouped table. FlatAggregate takes a TableAggregateFunction which returns multiple rows. Use a selection after flatAggregate.

      Example:

      
       tableEnv.createTemporarySystemFunction("tableAggFunc", MyTableAggregateFunction.class);
       tab.groupBy($("key"))
         .flatAggregate(call("tableAggFunc", $("a"), $("b")).as("x", "y", "z"))
         .select($("key"), $("x"), $("y"), $("z"));
       

      Scala Example:

      
       val tableAggFunc: TableAggregateFunction = new MyTableAggregateFunction
       tab.groupBy($"key")
         .flatAggregate(tableAggFunc($"a", $"b") as ("x", "y", "z"))
         .select($"key", $"x", $"y", $"z")