-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Flink: Move write from AppenderFactory to FileWriterFactory #14271
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,16 @@ protected PartitionedWriter( | |
| super(spec, format, appenderFactory, fileFactory, io, targetFileSize); | ||
| } | ||
|
|
||
| protected PartitionedWriter( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like PartitionedWriter is not used in Iceberg repo anymore
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it is not changed with this PR. |
||
| PartitionSpec spec, | ||
| FileFormat format, | ||
| FileWriterFactory<T> fileWriterFactory, | ||
| OutputFileFactory fileFactory, | ||
| FileIO io, | ||
| long targetFileSize) { | ||
| super(spec, format, fileWriterFactory, fileFactory, io, targetFileSize); | ||
| } | ||
|
|
||
| /** | ||
| * Create a PartitionKey from the values in row. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| package org.apache.iceberg.data; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.Serializable; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.FileFormat; | ||
|
|
@@ -37,9 +38,10 @@ | |
| import org.apache.iceberg.io.FileWriterFactory; | ||
| import org.apache.iceberg.orc.ORC; | ||
| import org.apache.iceberg.parquet.Parquet; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
|
|
||
| /** A base writer factory to be extended by query engine integrations. */ | ||
| public abstract class BaseFileWriterFactory<T> implements FileWriterFactory<T> { | ||
| public abstract class BaseFileWriterFactory<T> implements FileWriterFactory<T>, Serializable { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needed for Flink serialization
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked the child classes. Since
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I had test failures. Flink was not able to serialize/deserialize the factory, because the base class was not serializable.
BaseTable implements Added a test anyways.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah. I didn't notice that |
||
| private final Table table; | ||
| private final FileFormat dataFileFormat; | ||
| private final Schema dataSchema; | ||
|
|
@@ -49,7 +51,32 @@ public abstract class BaseFileWriterFactory<T> implements FileWriterFactory<T> { | |
| private final Schema equalityDeleteRowSchema; | ||
| private final SortOrder equalityDeleteSortOrder; | ||
| private final Schema positionDeleteRowSchema; | ||
| private final Map<String, String> writerProperties; | ||
|
|
||
| protected BaseFileWriterFactory( | ||
| Table table, | ||
| FileFormat dataFileFormat, | ||
| Schema dataSchema, | ||
| SortOrder dataSortOrder, | ||
| FileFormat deleteFileFormat, | ||
| int[] equalityFieldIds, | ||
| Schema equalityDeleteRowSchema, | ||
| SortOrder equalityDeleteSortOrder, | ||
| Schema positionDeleteRowSchema, | ||
| Map<String, String> writerProperties) { | ||
| this.table = table; | ||
| this.dataFileFormat = dataFileFormat; | ||
| this.dataSchema = dataSchema; | ||
| this.dataSortOrder = dataSortOrder; | ||
| this.deleteFileFormat = deleteFileFormat; | ||
| this.equalityFieldIds = equalityFieldIds; | ||
| this.equalityDeleteRowSchema = equalityDeleteRowSchema; | ||
| this.equalityDeleteSortOrder = equalityDeleteSortOrder; | ||
| this.positionDeleteRowSchema = positionDeleteRowSchema; | ||
| this.writerProperties = writerProperties; | ||
| } | ||
|
|
||
| @Deprecated | ||
| protected BaseFileWriterFactory( | ||
| Table table, | ||
| FileFormat dataFileFormat, | ||
|
|
@@ -69,6 +96,7 @@ protected BaseFileWriterFactory( | |
| this.equalityDeleteRowSchema = equalityDeleteRowSchema; | ||
| this.equalityDeleteSortOrder = equalityDeleteSortOrder; | ||
| this.positionDeleteRowSchema = positionDeleteRowSchema; | ||
| this.writerProperties = ImmutableMap.of(); | ||
| } | ||
|
|
||
| protected abstract void configureDataWrite(Avro.DataWriteBuilder builder); | ||
|
|
@@ -103,6 +131,7 @@ public DataWriter<T> newDataWriter( | |
| Avro.writeData(file) | ||
| .schema(dataSchema) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .withSpec(spec) | ||
| .withPartition(partition) | ||
|
|
@@ -119,6 +148,7 @@ public DataWriter<T> newDataWriter( | |
| Parquet.writeData(file) | ||
| .schema(dataSchema) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .withSpec(spec) | ||
| .withPartition(partition) | ||
|
|
@@ -135,6 +165,7 @@ public DataWriter<T> newDataWriter( | |
| ORC.writeData(file) | ||
| .schema(dataSchema) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .withSpec(spec) | ||
| .withPartition(partition) | ||
|
|
@@ -168,6 +199,7 @@ public EqualityDeleteWriter<T> newEqualityDeleteWriter( | |
| Avro.DeleteWriteBuilder avroBuilder = | ||
| Avro.writeDeletes(file) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .rowSchema(equalityDeleteRowSchema) | ||
| .equalityFieldIds(equalityFieldIds) | ||
|
|
@@ -185,6 +217,7 @@ public EqualityDeleteWriter<T> newEqualityDeleteWriter( | |
| Parquet.DeleteWriteBuilder parquetBuilder = | ||
| Parquet.writeDeletes(file) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .rowSchema(equalityDeleteRowSchema) | ||
| .equalityFieldIds(equalityFieldIds) | ||
|
|
@@ -202,6 +235,7 @@ public EqualityDeleteWriter<T> newEqualityDeleteWriter( | |
| ORC.DeleteWriteBuilder orcBuilder = | ||
| ORC.writeDeletes(file) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .rowSchema(equalityDeleteRowSchema) | ||
| .equalityFieldIds(equalityFieldIds) | ||
|
|
@@ -237,6 +271,7 @@ public PositionDeleteWriter<T> newPositionDeleteWriter( | |
| Avro.DeleteWriteBuilder avroBuilder = | ||
| Avro.writeDeletes(file) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .rowSchema(positionDeleteRowSchema) | ||
| .withSpec(spec) | ||
|
|
@@ -252,6 +287,7 @@ public PositionDeleteWriter<T> newPositionDeleteWriter( | |
| Parquet.DeleteWriteBuilder parquetBuilder = | ||
| Parquet.writeDeletes(file) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .rowSchema(positionDeleteRowSchema) | ||
| .withSpec(spec) | ||
|
|
@@ -267,6 +303,7 @@ public PositionDeleteWriter<T> newPositionDeleteWriter( | |
| ORC.DeleteWriteBuilder orcBuilder = | ||
| ORC.writeDeletes(file) | ||
| .setAll(properties) | ||
| .setAll(writerProperties) | ||
| .metricsConfig(metricsConfig) | ||
| .rowSchema(positionDeleteRowSchema) | ||
| .withSpec(spec) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is an approach with minimal effort to move Flink to FileWriterFactory.
Otherwise, the intention is probably for Flink and Kafka to move away from
BaseTaskWriteras well. E.g., Spark is usingFanoutDataWriterandClusteredDataWriter.Should we move Flink to use
PartitioningWriter? might be a bigger change though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we are missing is the
BaseEqualityDeltaWriter-RowDataDeltaWriterwhich keeps track of the previously written rows and create a position delete if it is deleted again.This could be done, but I would postpone it to another PR.
This PR would allow us to test the FileFormat API with Flink and also not expose the WriteBuilder on the FormatModelRegistry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with this approach. It doesn't require a big effort to migrate Flink to FileWriterFactory as an intermediate step, although if-else isn't perfect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we deprecate the
AppenderFactorythen we can remove the if statements.