avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [avro] branch master updated: AVRO-2465: Fix wrong defalut values in the avro-tools' usage
Date Mon, 19 Aug 2019 17:47:47 GMT
This is an automated email from the ASF dual-hosted git repository.

dkulp 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 e305f06  AVRO-2465: Fix wrong defalut values in the avro-tools' usage
e305f06 is described below

commit e305f0625be79753dd34d20a5bfbecf9f01e5b41
Author: Kengo Seki <sekikn@apache.org>
AuthorDate: Mon Jul 8 22:23:49 2019 +0900

    AVRO-2465: Fix wrong defalut values in the avro-tools' usage
---
 .../org/apache/avro/tool/DataFileWriteTool.java    |  2 +-
 .../java/org/apache/avro/tool/RecodecTool.java     |  2 +-
 .../src/main/java/org/apache/avro/tool/Util.java   |  7 ++++++-
 .../apache/avro/tool/TestCreateRandomFileTool.java |  8 ++++++++
 .../org/apache/avro/tool/TestDataFileTools.java    |  9 +++++++++
 .../org/apache/avro/tool/TestTextFileTools.java    | 22 +++++++++++++++++-----
 6 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java
index 3beb955..b763a00 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileWriteTool.java
@@ -53,7 +53,7 @@ public class DataFileWriteTool implements Tool {
   public int run(InputStream stdin, PrintStream out, PrintStream err, List<String>
args) throws Exception {
 
     OptionParser p = new OptionParser();
-    OptionSpec<String> codec = Util.compressionCodecOption(p);
+    OptionSpec<String> codec = Util.compressionCodecOptionWithDefault(p, DataFileConstants.NULL_CODEC);
     OptionSpec<Integer> level = Util.compressionLevelOption(p);
     OptionSpec<String> file = p.accepts("schema-file", "Schema File").withOptionalArg().ofType(String.class);
     OptionSpec<String> inschema = p.accepts("schema", "Schema").withOptionalArg().ofType(String.class);
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/RecodecTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/RecodecTool.java
index fded37b..c851891 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/RecodecTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/RecodecTool.java
@@ -41,7 +41,7 @@ public class RecodecTool implements Tool {
   public int run(InputStream in, PrintStream out, PrintStream err, List<String> args)
throws Exception {
 
     OptionParser optParser = new OptionParser();
-    OptionSpec<String> codecOpt = Util.compressionCodecOption(optParser);
+    OptionSpec<String> codecOpt = Util.compressionCodecOptionWithDefault(optParser,
DataFileConstants.NULL_CODEC);
     OptionSpec<Integer> levelOpt = Util.compressionLevelOption(optParser);
     OptionSet opts = optParser.parse(args.toArray(new String[0]));
 
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 9861fa2..f3d2d60 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
@@ -251,7 +251,12 @@ class Util {
   }
 
   static OptionSpec<String> compressionCodecOption(OptionParser optParser) {
-    return optParser.accepts("codec", "Compression codec").withRequiredArg().ofType(String.class).defaultsTo("null");
+    return optParser.accepts("codec", "Compression codec").withRequiredArg().ofType(String.class)
+        .defaultsTo(DEFLATE_CODEC);
+  }
+
+  static OptionSpec<String> compressionCodecOptionWithDefault(OptionParser optParser,
String s) {
+    return optParser.accepts("codec", "Compression codec").withRequiredArg().ofType(String.class).defaultsTo(s);
   }
 
   static OptionSpec<Integer> compressionLevelOption(OptionParser optParser) {
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
b/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
index 3e75623..e068e10 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Iterator;
 
@@ -134,4 +135,11 @@ public class TestCreateRandomFileTool {
 
     reader.close();
   }
+
+  @Test
+  public void testDefaultCodec() throws Exception {
+    // The default codec for random is deflate
+    run(Collections.emptyList());
+    assertTrue(err.toString().contains("Compression codec (default: deflate)"));
+  }
 }
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java
index 15e021e..00538aa 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java
@@ -257,4 +257,13 @@ public class TestDataFileTools {
     }
     return outFile;
   }
+
+  @Test
+  public void testDefaultCodec() throws Exception {
+    // The default codec for fromjson is null
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    PrintStream err = new PrintStream(baos);
+    new DataFileWriteTool().run(new ByteArrayInputStream(jsonData.getBytes()), null, err,
Collections.emptyList());
+    assertTrue(baos.toString().contains("Compression codec (default: null)"));
+  }
 }
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
index 30f05de..770b812 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
@@ -19,18 +19,21 @@ package org.apache.avro.tool;
 
 import static org.junit.Assert.assertEquals;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.OutputStream;
-import java.io.InputStream;
-import java.io.FileOutputStream;
 import java.io.FileInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Random;
 
 import org.apache.avro.Schema;
@@ -131,4 +134,13 @@ public class TestTextFileTools {
       }
     }
   }
+
+  @Test
+  public void testDefaultCodec() throws Exception {
+    // The default codec for fromtext is deflate
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    PrintStream err = new PrintStream(baos);
+    new FromTextTool().run(null, null, err, Collections.emptyList());
+    Assert.assertTrue(baos.toString().contains("Compression codec (default: deflate)"));
+  }
 }


Mime
View raw message