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

    https://github.com/apache/flink/pull/2653#discussion_r88484285
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/functions/utils/UserDefinedFunctionUtils.scala
 ---
    @@ -162,24 +191,107 @@ object UserDefinedFunctionUtils {
       }
     
       /**
    +    * Internal method of [[ScalarFunction#getResultType()]] that does some 
pre-checking and uses
    +    * [[TypeExtractor]] as default return type inference.
    +    */
    +  def getResultType(
    +    tableFunction: TableFunction[_],
    +    signature: Array[Class[_]])
    +  : TypeInformation[_] = {
    +    // find method for signature
    +    val evalMethod = tableFunction.getEvalMethods
    +      .find(m => signature.sameElements(m.getParameterTypes))
    +      .getOrElse(throw new ValidationException("Given signature is 
invalid."))
    +
    +    val userDefinedTypeInfo = tableFunction.getResultType
    +    if (userDefinedTypeInfo != null) {
    +      userDefinedTypeInfo
    +    } else {
    +      try {
    +        TypeExtractor.getForClass(evalMethod.getReturnType)
    +      } catch {
    +        case ite: InvalidTypesException =>
    +          throw new ValidationException(
    +            s"Return type of table function '$this' cannot be " +
    +              s"automatically determined. Please provide type information 
manually.")
    +      }
    +    }
    +  }
    +
    +  /**
         * Returns the return type of the evaluation method matching the given 
signature.
         */
       def getResultTypeClass(
    -      scalarFunction: ScalarFunction,
    +      function: EvaluableFunction,
           signature: Array[Class[_]])
         : Class[_] = {
         // find method for signature
    -    val evalMethod = scalarFunction.getEvalMethods
    +    val evalMethod = function.getEvalMethods
           .find(m => signature.sameElements(m.getParameterTypes))
           .getOrElse(throw new IllegalArgumentException("Given signature is 
invalid."))
         evalMethod.getReturnType
       }
     
       /**
    -    * Prints all signatures of a [[ScalarFunction]].
    +    * Prints all signatures of a [[EvaluableFunction]].
         */
    -  def signaturesToString(scalarFunction: ScalarFunction): String = {
    -    scalarFunction.getSignatures.map(signatureToString).mkString(", ")
    +  def signaturesToString(function: EvaluableFunction): String = {
    +    function.getSignatures.map(signatureToString).mkString(", ")
       }
     
    +  /**
    +    * Returns field names and field positions for a given 
[[TypeInformation]].
    +    *
    +    * Field names are automatically extracted for
    +    * [[org.apache.flink.api.common.typeutils.CompositeType]].
    +    *
    +    * @param inputType The TypeInformation extract the field names and 
positions from.
    +    * @return A tuple of two arrays holding the field names and 
corresponding field positions.
    +    */
    +  def getFieldInfo(inputType: TypeInformation[_])
    +  : (Array[String], Array[Int]) = {
    +    val fieldNames: Array[String] = inputType match {
    +      case t: TupleTypeInfo[_] => t.getFieldNames
    +      case c: CaseClassTypeInfo[_] => c.getFieldNames
    +      case p: PojoTypeInfo[_] => p.getFieldNames
    +      case a: AtomicType[_] => Array("f0")
    +      case tpe =>
    +        throw new TableException(s"Type $tpe lacks explicit field naming")
    +    }
    +    val fieldIndexes = fieldNames.indices.toArray
    +    (fieldNames, fieldIndexes)
    +  }
    +
    +  /**
    +    * Returns field names and field types for a given [[TypeInformation]].
    +    *
    +    * Field names are automatically extracted for
    +    * [[org.apache.flink.api.common.typeutils.CompositeType]].
    +    *
    +    * @param inputType The TypeInformation extract the field names and 
types from.
    +    * @tparam A The type of the TypeInformation.
    +    * @return A tuple of two arrays holding the field names and 
corresponding field types.
    +    */
    +  def getFieldAttribute[A](inputType: TypeInformation[A])
    --- End diff --
    
    Maybe merge this method and the method above?


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

Reply via email to