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

    https://github.com/apache/flink/pull/2653#discussion_r88346802
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/validate/FunctionCatalog.scala
 ---
    @@ -47,13 +52,50 @@ class FunctionCatalog {
         sqlFunctions += sqlFunction
       }
     
    +  /** Register multiple sql functions at one time. The functions has the 
same name. **/
    +  def registerSqlFunctions(functions: Seq[SqlFunction]): Unit = {
    +    if (functions.nonEmpty) {
    +      sqlFunctions --= sqlFunctions.filter(_.getName == 
functions.head.getName)
    +      sqlFunctions ++= functions
    +    }
    +  }
    +
       def getSqlOperatorTable: SqlOperatorTable =
         ChainedSqlOperatorTable.of(
           new BasicOperatorTable(),
           new ListSqlOperatorTable(sqlFunctions)
         )
     
       /**
    +    * Lookup table function and create an TableFunctionCall if we find a 
match.
    +    */
    +  def lookupTableFunction[T](name: String, children: Seq[Expression]): 
TableFunctionCall[T] = {
    +    val funcClass = functionBuilders
    +      .getOrElse(name.toLowerCase, throw ValidationException(s"Undefined 
function: $name"))
    +    funcClass match {
    +      // user-defined table function call
    +      case tf if classOf[TableFunction[T]].isAssignableFrom(tf) =>
    +        
Try(UserDefinedFunctionUtils.instantiate(tf.asInstanceOf[Class[TableFunction[T]]]))
 match {
    +          case Success(tableFunction) => {
    +            val clazz: Type = tableFunction.getClass.getGenericSuperclass
    +            val generic = clazz match {
    +              case cls: ParameterizedType => 
cls.getActualTypeArguments.toSeq.head
    +              case _ => throw new TableException(
    +                "New TableFunction classes need to inherit from 
TableFunction class," +
    +                  " and statement the generic type.")
    +            }
    +            implicit val typeInfo: TypeInformation[T] = 
TypeExtractor.createTypeInfo(generic)
    +              .asInstanceOf[TypeInformation[T]]
    +            TableFunctionCall(tableFunction, children, None)
    +          }
    +          case Failure(e) => throw ValidationException(e.getMessage)
    +        }
    +      case _ =>
    +        throw ValidationException("Unsupported table function.")
    --- End diff --
    
    I think this exception message could be improved. It is throw if the 
registered method does not implement the `TableFunction` interface.


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