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

    https://github.com/apache/flink/pull/4105#discussion_r121321436
  
    --- 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[_, _],
    --- End diff --
    
    Can we abstract a method according ` getAccumulatorTypeOfAggregateFunction` 
and `getResultTypeOfAggregateFunction`. just like follows:
    
    ```
    def getTypeByMethodOrTypeExtractor(
          aggregateFunction: AggregateFunction[_, _],
          clazz: Class[_],
          methodName: String,
          candidateType: TypeInformation[_] = null): TypeInformation[_] = {
    
        val resultType = try {
          val method: Method = aggregateFunction.getClass.getMethod(methodName)
          method.invoke(aggregateFunction).asInstanceOf[TypeInformation[_]]
        } catch {
          case _: NoSuchMethodException => null
          case ite: Throwable => throw new TableException("Unexpected 
exception:", ite)
        }
    
        if (resultType != null) {
          resultType
        } else if(candidateType != null) {
          candidateType
        } else {
          try {
            TypeExtractor.createTypeInfo(clazz).asInstanceOf[TypeInformation[_]]
          } catch {
            case ite: InvalidTypesException =>
              throw new TableException(
                s"Cannot infer type of $clazz" +
                s"You can override AggregateFunction.$methodName to specify the 
type.", ite)
          }
        }
      }
    ```
    I'm not sure whether it is the best way, Please let me know what you think?


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