flink1.12.x 支持的数据类型

说明

Flink 对可以在 DataSet 或 DataStream 中的元素类型进行了一些限制,要执行序列化和反序列化等一系列操作

在 链接 中的文章中,数据源中有 泛型,表示数据源中的对象类型,该类型就要满足 flink支持的数据类型

支持的类型

  • java基本数据类型、及包装类
  • flink的Tuple
  • Flink POJO
  • 集合,如:List、Map、Enum、数组

Flink的Tuple

Tuple类型 Tuple 是flink 一个很特殊的类型 (元组类型),是一个抽象类,共26个Tuple子类继承Tuple 他们是 Tuple0一直到Tuple25

Flink POJO

POJO类型要比一般类型好用。Flink访问POJO要比一般类型更高效。

与 java 的pojo有些区别,Flink POJO要求如下:

  • 是公共类;
  • 无参构造是公共的;
  • 所有属性声明为公共的,或提供 getter,setter方法
  • 所有属性的类型必须是Flink支持的

例子

flink pojo:

public class WordWithCount {
    public String word;
    public int count;
    public WordWithCount() {}
    public WordWithCount(String word, int count) { this.word = word; this.count = count; }
}

根据集合创建 DataStream:

DataStream<WordWithCount> wordCounts = env.fromElements(
    new WordWithCount("hello", 1),
    new WordWithCount("world", 2));
    wordCounts.keyBy("word");

参考:

https://www.jb51.net/article/214563.htm


原文出处:/show_1IX42i64rQvh.html