flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request #3039: [FLINK-5280] Update TableSource to support nested ...
Date Thu, 05 Jan 2017 22:18:51 GMT
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3039#discussion_r94859631
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/TableEnvironment.scala
---
    @@ -535,4 +511,92 @@ object TableEnvironment {
     
         new ScalaStreamTableEnv(executionEnvironment, tableConfig)
       }
    +
    +  /**
    +    * Returns field names for a given [[TypeInformation]].
    +    *
    +    * Field names are automatically extracted for
    +    * [[org.apache.flink.api.common.typeutils.CompositeType]]
    +    * or [[org.apache.flink.api.common.typeinfo.AtomicType]].
    +    * The method fails if inputType is not a
    +    * [[org.apache.flink.api.common.typeutils.CompositeType]]
    +    * or [[org.apache.flink.api.common.typeinfo.AtomicType]].
    +    *
    +    * @param inputType The TypeInformation extract the field names.
    +    * @tparam A The type of the TypeInformation.
    +    * @return A an array holding the field names
    +    */
    +  def getFieldNames[A](inputType: TypeInformation[A]): Array[String] = {
    +    validateType(inputType)
    +
    +    val fieldNames: Array[String] = inputType match {
    +      case t: CompositeType[_] => t.getFieldNames
    +      case a: AtomicType[_] => Array("f0")
    +      case tpe =>
    +        throw new TableException(s"Currently only CompositeType and AtomicType are supported.
" +
    +          s"Type $tpe lacks explicit field naming")
    +    }
    +
    +    if (fieldNames.contains("*")) {
    +      throw new TableException("Field name can not be '*'.")
    +    }
    +
    +    fieldNames
    +  }
    +
    +  /**
    +    * Validate if class represented by the typeInfo is static and globally accessible
    +    * @param typeInfo type to check
    +    * @throws TableException if type does not meet these criteria
    +    */
    +  def validateType(typeInfo: TypeInformation[_]): Unit = {
    +    val clazz = typeInfo.getTypeClass
    +    if ((clazz.isMemberClass && !Modifier.isStatic(clazz.getModifiers)) ||
    +      !Modifier.isPublic(clazz.getModifiers) ||
    +      clazz.getCanonicalName == null) {
    +      throw TableException(s"Class '$clazz' described in type information '$typeInfo'
must be " +
    +        s"static and globally accessible.")
    +    }
    +  }
    +
    +  /**
    +    * Returns field indexes for a given [[TypeInformation]].
    +    *
    +    * Field indexes are automatically extracted for
    +    * [[org.apache.flink.api.common.typeutils.CompositeType]]
    +    * or [[org.apache.flink.api.common.typeinfo.AtomicType]].
    +    * The method fails if inputType is not a
    --- End diff --
    
    No need to mention this, IMO.


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