[
https://issues.apache.org/jira/browse/FLINK-10976?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16718450#comment-16718450
]
ASF GitHub Bot commented on FLINK-10976:
----------------------------------------
hequn8128 commented on a change in pull request #7235: [FLINK-10976] [table]
Add support for aggregate to table API
URL: https://github.com/apache/flink/pull/7235#discussion_r240877583
##########
File path:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/table.scala
##########
@@ -999,6 +999,47 @@ class Table(
new OverWindowedTable(this, overWindows.toArray)
}
+ /**
+ * Performs a global aggregate operation with an aggregate function. Use
this before a selection
+ * to perform the selection operation. The output will be flattened if the
output type is a
+ * composite type.
+ *
+ * Example:
+ *
+ * {{{
+ * val aggFunc: AggregateFunction[_, _] = new MyAggregateFunction
+ * tableEnv.registerFunction("aggFunc", aggFunc);
+ * table.aggregate("aggFunc(a, b) as (f0, f1, f2)").select('f0, 'f1)
+ * }}}
+ */
+ def aggregate(aggregateFunction: Expression): AggregatedTable = {
+ unwrap(aggregateFunction, tableEnv) match {
+ case _: Aggregation =>
+ case _ => throw new ValidationException("Only AggregateFunction can be
used in aggregate.")
+ }
+
+ new AggregatedTable(this, Nil, aggregateFunction)
+ }
+
+ /**
+ * Performs a global aggregate operation with an aggregate function. Use
this before a selection
+ * to perform the selection operation. The output will be flattened if the
output type is a
+ * composite type.
+ *
+ * Example:
+ *
+ * {{{
+ * val aggFunc: AggregateFunction[_, _] = new MyAggregateFunction
+ * tableEnv.registerFunction("aggFunc", aggFunc);
+ * table.aggregate("aggFunc(a, b) as (f0, f1, f2)").select("f0, f1")
+ * }}}
+ */
+ def aggregate(aggregateFunction: String): AggregatedTable = {
+ val withResolvedAggFunctionCall = replaceAggFunctionCall(
Review comment:
Replace with `groupBy().aggregate(aggregateFunction)`
----------------------------------------------------------------
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:
[email protected]
> Add Aggregate operator to Table API
> -----------------------------------
>
> Key: FLINK-10976
> URL: https://issues.apache.org/jira/browse/FLINK-10976
> Project: Flink
> Issue Type: Sub-task
> Components: Table API & SQL
> Reporter: sunjincheng
> Assignee: Dian Fu
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.8.0
>
>
> Add Aggregate operator to Table API as described in [Google
> doc|https://docs.google.com/document/d/1tnpxg31EQz2-MEzSotwFzqatsB4rNLz0I-l_vPa5H4Q/edit#heading=h.q23rny2iglsr].
> The usage:
> {code:java}
> val res = tab
> .groupBy('a) // leave out groupBy-clause to define global aggregates
> .agg(fun: AggregateFunction) // output has columns 'a, 'b, 'c
> .select('a, 'c)
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)