amogh-jahagirdar commented on a change in pull request #4083:
URL: https://github.com/apache/iceberg/pull/4083#discussion_r804266335
##########
File path: core/src/main/java/org/apache/iceberg/avro/Avro.java
##########
@@ -217,17 +211,44 @@ static Context deleteContext(Map<String, String> config) {
Context dataContext = dataContext(config);
String codecAsString = config.get(DELETE_AVRO_COMPRESSION);
- CodecFactory codec = codecAsString != null ? toCodec(codecAsString) :
dataContext.codec();
+ String compressionLevel =
config.getOrDefault(DELETE_AVRO_COMPRESSION_LEVEL,
AVRO_COMPRESSION_LEVEL_DEFAULT);
+ CodecFactory codec = codecAsString != null ? toCodec(codecAsString,
compressionLevel) : dataContext.codec();
return new Context(codec);
}
- private static CodecFactory toCodec(String codecAsString) {
+ private static CodecFactory toCodec(String codecAsString, String
compressionLevel) {
+ CodecFactory codecFactory = null;
try {
- return
CodecName.valueOf(codecAsString.toUpperCase(Locale.ENGLISH)).get();
+ switch (Codec.valueOf(codecAsString.toUpperCase(Locale.ENGLISH))) {
+ case UNCOMPRESSED:
+ codecFactory = CodecFactory.nullCodec();
+ break;
+ case SNAPPY:
+ codecFactory = CodecFactory.snappyCodec();
+ break;
+ case ZSTD:
+ codecFactory =
CodecFactory.zstandardCodec(getCompressionLevel(compressionLevel,
+ ZSTD_COMPRESSION_LEVEL_DEFAULT));
+ break;
+ case GZIP:
+ codecFactory =
CodecFactory.deflateCodec(getCompressionLevel(compressionLevel,
+ GZIP_COMPRESSION_LEVEL_DEFAULT));
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported compression
codec: " + codecAsString);
+ }
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unsupported compression codec: "
+ codecAsString);
}
+ return codecFactory;
+ }
+
+ private static int getCompressionLevel(String tableCompressionLevel, int
defaultCompressionLevel) {
Review comment:
Makes sense, I think compressionLevelAsInt may convey what we are doing
better (converting a string compression level to an integer, falling back to a
default if the string is null)? Similar to what we do in PropertyUtil.
--
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]