You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-zh@flink.apache.org by Dream-底限 <zh...@akulaku.com> on 2020/11/03 03:52:47 UTC

flink输出流类型

hi、
请问下面这两种输出流实现的时候,怎么确定选用实现upsert还是retract,因为看这两个api描述功能是差不多的,并且代码实现只是upsert多了两个方法,具体完成的功能貌似可以是一样的,这要怎么作出选择:



public interface RetractStreamTableSink<T>
extends StreamTableSink
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/sinks/StreamTableSink.html><Tuple2
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/api/java/tuple/Tuple2.html><Boolean
<http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html?is-external=true>,T>>

Defines an external TableSink
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/sinks/TableSink.html>
to
emit a streaming Table
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/api/Table.html>
with
insert, update, and delete changes.

The table will be converted into a stream of accumulate and retraction
messages which are encoded as Tuple2
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/api/java/tuple/Tuple2.html>.
The first field is a Boolean
<http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html?is-external=true>
flag
to indicate the message type. The second field holds the record of the
requested type T.

A message with true Boolean
<http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html?is-external=true>
flag
is an accumulate (or add) message.

A message with false flag is a retract message.


public interface UpsertStreamTableSink<T>
extends StreamTableSink
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/sinks/StreamTableSink.html><Tuple2
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/api/java/tuple/Tuple2.html><Boolean
<http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html?is-external=true>,T>>

Defines an external TableSink
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/sinks/TableSink.html>
to
emit a streaming Table
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/api/Table.html>
with
insert, update, and delete changes. The Table
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/api/Table.html>
must
be have unique key fields (atomic or composite) or be append-only.

If the Table
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/api/Table.html>
does
not have a unique key and is not append-only, a TableException
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/api/TableException.html>
will
be thrown.

The unique key of the table is configured by the setKeyFields(String[])
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/sinks/UpsertStreamTableSink.html#setKeyFields-java.lang.String:A->
 method.

The Table
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/table/api/Table.html>
will
be converted into a stream of upsert and delete messages which are encoded
as Tuple2
<https://ci.apache.org/projects/flink/flink-docs-release-1.11/api/java/org/apache/flink/api/java/tuple/Tuple2.html>.
The first field is a Boolean
<http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html?is-external=true>
flag
to indicate the message type. The second field holds the record of the
requested type T.

A message with true Boolean
<http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html?is-external=true>
field
is an upsert message for the configured key.

A message with false flag is a delete message for the configured key.

If the table is append-only, all messages will have a true flag and must be
interpreted as insertions.