Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flink: new sink base on the unified sink API #4904

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ private FlinkConfigOptions() {}
.defaultValue(false)
.withDescription("Use the FLIP-27 based Iceberg source implementation.");

public static final ConfigOption<Boolean> TABLE_EXEC_ICEBERG_USE_FLIP143_SINK =
ConfigOptions.key("table.exec.iceberg.use-flip143-sink")
.booleanType()
.defaultValue(false)
.withDescription("Use the FLIP-143 based Iceberg sink implementation.");

public static final ConfigOption<SplitAssignerType> TABLE_EXEC_SPLIT_ASSIGNER_TYPE =
ConfigOptions.key("table.exec.iceberg.split-assigner-type")
.enumType(SplitAssignerType.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@
import java.util.List;
import java.util.Map;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.table.api.TableSchema;
import org.apache.flink.table.api.constraints.UniqueConstraint;
import org.apache.flink.table.connector.ChangelogMode;
import org.apache.flink.table.connector.ProviderContext;
import org.apache.flink.table.connector.sink.DataStreamSinkProvider;
import org.apache.flink.table.connector.sink.DynamicTableSink;
import org.apache.flink.table.connector.sink.abilities.SupportsOverwrite;
import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
import org.apache.flink.table.data.RowData;
import org.apache.flink.types.RowKind;
import org.apache.flink.util.Preconditions;
import org.apache.iceberg.flink.sink.FlinkSink;
import org.apache.iceberg.flink.sink.IcebergSink;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;

public class IcebergTableSink implements DynamicTableSink, SupportsPartitioning, SupportsOverwrite {
Expand Down Expand Up @@ -62,23 +67,45 @@ public IcebergTableSink(

@Override
public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {

Preconditions.checkState(
!overwrite || context.isBounded(),
"Unbounded data stream doesn't support overwrite operation.");

List<String> equalityColumns =
tableSchema.getPrimaryKey().map(UniqueConstraint::getColumns).orElseGet(ImmutableList::of);

hililiwei marked this conversation as resolved.
Show resolved Hide resolved
return (DataStreamSinkProvider)
(providerContext, dataStream) ->
FlinkSink.forRowData(dataStream)
.tableLoader(tableLoader)
.tableSchema(tableSchema)
.equalityFieldColumns(equalityColumns)
.overwrite(overwrite)
.setAll(writeProps)
.flinkConf(readableConfig)
.append();
if (readableConfig.get(FlinkConfigOptions.TABLE_EXEC_ICEBERG_USE_FLIP143_SINK)) {
DataStreamSinkProvider dataStreamSinkProvider =
new DataStreamSinkProvider() {

@Override
public DataStreamSink<?> consumeDataStream(
ProviderContext providerContext, DataStream<RowData> dataStream) {

return IcebergSink.forRowData(dataStream)
.tableLoader(tableLoader)
.tableSchema(tableSchema)
.equalityFieldColumns(equalityColumns)
.overwrite(overwrite)
.setAll(writeProps)
.flinkConf(readableConfig)
.append();
}
};
return dataStreamSinkProvider;
} else {
return (DataStreamSinkProvider)
(providerContext, dataStream) ->
FlinkSink.forRowData(dataStream)
.tableLoader(tableLoader)
.tableSchema(tableSchema)
.equalityFieldColumns(equalityColumns)
.overwrite(overwrite)
.setAll(writeProps)
.flinkConf(readableConfig)
.append();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;

class DeltaManifests {
public class DeltaManifests {

private static final CharSequence[] EMPTY_REF_DATA_FILES = new CharSequence[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.apache.iceberg.ManifestFiles;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;

class DeltaManifestsSerializer implements SimpleVersionedSerializer<DeltaManifests> {
public class DeltaManifestsSerializer implements SimpleVersionedSerializer<DeltaManifests> {
private static final int VERSION_1 = 1;
private static final int VERSION_2 = 2;
private static final byte[] EMPTY_BINARY = new byte[0];

static final DeltaManifestsSerializer INSTANCE = new DeltaManifestsSerializer();
public static final DeltaManifestsSerializer INSTANCE = new DeltaManifestsSerializer();

@Override
public int getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.iceberg.io.WriteResult;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;

class FlinkManifestUtil {
public class FlinkManifestUtil {
private static final int FORMAT_V2 = 2;
private static final Long DUMMY_SNAPSHOT_ID = 0L;

Expand All @@ -60,7 +60,20 @@ static List<DataFile> readDataFiles(ManifestFile manifestFile, FileIO io) throws
}
}

static ManifestOutputFileFactory createOutputFileFactory(
public static ManifestOutputFileFactory createOutputFileFactory(
Table table, int subTaskId, long attemptNumber) {
TableOperations ops = ((HasTableOperations) table).operations();
return new ManifestOutputFileFactory(
ops,
table.io(),
table.properties(),
"flinkJobId",
"operatorUniqueId",
subTaskId,
attemptNumber);
}

public static ManifestOutputFileFactory createOutputFileFactory(
Table table, String flinkJobId, String operatorUniqueId, int subTaskId, long attemptNumber) {
TableOperations ops = ((HasTableOperations) table).operations();
return new ManifestOutputFileFactory(
Expand All @@ -73,7 +86,7 @@ static ManifestOutputFileFactory createOutputFileFactory(
attemptNumber);
}

static DeltaManifests writeCompletedFiles(
public static DeltaManifests writeCompletedFiles(
WriteResult result, Supplier<OutputFile> outputFileSupplier, PartitionSpec spec)
throws IOException {

Expand Down Expand Up @@ -104,7 +117,7 @@ static DeltaManifests writeCompletedFiles(
return new DeltaManifests(dataManifest, deleteManifest, result.referencedDataFiles());
}

static WriteResult readCompletedFiles(DeltaManifests deltaManifests, FileIO io)
public static WriteResult readCompletedFiles(DeltaManifests deltaManifests, FileIO io)
throws IOException {
WriteResult.Builder builder = WriteResult.builder();

Expand Down