元组Tuple
Tuple
是flink 一个很特殊的类型 (元组类型),是一个抽象类,共26个Tuple子类继承Tuple 他们是Tuple0
一直到Tuple25
Tuple
后的数字,代表每一个元组中可用空间(理解为插槽也行,每个字段对应一个插槽)
public class Tuple2<T0, T1> extends Tuple {
private static final long serialVersionUID = 1L;
/** Field 0 of the tuple. */
public T0 f0;
/** Field 1 of the tuple. */
public T1 f1;
/**
* Creates a new tuple where all fields are null.
*/
public Tuple2() {}
/**
* Creates a new tuple and assigns the given values to the tuple's fields.
*
* @param value0 The value for field 0
* @param value1 The value for field 1
*/
public Tuple2(T0 value0, T1 value1) {
this.f0 = value0;
this.f1 = value1;
}
'''还有别的方法'''
}
Collector
public interface Collector<T> {
/**
* Emits a record.
*
* @param record The record to collect.
*/
void collect(T record);
/**
* Closes the collector. If any data was buffered, that data will be flushed.
*/
void close();
}
- Collects a record and forwards it. The collector is the “push” counterpart of the java.util.Iterator, which “pulls” data in.
- 迭代器是一个list,把数据都放进去。而这个Collector是要把想要输出的结果都收集起来,然后再Push出去。
- 可以通过collect()方法来把数据输出
Parameter Tool
flink提供了ParameTool来读取参数
DataString
keyBy
- 按key重分区, 有点类似于groupBy,重新分组的意思