[ 
https://issues.apache.org/jira/browse/FLINK-7452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16291067#comment-16291067
 ] 

ASF GitHub Bot commented on FLINK-7452:
---------------------------------------

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

    https://github.com/apache/flink/pull/4612#discussion_r156937828
  
    --- Diff: 
flink-scala/src/main/scala/org/apache/flink/api/scala/typeutils/Types.scala ---
    @@ -0,0 +1,371 @@
    +/*
    + * 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.api.scala.typeutils
    +
    +import org.apache.flink.annotation.PublicEvolving
    +import org.apache.flink.api.common.functions.InvalidTypesException
    +import org.apache.flink.api.common.typeinfo.{TypeInformation, Types => 
JTypes}
    +import org.apache.flink.types.Row
    +
    +import _root_.scala.collection.JavaConverters._
    +import _root_.scala.util.{Either, Try}
    +
    +/**
    +  * This class gives access to the type information of the most common 
Scala types for which Flink
    +  * has built-in serializers and comparators.
    +  *
    +  * This class contains types of 
[[org.apache.flink.api.common.typeinfo.Types]] and adds
    +  * types for Scala specific classes (such as [[Unit]] or case classes).
    +  *
    +  * In many cases, Flink tries to analyze generic signatures of functions 
to determine return
    +  * types automatically. This class is intended for cases where type 
information has to be
    +  * supplied manually or would result in an inefficient type.
    +  *
    +  * Scala macros allow to determine type information of classes and type 
parameters. You can
    +  * use [[Types.of]] to let type information be determined automatically.
    +  */
    +@PublicEvolving
    +object Types {
    +
    +  /**
    +    * Generates type information based on the given class and/or its type 
parameters.
    +    *
    +    * The definition is similar to a 
[[org.apache.flink.api.common.typeinfo.TypeHint]] but does
    +    * not require to implement anonymous classes.
    +    *
    +    * If the class could not be analyzed by the Scala type analyzer, the 
Java analyzer
    +    * will be used.
    +    *
    +    * Example use:
    +    *
    +    * `Types.of[(Int, String, String)]` for Scala tuples
    +    * `Types.of[Unit]` for Scala specific types
    +    *
    +    * @tparam T class to be analyzed
    +    */
    +  def of[T: TypeInformation]: TypeInformation[T] = {
    +    val typeInfo: TypeInformation[T] = implicitly[TypeInformation[T]]
    +    typeInfo
    +  }
    +
    +  /**
    +    * Returns type information for Scala [[Nothing]]. Does not support a 
null value.
    +    */
    +  val NOTHING: TypeInformation[Nothing] = new ScalaNothingTypeInfo
    +
    +  /**
    +    * Returns type information for Scala [[Unit]]. Does not support a null 
value.
    +    */
    +  val UNIT: TypeInformation[Unit] = new UnitTypeInfo
    +
    +  /**
    +    * Returns type information for [[String]] and [[java.lang.String]]. 
Supports a null value.
    +    */
    +  val STRING: TypeInformation[String] = JTypes.STRING
    +
    +  /**
    +    * Returns type information for primitive [[Byte]] and 
[[java.lang.Byte]]. Does not
    +    * support a null value.
    +    */
    +  val BYTE: TypeInformation[java.lang.Byte] = JTypes.BYTE
    +
    +  /**
    +    * Returns type information for primitive [[Boolean]] and 
[[java.lang.Boolean]]. Does not
    +    * support a null value.
    +    */
    +  val BOOLEAN: TypeInformation[java.lang.Boolean] = JTypes.BOOLEAN
    +
    +  /**
    +    * Returns type information for primitive [[Short]] and 
[[java.lang.Short]]. Does not
    +    * support a null value.
    +    */
    +  val SHORT: TypeInformation[java.lang.Short] = JTypes.SHORT
    +
    +  /**
    +    * Returns type information for primitive [[Int]] and 
[[java.lang.Integer]]. Does not
    +    * support a null value.
    +    */
    +  val INT: TypeInformation[java.lang.Integer] = JTypes.INT
    +
    +  /**
    +    * Returns type information for primitive [[Long]] and 
[[java.lang.Long]]. Does not
    +    * support a null value.
    +    */
    +  val LONG: TypeInformation[java.lang.Long] = JTypes.LONG
    +
    +  /**
    +    * Returns type information for primitive [[Float]] and 
[[java.lang.Float]]. Does not
    +    * support a null value.
    +    */
    +  val FLOAT: TypeInformation[java.lang.Float] = JTypes.FLOAT
    +
    +  /**
    +    * Returns type information for primitive [[Double]] and 
[[java.lang.Double]]. Does not
    +    * support a null value.
    +    */
    +  val DOUBLE: TypeInformation[java.lang.Double] = JTypes.DOUBLE
    +
    +  /**
    +    * Returns type information for primitive [[Char]] and 
[[java.lang.Character]]. Does not
    +    * support a null value.
    +    */
    +  val CHAR: TypeInformation[java.lang.Character] = JTypes.CHAR
    +
    +  /**
    +    * Returns type information for Java [[java.math.BigDecimal]]. Supports 
a null value.
    +    *
    +    * Note that Scala [[BigDecimal]] is not supported yet.
    +    */
    +  val JAVA_BIG_DEC: TypeInformation[java.math.BigDecimal] = JTypes.BIG_DEC
    +
    +  /**
    +    * Returns type information for Java [[java.math.BigInteger]]. Supports 
a null value.
    +    *
    +    * Note that Scala [[BigInt]] is not supported yet.
    +    */
    +  val JAVA_BIG_INT: TypeInformation[java.math.BigInteger] = JTypes.BIG_INT
    +
    +  /**
    +    * Returns type information for [[java.sql.Date]]. Supports a null 
value.
    +    */
    +  val SQL_DATE: TypeInformation[java.sql.Date] = JTypes.SQL_DATE
    +
    +  /**
    +    * Returns type information for [[java.sql.Time]]. Supports a null 
value.
    +    */
    +  val SQL_TIME: TypeInformation[java.sql.Time] = JTypes.SQL_TIME
    +
    +  /**
    +    * Returns type information for [[java.sql.Timestamp]]. Supports a null 
value.
    +    */
    +  val SQL_TIMESTAMP: TypeInformation[java.sql.Timestamp] = 
JTypes.SQL_TIMESTAMP
    +
    +  /**
    +    * Returns type information for [[org.apache.flink.types.Row]] with 
fields of the given types.
    +    * A row itself must not be null.
    +    *
    +    * A row is a fixed-length, null-aware composite type for storing 
multiple values in a
    +    * deterministic field order. Every field can be null independent of 
the field's type.
    +    * The type of row fields cannot be automatically inferred; therefore, 
it is required to pass
    +    * type information whenever a row is used.
    +    *
    +    * <p>The schema of rows can have up to <code>Integer.MAX_VALUE</code> 
fields, however, all row instances
    --- End diff --
    
    line exceeds 100  characters.


> Add helper methods for all built-in Flink types to Types
> --------------------------------------------------------
>
>                 Key: FLINK-7452
>                 URL: https://issues.apache.org/jira/browse/FLINK-7452
>             Project: Flink
>          Issue Type: Improvement
>          Components: Type Serialization System
>            Reporter: Timo Walther
>            Assignee: Timo Walther
>
> Sometimes it is very difficult to provide `TypeInformation` manually, in case 
> some extraction fails or is not available. {{TypeHint}}s should be the 
> preferred way but this methods can ensure correct types.
> I propose to add all built-in Flink types to the {{Types}}. Such as:
> {code}
> Types.POJO(MyPojo.class)
> Types.POJO(Map<String, TypeInformation>)
> Types.GENERIC(Object.class)
> Types.TUPLE(TypeInformation, ...)
> Types.MAP(TypeInformation, TypeInformation)
> {code}
> The methods should validate that the returned type is exactly the requested 
> type. And especially in case of POJO should help creating  {{PojoTypeInfo}}.
> Once this is in place, we can deprecate the {{TypeInfoParser}}.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to