use of org.apache.flink.table.sinks.AppendStreamTableSink in project flink by apache.
the class CommonExecLegacySink method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<T> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
if (tableSink instanceof StreamTableSink) {
final Transformation<T> transform;
if (tableSink instanceof RetractStreamTableSink) {
transform = translateToTransformation(planner, config, true);
} else if (tableSink instanceof UpsertStreamTableSink) {
UpsertStreamTableSink<T> upsertSink = (UpsertStreamTableSink<T>) tableSink;
final boolean isAppendOnlyTable = !needRetraction;
upsertSink.setIsAppendOnly(isAppendOnlyTable);
if (upsertKeys != null) {
upsertSink.setKeyFields(upsertKeys);
} else {
if (isAppendOnlyTable) {
upsertSink.setKeyFields(null);
} else {
throw new TableException("UpsertStreamTableSink requires that Table has a full primary keys if it is updated.");
}
}
transform = translateToTransformation(planner, config, true);
} else if (tableSink instanceof AppendStreamTableSink) {
// verify table is an insert-only (append-only) table
if (needRetraction) {
throw new TableException("AppendStreamTableSink requires that Table has only insert changes.");
}
transform = translateToTransformation(planner, config, false);
} else {
if (isStreaming) {
throw new TableException("Stream Tables can only be emitted by AppendStreamTableSink, " + "RetractStreamTableSink, or UpsertStreamTableSink.");
} else {
transform = translateToTransformation(planner, config, false);
}
}
final DataStream<T> dataStream = new DataStream<T>(planner.getExecEnv(), transform);
final DataStreamSink<T> dsSink = (DataStreamSink<T>) ((StreamTableSink<T>) tableSink).consumeDataStream(dataStream);
if (dsSink == null) {
throw new TableException(String.format("The StreamTableSink#consumeDataStream(DataStream) must be implemented " + "and return the sink transformation DataStreamSink. " + "However, %s doesn't implement this method.", tableSink.getClass().getCanonicalName()));
}
return dsSink.getLegacyTransformation();
} else if (tableSink instanceof DataStreamTableSink) {
// is no real table sink, so we just need translate its input to Transformation.
return translateToTransformation(planner, config, ((DataStreamTableSink<T>) tableSink).withChangeFlag());
} else {
throw new TableException(String.format("Only Support StreamTableSink! However %s is not a StreamTableSink.", tableSink.getClass().getCanonicalName()));
}
}
Aggregations