You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by fhueske <gi...@git.apache.org> on 2017/04/05 16:50:22 UTC

[GitHub] flink pull request #3623: [FLINK-6196] [table] Support dynamic schema in Tab...

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

    https://github.com/apache/flink/pull/3623#discussion_r109939331
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/utils/UserDefinedFunctionUtils.scala ---
    @@ -358,4 +366,120 @@ object UserDefinedFunctionUtils {
         InstantiationUtil
           .deserializeObject[UserDefinedFunction](byteData, Thread.currentThread.getContextClassLoader)
       }
    +
    +  /**
    +    * Build a TableFunctionCall, a name and a sequence of params will determine a unique
    +    * [[TableFunctionCall]]
    +    *
    +    * @param name function name
    +    * @param implicitResultType If no result type returned, it will use this type.
    +    * @param params The input expressions
    +    * @return A unique [[TableFunctionCall]]
    +    */
    +  private[table] def buildTableFunctionCall(
    +      name: String,
    +      tableFunction: TableFunction[_],
    +      implicitResultType: TypeInformation[_],
    +      params: Expression*): TableFunctionCall = {
    +    val arguments = transformLiteralExpressions(params: _*)
    +    val userDefinedResultType = tableFunction.getResultType(arguments)
    +    val resultType = {
    +      if (userDefinedResultType != null) userDefinedResultType
    +      else implicitResultType
    +    }
    +    TableFunctionCall(name, tableFunction, params, resultType)
    +  }
    +
    +  /**
    +    * Transform the expressions to Objects
    +    * Only literal expressions will be transformed, non-literal expressions will be
    +    * translated to nulls.
    +    *
    +    * @param params actual parameters of the function
    +    * @return A java List of the Objects
    +    */
    +  private[table] def transformLiteralExpressions(params: Expression*): java.util.List[AnyRef] = {
    +    params.map {
    +      case exp: Literal =>
    +        exp.value.asInstanceOf[AnyRef]
    +      case _ =>
    +        null
    +    }
    +  }
    +
    +  /**
    +    * Transform the rex nodes to Objects
    +    * Only literal rex nodes will be transformed, non-literal rex nodes will be
    +    * translated to nulls.
    +    *
    +    * @param rexNodes actual parameters of the function
    +    * @return A java List of the Objects
    +    */
    +  private[table] def transformRexNodes(
    +      rexNodes: java.util.List[RexNode]): java.util.List[AnyRef] = {
    +    rexNodes.map {
    +      case rexNode: RexLiteral =>
    +        val value = rexNode.getValue2
    +        rexNode.getType.getSqlTypeName match {
    +          case SqlTypeName.INTEGER =>
    +            value.asInstanceOf[Long].toInt.asInstanceOf[AnyRef]
    +          case SqlTypeName.SMALLINT =>
    +            value.asInstanceOf[Long].toShort.asInstanceOf[AnyRef]
    +          case SqlTypeName.TINYINT =>
    +            value.asInstanceOf[Long].toByte.asInstanceOf[AnyRef]
    +          case SqlTypeName.FLOAT =>
    +            value.asInstanceOf[Double].toFloat.asInstanceOf[AnyRef]
    +          case SqlTypeName.REAL =>
    +            value.asInstanceOf[Double].toFloat.asInstanceOf[AnyRef]
    +          case _ =>
    +            value.asInstanceOf[AnyRef]
    +        }
    +      case _ =>
    +        null
    +    }
    +  }
    +
    +  private [table] def buildRelDataType(
    --- End diff --
    
    -space: `private[table]`


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