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 #4536: [FLINK-7439] [table] Support variable arguments fo...
Date Mon, 28 Aug 2017 00:48:43 GMT
Github user sunjincheng121 commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4536#discussion_r135425816
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/utils/TableSqlFunction.scala
---
    @@ -74,48 +75,102 @@ class TableSqlFunction(
     
     object TableSqlFunction {
     
    -  /**
    -    * Util function to create a [[TableSqlFunction]].
    -    *
    -    * @param name function name (used by SQL parser)
    -    * @param udtf user-defined table function to be called
    -    * @param rowTypeInfo the row type information generated by the table function
    -    * @param typeFactory type factory for converting Flink's between Calcite's types
    -    * @param functionImpl Calcite table function schema
    -    * @return [[TableSqlFunction]]
    -    */
    -  def apply(
    +  private[flink] def createOperandTypeInference(
         name: String,
         udtf: TableFunction[_],
    -    rowTypeInfo: TypeInformation[_],
    -    typeFactory: FlinkTypeFactory,
    -    functionImpl: FlinkTableFunctionImpl[_]): TableSqlFunction = {
    -
    -    val argTypes: util.List[RelDataType] = new util.ArrayList[RelDataType]
    -    val typeFamilies: util.List[SqlTypeFamily] = new util.ArrayList[SqlTypeFamily]
    -    // derives operands' data types and type families
    -    functionImpl.getParameters.asScala.foreach{ o =>
    -      val relType: RelDataType = o.getType(typeFactory)
    -      argTypes.add(relType)
    -      typeFamilies.add(Util.first(relType.getSqlTypeName.getFamily, SqlTypeFamily.ANY))
    +    typeFactory: FlinkTypeFactory)
    +  : SqlOperandTypeInference = {
    +    /**
    +      * Operand type inference based on [[TableFunction]] given information.
    +      */
    +    new SqlOperandTypeInference {
    +      override def inferOperandTypes(
    +          callBinding: SqlCallBinding,
    +          returnType: RelDataType,
    +          operandTypes: Array[RelDataType]): Unit = {
    +
    +        val operandTypeInfo = getOperandTypeInfo(callBinding)
    +
    +        val foundSignature = getEvalMethodSignature(udtf, operandTypeInfo)
    +          .getOrElse(throw new ValidationException(
    +            s"Given parameters of function '$name' do not match any signature. \n" +
    +              s"Actual: ${signatureToString(operandTypeInfo)} \n" +
    +              s"Expected: ${signaturesToString(udtf, "eval")}"))
    +
    +        val inferredTypes = foundSignature
    +          .map(TypeExtractor.getForClass(_))
    +          .map(typeFactory.createTypeFromTypeInfo(_, isNullable = true))
    +
    +        for (i <- operandTypes.indices) {
    +          if (i < inferredTypes.length - 1) {
    +            operandTypes(i) = inferredTypes(i)
    +          } else if (null != inferredTypes.last.getComponentType) {
    +            // last argument is a collection, the array type
    +            operandTypes(i) = inferredTypes.last.getComponentType
    +          } else {
    +            operandTypes(i) = inferredTypes.last
    +          }
    +        }
    +      }
         }
    -    // derives whether the 'input'th parameter of a method is optional.
    -    val optional: Predicate[Integer] = new Predicate[Integer]() {
    -      def apply(input: Integer): Boolean = {
    -        functionImpl.getParameters.get(input).isOptional
    +  }
    +
    +  private[flink] def createOperandTypeChecker(
    --- End diff --
    
    Can we share the methods of  `SqlOperandTypeInference` and `createOperandTypeChecker`
with `ScalarSqlFunction``TableSqlFunction` and `AggSqlFunction`, Because all of the UDX need
them, and the logic of these method are  same or similar.  May be we can move them into `UserDefinedFunctionUtils`.
What do 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message