aokolnychyi commented on a change in pull request #2827:
URL: https://github.com/apache/iceberg/pull/2827#discussion_r670669132
##########
File path: core/src/main/java/org/apache/iceberg/avro/Avro.java
##########
@@ -190,8 +189,134 @@ private CodecFactory codec() {
// add the Iceberg schema to keyValueMetadata
meta("iceberg.schema", SchemaParser.toJson(schema));
+ Context context = createContextFunc.apply(config);
+ CodecFactory codec = context.codec();
+
return new AvroFileAppender<>(
- schema, AvroSchemaUtil.convert(schema, name), file, writerFunc,
codec(), metadata, metricsConfig, overwrite);
+ schema, AvroSchemaUtil.convert(schema, name), file, writerFunc,
codec, metadata, metricsConfig, overwrite);
+ }
+
+ private static class Context {
+ private final CodecFactory codec;
+
+ private Context(CodecFactory codec) {
+ this.codec = codec;
+ }
+
+ public static Context dataContext(Map<String, String> props) {
+ String codecAsString = props.getOrDefault(AVRO_COMPRESSION,
AVRO_COMPRESSION_DEFAULT);
+ CodecFactory codec = toCodec(codecAsString);
+
+ return new Context(codec);
+ }
+
+ public static Context deleteContext(Map<String, String> props) {
+ // default delete config using data config
+ Context dataContext = dataContext(props);
+
+ String codecAsString = props.get(DELETE_AVRO_COMPRESSION);
+ CodecFactory codec = codecAsString != null ? toCodec(codecAsString) :
dataContext.codec();
+
+ return new Context(codec);
+ }
+
+ private static CodecFactory toCodec(String codecAsString) {
+ try {
+ return
CodecName.valueOf(codecAsString.toUpperCase(Locale.ENGLISH)).get();
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Unsupported compression codec: "
+ codecAsString);
+ }
+ }
+
+ public CodecFactory codec() {
+ return codec;
+ }
+ }
+ }
+
+ public static DataWriteBuilder writeData(OutputFile file) {
+ return new DataWriteBuilder(file);
+ }
+
+ public static class DataWriteBuilder {
Review comment:
This matches our logic for building delete writers in this class.
--
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]