Github user sunjincheng121 commented on a diff in the pull request:
https://github.com/apache/flink/pull/4105#discussion_r121346261
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/aggregate/AggregateUtil.scala
---
@@ -1395,50 +1399,25 @@ object AggregateUtil {
case udagg: AggSqlFunction =>
aggregates(index) = udagg.getFunction
+ accTypes(index) = udagg.accType
case unSupported: SqlAggFunction =>
throw new TableException(s"unsupported Function:
'${unSupported.getName}'")
}
}
- (aggFieldIndexes, aggregates)
- }
-
- private def createAccumulatorType(
- aggregates: Array[TableAggregateFunction[_, _]]):
Seq[TypeInformation[_]] = {
-
- val aggTypes: Seq[TypeInformation[_]] =
- aggregates.map {
- agg =>
- val accType = try {
- val method: Method =
agg.getClass.getMethod("getAccumulatorType")
- method.invoke(agg).asInstanceOf[TypeInformation[_]]
- } catch {
- case _: NoSuchMethodException => null
- case ite: Throwable => throw new TableException("Unexpected
exception:", ite)
- }
- if (accType != null) {
- accType
- } else {
- val accumulator = agg.createAccumulator()
- try {
- TypeInformation.of(accumulator.getClass)
- } catch {
- case ite: InvalidTypesException =>
- throw new TableException(
- "Cannot infer type of accumulator. " +
- "You can override
AggregateFunction.getAccumulatorType() to specify the type.",
- ite)
- }
- }
- }
+ // create accumulator type information for every aggregate function
+ aggregates.zipWithIndex.foreach { case (agg, index) =>
+ accTypes(index) = getAccumulatorTypeOfAggregateFunction(agg,
accTypes(index))
--- End diff --
If i understand correctly. only build-in AGG need call
`getAccumulatorTypeOfAggregateFunction`.
and all the UDAGG do not need call this method. is that correct? If so, I
think if only `null==accTypes(index)` need call this method. Please explain
more If I understand incorrectly. thanks!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---