flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wuchong <...@git.apache.org>
Subject [GitHub] flink pull request #3039: [FLINK-5280] Update TableSource to support nested ...
Date Fri, 23 Dec 2016 12:22:37 GMT
Github user wuchong commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3039#discussion_r93756028
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/TableEnvironment.scala
---
    @@ -535,4 +509,74 @@ object TableEnvironment {
     
         new ScalaStreamTableEnv(executionEnvironment, tableConfig)
       }
    +
    +  /**
    +    * Returns field names and field positions for a given [[TypeInformation]].
    +    *
    +    * Field names are automatically extracted for
    +    * [[org.apache.flink.api.common.typeutils.CompositeType]].
    +    * The method fails if inputType is not a
    +    * [[org.apache.flink.api.common.typeutils.CompositeType]].
    +    *
    +    * @param inputType The TypeInformation extract the field names and positions from.
    +    * @tparam A The type of the TypeInformation.
    +    * @return A tuple of two arrays holding the field names and corresponding field positions.
    +    */
    +  def getFieldInfo[A](inputType: TypeInformation[A]): (Array[String], Array[Int]) = {
    +    validateType(inputType)
    +
    +    val fieldNames: Array[String] = inputType match {
    +      case t: TupleTypeInfo[A] => t.getFieldNames
    +      case c: CaseClassTypeInfo[A] => c.getFieldNames
    +      case p: PojoTypeInfo[A] => p.getFieldNames
    +      case r: RowTypeInfo => r.getFieldNames
    +      case tpe =>
    +        throw new TableException(s"Type $tpe lacks explicit field naming")
    +    }
    +    val fieldIndexes = fieldNames.indices.toArray
    +
    +    if (fieldNames.contains("*")) {
    +      throw new TableException("Field name can not be '*'.")
    +    }
    +
    +    (fieldNames, fieldIndexes)
    +  }
    +
    +  def validateType(typeInfo: TypeInformation[_]): Unit = {
    --- End diff --
    
    Could you add comment to describe what does this method do ? 


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