You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by nk...@apache.org on 2019/07/23 09:56:08 UTC

[avro] branch master updated: AVRO-2461: Add compression level support to fromjson and recodec (#576)

This is an automated email from the ASF dual-hosted git repository.

nkollar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new ad9614a  AVRO-2461: Add compression level support to fromjson and recodec (#576)
ad9614a is described below

commit ad9614acebcf686a67f052ba80ca8eb872402066
Author: Kengo Seki <se...@apache.org>
AuthorDate: Tue Jul 23 18:56:03 2019 +0900

    AVRO-2461: Add compression level support to fromjson and recodec (#576)
---
 .../src/main/java/org/apache/avro/tool/Util.java   |  6 ++-
 .../test/java/org/apache/avro/tool/TestUtil.java   | 54 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java b/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
index 0b576d8..9861fa2 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
@@ -255,8 +255,8 @@ class Util {
   }
 
   static OptionSpec<Integer> compressionLevelOption(OptionParser optParser) {
-    return optParser.accepts("level", "Compression level (only applies to deflate and xz)").withRequiredArg()
-        .ofType(Integer.class).defaultsTo(Deflater.DEFAULT_COMPRESSION);
+    return optParser.accepts("level", "Compression level (only applies to deflate, xz, and zstandard)")
+        .withRequiredArg().ofType(Integer.class).defaultsTo(Deflater.DEFAULT_COMPRESSION);
   }
 
   static CodecFactory codecFactory(OptionSet opts, OptionSpec<String> codec, OptionSpec<Integer> level) {
@@ -270,6 +270,8 @@ class Util {
       return CodecFactory.deflateCodec(level.value(opts));
     } else if (codecName.equals(DataFileConstants.XZ_CODEC)) {
       return CodecFactory.xzCodec(level.value(opts));
+    } else if (codecName.equals(DataFileConstants.ZSTANDARD_CODEC)) {
+      return CodecFactory.zstandardCodec(level.value(opts));
     } else {
       return CodecFactory.fromString(codec.value(opts));
     }
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestUtil.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestUtil.java
new file mode 100644
index 0000000..1484e99
--- /dev/null
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestUtil.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro.tool;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import joptsimple.OptionSpec;
+import org.apache.avro.file.*;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+import java.lang.reflect.Method;
+
+public class TestUtil {
+
+  @Rule
+  public TestName name = new TestName();
+
+  private void zstandardCompressionLevel(int level) throws Exception {
+    OptionParser optParser = new OptionParser();
+    OptionSpec<String> codecOpt = Util.compressionCodecOption(optParser);
+    OptionSpec<Integer> levelOpt = Util.compressionLevelOption(optParser);
+
+    OptionSet opts = optParser.parse(new String[] { "--codec", "zstandard", "--level", String.valueOf(level) });
+    CodecFactory codecFactory = Util.codecFactory(opts, codecOpt, levelOpt);
+    Method createInstance = CodecFactory.class.getDeclaredMethod("createInstance");
+    createInstance.setAccessible(true);
+    Codec codec = (ZstandardCodec) createInstance.invoke(codecFactory);
+    Assert.assertEquals(String.format("zstandard[%d]", level), codec.toString());
+  }
+
+  @Test
+  public void testCodecFactoryZstandardCompressionLevel() throws Exception {
+    zstandardCompressionLevel(1);
+    zstandardCompressionLevel(CodecFactory.DEFAULT_ZSTANDARD_LEVEL);
+  }
+}