dianfu commented on a change in pull request #7209: [FLINK-10977][table] Add UnBounded FlatAggregate operator to streaming Table API URL: https://github.com/apache/flink/pull/7209#discussion_r240945195
########## File path: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/table.scala ########## @@ -1028,6 +1061,119 @@ class Table( } } +class FlatAggTable( + private[flink] val table: Table, + private[flink] val tableAggCall: TableAggFunctionCall) { + + /** + * Performs a selection operation on a FlatAggTable table. Similar to an SQL SELECT statement. + * The field expressions can contain complex expressions. + * + * __Note__: You have to close the flatAggregate with a select statement. And the select + * statement does not support * and aggregate functions. + * + * Example: + * + * {{{ + * val tableAggFunc: TableAggregateFunction = new MyTableAggregateFunction + * tab.flatAggregate(tableAggFunc('a, 'b)).select(udf('_1), '_2, '_3) + * }}} + */ + def select(fields: Expression*): Table = { + new GroupedFlatAggTable(table, Nil, tableAggCall).select(fields: _*) + } + + /** + * Performs a selection operation on a FlatAggTable table. Similar to an SQL SELECT statement. + * The field expressions can contain complex expressions. + * + * __Note__: You have to close the flatAggregate with a select statement. And the select + * statement does not support * and aggregate functions. + * + * Example: + * + * {{{ + * val tableAggFunc: TableAggregateFunction = new MyTableAggregateFunction + * tableEnv.registerFunction("myTableAggFunc", tableAggFunc); + * tab.flatAggregate("myTableAggFunc(a, b)").select("_1, _2, _3") + * }}} + */ + def select(fields: String): Table = { + new GroupedFlatAggTable(table, Nil, tableAggCall).select(fields) + } +} + +/** + * A table that has been grouped on a set of grouping keys and perform flatAggregate. + */ +class GroupedFlatAggTable( + private[flink] val table: Table, + private[flink] val groupKey: Seq[Expression], + private[flink] val tableAggCall: TableAggFunctionCall) { + + /** + * Performs a selection operation on a GroupedFlatAggTable table. Similar to an SQL SELECT + * statement. The field expressions can contain complex expressions. + * + * __Note__: You have to close the flatAggregate with a select statement. And the select + * statement does not support * and aggregate functions. + * + * Example: + * + * {{{ + * val tableAggFunc: TableAggregateFunction = new MyTableAggregateFunction + * tab.groupBy('key).flatAggregate(tableAggFunc('a, 'b)).select(udf('_1), '_2, '_3) + * }}} + */ + def select(fields: Expression*): Table = { + val expandedFields = expandProjectList(tableAggCall.args, table.logicalPlan, table.tableEnv) + val projectFields = extractFieldReferences(expandedFields ++ groupKey) + + val flatAggTable = new Table(table.tableEnv, + TableAggregate(groupKey, tableAggCall, + Project(projectFields, table.logicalPlan).validate(table.tableEnv) + ).validate(table.tableEnv)) + + // check no '*' in the select of flatAggregate. Review comment: Why * is not supported? I think * should not be supported currently in group window case. Right? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services