[
https://issues.apache.org/jira/browse/FLINK-5906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15994793#comment-15994793
]
ASF GitHub Bot commented on FLINK-5906:
---------------------------------------
Github user fhueske commented on a diff in the pull request:
https://github.com/apache/flink/pull/3809#discussion_r114505152
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/aggregations.scala
---
@@ -130,3 +142,63 @@ case class Avg(child: Expression) extends Aggregation {
new SqlAvgAggFunction(AVG)
}
}
+
+case class UDAGGFunctionCall(
+ aggregateFunction: AggregateFunction[_, _],
+ args: Seq[Expression])
+ extends Aggregation {
+
+ override private[flink] def children: Seq[Expression] = args
+
+ // Override makeCopy method in TreeNode, to produce vargars properly
+ override def makeCopy(args: Array[AnyRef]): this.type = {
+ if (args.length < 1) {
+ throw new TableException("Invalid constructor params")
+ }
+ val agg = args.head.asInstanceOf[AggregateFunction[_, _]]
+ val arg = args.last.asInstanceOf[Seq[Expression]]
+ new UDAGGFunctionCall(agg, arg).asInstanceOf[this.type]
+ }
+
+ override def resultType: TypeInformation[_] =
TypeExtractor.createTypeInfo(
+ aggregateFunction, classOf[AggregateFunction[_, _]],
aggregateFunction.getClass, 0)
+
+ override def validateInput(): ValidationResult = {
+ val signature = children.map(_.resultType)
+ // look for a signature that matches the input types
+ val foundSignature = getAccumulateMethodSignature(aggregateFunction,
signature)
+ if (foundSignature.isEmpty) {
+ ValidationFailure(s"Given parameters do not match any signature. \n"
+
+ s"Actual: ${signatureToString(signature)} \n" +
+ s"Expected:
${signaturesToString(aggregateFunction, "accumulate")}")
+ } else {
+ ValidationSuccess
+ }
+ }
+
+ override def toString(): String =
s"${aggregateFunction.getClass.getSimpleName}($args)"
+
+ override def toAggCall(name: String)(implicit relBuilder: RelBuilder):
AggCall = {
+ val typeFactory =
relBuilder.getTypeFactory.asInstanceOf[FlinkTypeFactory]
+ val sqlFunction = AggSqlFunction(name, aggregateFunction, resultType,
typeFactory)
+ relBuilder.aggregateCall(sqlFunction, false, null, name,
args.map(_.toRexNode): _*)
+ }
+
+ override private[flink] def getSqlAggFunction()(implicit relBuilder:
RelBuilder) = {
+ val typeFactory =
relBuilder.getTypeFactory.asInstanceOf[FlinkTypeFactory]
+ AggSqlFunction("UDAGG", // tableAPI parser does not really use this
+ aggregateFunction,
+ resultType,
+ typeFactory)
+ }
+
+ override private[flink] def toRexNode(implicit relBuilder: RelBuilder):
RexNode = {
+ val typeFactory =
relBuilder.getTypeFactory.asInstanceOf[FlinkTypeFactory]
+ relBuilder.call(
+ AggSqlFunction("UDAGG", // tableAPI parser does not really use this
--- End diff --
Call `getSqlAggFunction` here?
> Add support to register UDAGG in Table and SQL API
> --------------------------------------------------
>
> Key: FLINK-5906
> URL: https://issues.apache.org/jira/browse/FLINK-5906
> Project: Flink
> Issue Type: Sub-task
> Components: Table API & SQL
> Reporter: Fabian Hueske
> Assignee: Shaoxuan Wang
>
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)