pvary commented on code in PR #12298:
URL: https://github.com/apache/iceberg/pull/12298#discussion_r2002913615
##########
core/src/main/java/org/apache/iceberg/avro/Avro.java:
##########
@@ -99,92 +121,187 @@ public static WriteBuilder write(OutputFile file) {
return new WriteBuilder(file);
}
+ @Deprecated
public static WriteBuilder write(EncryptedOutputFile file) {
return new WriteBuilder(file.encryptingOutputFile());
}
- public static class WriteBuilder implements InternalData.WriteBuilder {
+ public static <E> AppenderBuilder<E> appender(EncryptedOutputFile file) {
+ Preconditions.checkState(
+ !(file instanceof NativeEncryptionOutputFile), "Native Avro encryption
is not supported");
+ return new AppenderBuilder<>(file.encryptingOutputFile());
+ }
+
+ public static <E> AppenderBuilder<E> appender(OutputFile file) {
+ return new AppenderBuilder<>(file);
+ }
+
+ @Deprecated
+ public static class WriteBuilder extends
AppenderBuilderInternal<WriteBuilder, Object> {
+ private WriteBuilder(OutputFile file) {
+ super(file);
+ }
+ }
+
+ public static class AppenderBuilder<E> extends
AppenderBuilderInternal<AppenderBuilder<E>, E> {
+ private AppenderBuilder(OutputFile file) {
+ super(file);
+ }
+ }
+
+ /** Will be removed when the {@link WriteBuilder} is removed. */
+ @SuppressWarnings("unchecked")
+ static class AppenderBuilderInternal<B extends AppenderBuilderInternal<B,
E>, E>
+ implements InternalData.WriteBuilder, DataFileAppenderBuilder<B, E> {
private final OutputFile file;
private final Map<String, String> config = Maps.newHashMap();
private final Map<String, String> metadata = Maps.newLinkedHashMap();
private org.apache.iceberg.Schema schema = null;
private String name = "table";
private Function<Schema, DatumWriter<?>> createWriterFunc = null;
+ private BiFunction<Schema, E, DatumWriter<?>> writerFunction = null;
+ private BiFunction<Schema, E, DatumWriter<?>> deleteRowWriterFunction =
null;
private boolean overwrite;
private MetricsConfig metricsConfig;
private Function<Map<String, String>, Context> createContextFunc =
Context::dataContext;
+ private E engineSchema;
- private WriteBuilder(OutputFile file) {
+ private AppenderBuilderInternal(OutputFile file) {
this.file = file;
}
- public WriteBuilder forTable(Table table) {
+ @Deprecated
+ public B forTable(Table table) {
schema(table.schema());
setAll(table.properties());
metricsConfig(MetricsConfig.forTable(table));
- return this;
+ return (B) this;
}
@Override
- public WriteBuilder schema(org.apache.iceberg.Schema newSchema) {
+ public B schema(org.apache.iceberg.Schema newSchema) {
this.schema = newSchema;
- return this;
+ return (B) this;
}
@Override
- public WriteBuilder named(String newName) {
+ public B named(String newName) {
this.name = newName;
- return this;
+ return (B) this;
}
- public WriteBuilder createWriterFunc(Function<Schema, DatumWriter<?>>
writerFunction) {
- this.createWriterFunc = writerFunction;
- return this;
+ public B createWriterFunc(Function<Schema, DatumWriter<?>>
newWriterFunction) {
+ Preconditions.checkState(
+ writerFunction == null && deleteRowWriterFunction == null,
+ "Cannot set multiple writer builder functions");
+ this.createWriterFunc = newWriterFunction;
+ return (B) this;
+ }
+
+ public B writerFunction(BiFunction<Schema, E, DatumWriter<?>>
newWriterFunction) {
+ Preconditions.checkState(
+ createWriterFunc == null, "Cannot set multiple writer builder
functions");
+ this.writerFunction = newWriterFunction;
+ return (B) this;
+ }
+
+ public B deleteRowWriterFunction(BiFunction<Schema, E, DatumWriter<?>>
newWriterFunction) {
+ Preconditions.checkState(
+ createWriterFunc == null, "Cannot set multiple writer builder
functions");
+ this.deleteRowWriterFunction = newWriterFunction;
+ return (B) this;
}
@Override
- public WriteBuilder set(String property, String value) {
+ public B set(String property, String value) {
config.put(property, value);
- return this;
+ return (B) this;
}
- public WriteBuilder setAll(Map<String, String> properties) {
+ @Deprecated
+ public B setAll(Map<String, String> properties) {
config.putAll(properties);
- return this;
+ return (B) this;
}
@Override
- public WriteBuilder meta(String property, String value) {
+ public B meta(String property, String value) {
metadata.put(property, value);
- return this;
+ return (B) this;
}
@Override
- public WriteBuilder meta(Map<String, String> properties) {
+ public B meta(Map<String, String> properties) {
metadata.putAll(properties);
- return this;
+ return (B) this;
}
- public WriteBuilder metricsConfig(MetricsConfig newMetricsConfig) {
+ @Override
+ public B metricsConfig(MetricsConfig newMetricsConfig) {
this.metricsConfig = newMetricsConfig;
- return this;
+ return (B) this;
}
@Override
- public WriteBuilder overwrite() {
+ public B overwrite() {
return overwrite(true);
}
- public WriteBuilder overwrite(boolean enabled) {
+ @Override
+ public B overwrite(boolean enabled) {
this.overwrite = enabled;
- return this;
+ return (B) this;
}
// supposed to always be a private method used strictly by data and delete
write builders
- private WriteBuilder createContextFunc(
- Function<Map<String, String>, Context> newCreateContextFunc) {
+ // protected because of inheritance until deprecation of the WriteBuilder
Review Comment:
done
##########
data/src/main/java/org/apache/iceberg/data/GenericFileWriterFactory.java:
##########
@@ -50,62 +49,58 @@ class GenericFileWriterFactory extends
BaseFileWriterFactory<Record> {
super(
table,
dataFileFormat,
+ DataFileToObjectModelRegistry.GENERIC_OBJECT_MODEL,
dataSchema,
dataSortOrder,
deleteFileFormat,
equalityFieldIds,
equalityDeleteRowSchema,
equalityDeleteSortOrder,
+ positionDeleteRowSchema,
+ ImmutableMap.of(),
+ dataSchema,
+ equalityDeleteRowSchema,
positionDeleteRowSchema);
}
static Builder builderFor(Table table) {
return new Builder(table);
}
- @Override
protected void configureDataWrite(Avro.DataWriteBuilder builder) {
- builder.createWriterFunc(DataWriter::create);
+ throw new UnsupportedOperationException("Deprecated");
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]