wuchong commented on a change in pull request #8276: [FLINK-12314] [docs-zh] 
Translate the "Type Serialization" page into …
URL: https://github.com/apache/flink/pull/8276#discussion_r281012770
 
 

 ##########
 File path: docs/dev/types_serialization.zh.md
 ##########
 @@ -246,98 +226,89 @@ public class AppendOne<T> implements MapFunction<T, 
Tuple2<T, Long>> {
 }
 {% endhighlight %}
 
-There are cases where Flink cannot reconstruct all generic type information. 
In that case, a user has to help out via *type hints*.
+在某些情况下,Flink 无法重建所有泛型类型信息。 在这种情况下,用户必须通过*类型提示*来解决问题。
 
+#### Java API 中的类型提示
 
-#### Type Hints in the Java API
-
-In cases where Flink cannot reconstruct the erased generic type information, 
the Java API
-offers so called *type hints*. The type hints tell the system the type of
-the data stream or data set produced by a function:
+在 Flink 无法重建被擦除的泛型类型信息的情况下,Java API 需要提供所谓的*类型提示*。
+类型提示告诉系统 DateStream 或者 DateSet 产生的类型:
 
 {% highlight java %}
 DataSet<SomeType> result = dataSet
     .map(new MyGenericNonInferrableFunction<Long, SomeType>())
         .returns(SomeType.class);
 {% endhighlight %}
 
-The `returns` statement specifies the produced type, in this case via a class. 
The hints support
-type definition via
-
-* Classes, for non-parameterized types (no generics)
-* TypeHints in the form of `returns(new TypeHint<Tuple2<Integer, 
SomeType>>(){})`. The `TypeHint` class
-  can capture generic type information and preserve it for the runtime (via an 
anonymous subclass).
+在上面情况下 `returns` 表达通过 Class 类型指出产生的类型。通过下面方式支持类型提示:
 
+* 对于非参数化的类型(没有泛型)的 Class 类型
+* 以 `returns(new TypeHint<Tuple2<Integer, SomeType>>(){})` 方式进行类型提示。
+  `TypeHint` 类可以捕获泛型的类型信息并且保存到执行期间(通过匿名子类)。
 
-#### Type extraction for Java 8 lambdas
+#### Java 8 lambdas 的类型提取
 
-Type extraction for Java 8 lambdas works differently than for non-lambdas, 
because lambdas are not associated
-with an implementing class that extends the function interface.
+Java 8 lambdas 的类型提取与非-lambdas 不同,因为 lambdas 与扩展函数接口的实现类没有关联。
 
-Currently, Flink tries to figure out which method implements the lambda and 
uses Java's generic signatures to
-determine the parameter types and the return type. However, these signatures 
are not generated for lambdas
-by all compilers (as of writing this document only reliably by the Eclipse JDT 
compiler from 4.5 onwards).
+Flink 目前试图找出实现 lambda 的方法,并使用 Java 的泛型签名来确定参数类型和返回类型。 
+但是,并非所有编译器都为 lambda 生成这些签名(此文档写作时,只有 Eclipse JDT 编译器从4.5开始可靠支持)。
 
 
-#### Serialization of POJO types
+#### POJO 类型的序列化
 
-The PojoTypeInformation is creating serializers for all the fields inside the 
POJO. Standard types such as
-int, long, String etc. are handled by serializers we ship with Flink.
-For all other types, we fall back to Kryo.
+PojoTypeInformation 为 POJO 中的所有字段创建序列化器。Flink 标准类型如 int、long、String 等由 Flink 
序列化器处理。
+对于所有其他类型,我们回退到 Kryo。
 
-If Kryo is not able to handle the type, you can ask the PojoTypeInfo to 
serialize the POJO using Avro.
-To do so, you have to call
+对于 Kryo 不能处理的类型,你可以要求 PojoTypeInfo 使用 Avro 对 POJO 进行序列化。
+需要通过下面的代码开启。
 
 {% highlight java %}
 final ExecutionEnvironment env = 
ExecutionEnvironment.getExecutionEnvironment();
 env.getConfig().enableForceAvro();
 {% endhighlight %}
 
-Note that Flink is automatically serializing POJOs generated by Avro with the 
Avro serializer.
+请注意,Flink 会使用 Avro 序列化器自动序列化 Avro 生成的 POJO。
 
-If you want your **entire** POJO Type to be treated by the Kryo serializer, set
+通过下面设置可以让你的**整个** POJO 类型被 Kryo 序列化器处理。
 
 {% highlight java %}
 final ExecutionEnvironment env = 
ExecutionEnvironment.getExecutionEnvironment();
 env.getConfig().enableForceKryo();
 {% endhighlight %}
 
-If Kryo is not able to serialize your POJO, you can add a custom serializer to 
Kryo, using
+如果 Kryo 不能序列化你的 POJO,可以通过下面的代码添加自定义的序列化器
 {% highlight java %}
 env.getConfig().addDefaultKryoSerializer(Class<?> type, Class<? extends 
Serializer<?>> serializerClass)
 {% endhighlight %}
 
-There are different variants of these methods available.
+这些方法有不同的变体可供选择。
 
 
-## Disabling Kryo Fallback
+## 禁止回退到 Kryo
 
-There are cases when programs may want to explicitly avoid using Kryo as a 
fallback for generic types. The most
-common one is wanting to ensure that all types are efficiently serialized 
either through Flink's own serializers,
-or via user-defined custom serializers.
+对于泛型信息,程序可能希望在一些情况下显示的避免使用 Kryo。最常见的场景是,用户想要确保所有的类型都可以通过 Flink 自身
+或者用户自定义的序列化器高效的进行序列化操作。
 
-The setting below will raise an exception whenever a data type is encountered 
that would go through Kryo:
+下面的设置将引起通过 Kryo 的数据类型抛出异常:
 {% highlight java %}
 env.getConfig().disableGenericTypes();
 {% endhighlight %}
 
 
-## Defining Type Information using a Factory
+## 使用工厂方法定义类型信息
 
-A type information factory allows for plugging-in user-defined type 
information into the Flink type system.
-You have to implement `org.apache.flink.api.common.typeinfo.TypeInfoFactory` 
to return your custom type information. 
-The factory is called during the type extraction phase if the corresponding 
type has been annotated 
-with the `@org.apache.flink.api.common.typeinfo.TypeInfo` annotation. 
+类型信息工厂允许将用户定义的类型信息插入 Flink 类型系统。
+你可以通过实现 `org.apache.flink.api.common.typeinfo.TypeInfoFactory` 来返回自定义的类型信息工厂。
+如果相应的类型已使用 `@ org.apache.flink.api.common.typeinfo.TypeInfo` 
注释进行注释,则在类型提取阶段调用自定义
 
 Review comment:
   ```suggestion
   如果相应的类型已指定了 `@org.apache.flink.api.common.typeinfo.TypeInfo` 注解,则在类型提取阶段会调用 
TypeInfo 注解指定的
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to