flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sunjincheng121 <...@git.apache.org>
Subject [GitHub] flink pull request #4379: [FLINK-7194] [table] Add methods for type hints to...
Date Fri, 21 Jul 2017 00:40:56 GMT
Github user sunjincheng121 commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4379#discussion_r128662028
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/utils/UserDefinedFunctionUtils.scala
---
    @@ -314,7 +314,28 @@ object UserDefinedFunctionUtils {
           aggregateFunction: AggregateFunction[_, _],
           extractedType: TypeInformation[_] = null)
         : TypeInformation[_] = {
    -    getParameterTypeOfAggregateFunction(aggregateFunction, "getResultType", 0, extractedType)
    +
    +    val resultType = aggregateFunction.getResultType
    +    if (resultType != null) {
    +      resultType
    +    } else if (extractedType != null) {
    +      extractedType
    +    } else {
    +      try {
    +        TypeExtractor
    +          .createTypeInfo(aggregateFunction,
    +            classOf[AggregateFunction[_, _]],
    +            aggregateFunction.getClass,
    +            0)
    +          .asInstanceOf[TypeInformation[_]]
    +      } catch {
    +        case ite: InvalidTypesException =>
    +          throw new TableException(
    +            s"Cannot infer generic type of ${aggregateFunction.getClass}. " +
    +              s"You can override AggregateFunction.getResultType() to specify the type.",
    +            ite)
    +      }
    +    }
    --- End diff --
    
    Just  a suggestion(I am not sure the suggestion is better or not):
    Extract common code for `getResultTypeOfAggregateFunction` and `getAccumulatorTypeOfAggregateFunction`.
Something like following:
    ![image](https://user-images.githubusercontent.com/22488084/28444428-c85f8dc2-6def-11e7-996e-de80a728a6ce.png)



---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message