Github user wuchong commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4105#discussion_r121625889
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/utils/UserDefinedFunctionUtils.scala
 ---
    @@ -329,6 +337,41 @@ object UserDefinedFunctionUtils {
         }
       }
     
    +
    +  /**
    +    * Internal method of AggregateFunction#getAccumulatorType() that does 
some pre-checking
    +    * and uses [[TypeExtractor]] as default return type inference.
    +    */
    +  def getAccumulatorTypeOfAggregateFunction(
    +    aggregateFunction: AggregateFunction[_, _],
    +    extractedType: TypeInformation[_] = null)
    +  : TypeInformation[_] = {
    +
    +    val accType = try {
    +      val method: Method = 
aggregateFunction.getClass.getMethod("getAccumulatorType")
    +      method.invoke(aggregateFunction).asInstanceOf[TypeInformation[_]]
    +    } catch {
    +      case _: NoSuchMethodException => null
    +      case ite: Throwable => throw new TableException("Unexpected 
exception:", ite)
    +    }
    +    if (accType != null) {
    +      accType
    +    } else if (extractedType != null) {
    +      extractedType
    +    } else {
    +      val accumulator = aggregateFunction.createAccumulator()
    +      try {
    +        TypeInformation.of(accumulator.getClass)
    --- End diff --
    
    I think it's a good advice.


---
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.
---

Reply via email to