flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clarkyzl <...@git.apache.org>
Subject [GitHub] flink pull request #3623: [FLINK-6196] [table] Support dynamic schema in Tab...
Date Tue, 02 May 2017 01:50:11 GMT
Github user clarkyzl commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3623#discussion_r114236223
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/schema/DeferredTypeFlinkTableFunction.scala
---
    @@ -0,0 +1,68 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.table.plan.schema
    +
    +import java.lang.reflect.Method
    +import java.util
    +
    +import org.apache.calcite.rel.`type`.{RelDataType, RelDataTypeFactory}
    +import org.apache.flink.api.common.typeinfo.TypeInformation
    +import org.apache.flink.table.functions.utils.UserDefinedFunctionUtils
    +import org.apache.flink.table.functions.{TableFunction => FlinkUDTF}
    +
    +import scala.collection.JavaConversions._
    +
    +/**
    +  * A Deferred Type is a Table Function which the result type hasn't been determined
yet.
    +  * It will determine the result type after the arguments are passed.
    +  *
    +  * @param tableFunction The Table Function instance
    +  * @param evalMethod The eval() method of the [[tableFunction]]
    +  * @param implicitResultType Implicit result type.
    +  */
    +class DeferredTypeFlinkTableFunction(
    +    val tableFunction: FlinkUDTF[_],
    +    val evalMethod: Method,
    +    val implicitResultType: TypeInformation[_])
    +  extends FlinkTableFunction(tableFunction, evalMethod) {
    +
    +  val paramTypeInfos = evalMethod.getParameterTypes.toList
    +
    +  override def getResultType(arguments: util.List[AnyRef]): TypeInformation[_] = {
    +    determineResultType(arguments)
    +  }
    +
    +  override def getRowType(
    +      typeFactory: RelDataTypeFactory,
    +      arguments: util.List[AnyRef]): RelDataType = {
    +    val resultType = determineResultType(arguments)
    +    val (fieldNames, fieldIndexes, _) = UserDefinedFunctionUtils.getFieldInfo(resultType)
    +    UserDefinedFunctionUtils.buildRelDataType(typeFactory, resultType, fieldNames, fieldIndexes)
    +  }
    +
    +  private def determineResultType(arguments: util.List[AnyRef]): TypeInformation[_] =
{
    +    val resultType = tableFunction.getResultType(arguments, paramTypeInfos)
    --- End diff --
    
    I've updated the patch. I tried to use a `UserDefinedFunctionUtils.getEvalMethod()` to
find the `eval()' method when users call the `apply()`. They would be the consistent behaviors
now.


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