From 1e0c51c66e107a79b43c16dc1808168636626a3b Mon Sep 17 00:00:00 2001 From: Harsh J Date: Wed, 28 Dec 2011 14:30:19 +0000 Subject: [PATCH] HADOOP-7348. Change 'addnl' in getmerge util to be a flag '-nl' instead (XieXianshan via harsh) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1225192 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 2 ++ .../content/xdocs/file_system_shell.xml | 4 ++-- .../org/apache/hadoop/fs/shell/CopyCommands.java | 16 ++++++---------- .../src/test/resources/testConf.xml | 6 +++++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index fc7141d1a7..f522d6c5d1 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -79,6 +79,8 @@ Trunk (unreleased changes) HADOOP-7574. Improve FSShell -stat, add user/group elements (XieXianshan via harsh) + HADOOP-7348. Change 'addnl' in getmerge util to be a flag '-nl' instead (XieXianshan via harsh) + BUGS HADOOP-7851. Configuration.getClasses() never returns the default value. diff --git a/hadoop-common-project/hadoop-common/src/main/docs/src/documentation/content/xdocs/file_system_shell.xml b/hadoop-common-project/hadoop-common/src/main/docs/src/documentation/content/xdocs/file_system_shell.xml index ef4f76e5c8..6206a968a7 100644 --- a/hadoop-common-project/hadoop-common/src/main/docs/src/documentation/content/xdocs/file_system_shell.xml +++ b/hadoop-common-project/hadoop-common/src/main/docs/src/documentation/content/xdocs/file_system_shell.xml @@ -260,11 +260,11 @@
getmerge

- Usage: hdfs dfs -getmerge <src> <localdst> [addnl] + Usage: hdfs dfs -getmerge [-nl] <src> <localdst>

Takes a source directory and a destination file as input and concatenates files in src into the destination local file. - Optionally addnl can be set to enable adding a newline character at the end of each file. + Optionally -nl flag can be set to enable adding a newline character at the end of each file during merge.

diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java index 066e5fdb89..5260d9c80d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java @@ -45,26 +45,22 @@ public static void registerCommands(CommandFactory factory) { /** merge multiple files together */ public static class Merge extends FsCommand { public static final String NAME = "getmerge"; - public static final String USAGE = " [addnl]"; + public static final String USAGE = "[-nl] "; public static final String DESCRIPTION = "Get all the files in the directories that\n" + "match the source file pattern and merge and sort them to only\n" + - "one file on local fs. is kept."; + "one file on local fs. is kept.\n" + + " -nl Add a newline character at the end of each file."; protected PathData dst = null; protected String delimiter = null; @Override protected void processOptions(LinkedList args) throws IOException { - CommandFormat cf = new CommandFormat(2, 3); + CommandFormat cf = new CommandFormat(2, 3, "nl"); cf.parse(args); - // TODO: this really should be a -nl option - if ((args.size() > 2) && Boolean.parseBoolean(args.removeLast())) { - delimiter = "\n"; - } else { - delimiter = null; - } + delimiter = cf.getOpt("nl") ? "\n" : null; dst = new PathData(new File(args.removeLast()), getConf()); } @@ -197,4 +193,4 @@ public static class CopyToLocal extends Get { public static final String USAGE = Get.USAGE; public static final String DESCRIPTION = "Identical to the -get command."; } -} \ No newline at end of file +} diff --git a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml index e437cbccad..b1ce87e888 100644 --- a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml +++ b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml @@ -449,7 +449,7 @@ RegexpComparator - ^-getmerge <src> <localdst> \[addnl\]:( |\t)*Get all the files in the directories that( )* + ^-getmerge \[-nl\] <src> <localdst>:( |\t)*Get all the files in the directories that( )* RegexpComparator @@ -459,6 +459,10 @@ RegexpComparator ^( |\t)*one file on local fs. <src> is kept.( )* + + RegexpComparator + ^( |\t)*-nl Add a newline character at the end of each file.( )* +