HADOOP-2351 If select command returns no result, it doesn't need to show
the header information git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@603940 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f8a906f49f
commit
91de46cac1
|
@ -117,6 +117,10 @@ Trunk (unreleased changes)
|
||||||
(Edward Yoon via Stack)
|
(Edward Yoon via Stack)
|
||||||
HADOOP-2407 Keeping MapFile.Reader open is expensive: Part 2
|
HADOOP-2407 Keeping MapFile.Reader open is expensive: Part 2
|
||||||
HADOOP-2047 Add an '--master=X' and '--html' command-line parameters to shell
|
HADOOP-2047 Add an '--master=X' and '--html' command-line parameters to shell
|
||||||
|
(Edward Yoon via Stack)
|
||||||
|
HADOOP-2351 If select command returns no result, it doesn't need to show the
|
||||||
|
header information (Edward Yoon via Stack)
|
||||||
|
|
||||||
|
|
||||||
Release 0.15.1
|
Release 0.15.1
|
||||||
Branch 0.15
|
Branch 0.15
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class Shell {
|
||||||
public static final boolean DEFAULT_BELL_ENABLED = true;
|
public static final boolean DEFAULT_BELL_ENABLED = true;
|
||||||
public static String MASTER_ADDRESS = null;
|
public static String MASTER_ADDRESS = null;
|
||||||
public static String HTML_OPTION = null;
|
public static String HTML_OPTION = null;
|
||||||
|
public static int RELAUNCH_FLAG = 7;
|
||||||
|
|
||||||
/** Return the boolean value indicating whether end of command or not */
|
/** Return the boolean value indicating whether end of command or not */
|
||||||
static boolean isEndOfCommand(String line) {
|
static boolean isEndOfCommand(String line) {
|
||||||
|
@ -78,6 +79,14 @@ public class Shell {
|
||||||
*/
|
*/
|
||||||
public static void main(String args[]) throws IOException {
|
public static void main(String args[]) throws IOException {
|
||||||
argumentParsing(args);
|
argumentParsing(args);
|
||||||
|
if (args.length != 0) {
|
||||||
|
if (args[0].equals("--help") || args[0].equals("-h")) {
|
||||||
|
System.out
|
||||||
|
.println("Usage: ./bin/hbase shell [--master:master_address:port] [--html]\n");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HBaseConfiguration conf = new HBaseConfiguration();
|
HBaseConfiguration conf = new HBaseConfiguration();
|
||||||
ConsoleReader reader = new ConsoleReader();
|
ConsoleReader reader = new ConsoleReader();
|
||||||
System.setSecurityManager(new ShellSecurityManager());
|
System.setSecurityManager(new ShellSecurityManager());
|
||||||
|
@ -90,11 +99,10 @@ public class Shell {
|
||||||
}
|
}
|
||||||
if (HTML_OPTION != null) {
|
if (HTML_OPTION != null) {
|
||||||
tableFormater = new HtmlTableFormatter(out);
|
tableFormater = new HtmlTableFormatter(out);
|
||||||
System.out.println("--html");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HelpCommand help = new HelpCommand(out, tableFormater);
|
HelpCommand help = new HelpCommand(out, tableFormater);
|
||||||
if (args.length == 0 || !args[0].equals("7")) {
|
if (args.length == 0 || !args[0].equals(String.valueOf(Shell.RELAUNCH_FLAG))) {
|
||||||
help.printVersion();
|
help.printVersion();
|
||||||
}
|
}
|
||||||
StringBuilder queryStr = new StringBuilder();
|
StringBuilder queryStr = new StringBuilder();
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.HScannerInterface;
|
||||||
import org.apache.hadoop.hbase.HStoreKey;
|
import org.apache.hadoop.hbase.HStoreKey;
|
||||||
import org.apache.hadoop.hbase.HTable;
|
import org.apache.hadoop.hbase.HTable;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
|
import org.apache.hadoop.hbase.Shell;
|
||||||
import org.apache.hadoop.hbase.shell.generated.Parser;
|
import org.apache.hadoop.hbase.shell.generated.Parser;
|
||||||
import org.apache.hadoop.hbase.util.Writables;
|
import org.apache.hadoop.hbase.util.Writables;
|
||||||
import org.apache.hadoop.io.Text;
|
import org.apache.hadoop.io.Text;
|
||||||
|
@ -113,8 +114,10 @@ public class SelectCommand extends BasicCommand {
|
||||||
byte[][] result = null;
|
byte[][] result = null;
|
||||||
ParsedColumns parsedColumns = getColumns(admin, false);
|
ParsedColumns parsedColumns = getColumns(admin, false);
|
||||||
boolean multiple = parsedColumns.isMultiple() || this.version > 1;
|
boolean multiple = parsedColumns.isMultiple() || this.version > 1;
|
||||||
formatter.header(multiple ? HEADER_COLUMN_CELL : null);
|
|
||||||
for (Text column : parsedColumns.getColumns()) {
|
for (Text column : parsedColumns.getColumns()) {
|
||||||
|
if(count == 0) {
|
||||||
|
formatter.header(multiple ? HEADER_COLUMN_CELL : null);
|
||||||
|
}
|
||||||
if (this.timestamp != 0) {
|
if (this.timestamp != 0) {
|
||||||
result = table.get(this.rowKey, column, this.timestamp, this.version);
|
result = table.get(this.rowKey, column, this.timestamp, this.version);
|
||||||
} else {
|
} else {
|
||||||
|
@ -131,8 +134,10 @@ public class SelectCommand extends BasicCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
formatter.header(isMultiple() ? HEADER_COLUMN_CELL : null);
|
|
||||||
for (Map.Entry<Text, byte[]> e : table.getRow(this.rowKey).entrySet()) {
|
for (Map.Entry<Text, byte[]> e : table.getRow(this.rowKey).entrySet()) {
|
||||||
|
if(count == 0) {
|
||||||
|
formatter.header(isMultiple() ? HEADER_COLUMN_CELL : null);
|
||||||
|
}
|
||||||
Text key = e.getKey();
|
Text key = e.getKey();
|
||||||
String keyStr = key.toString();
|
String keyStr = key.toString();
|
||||||
if (!this.columns.contains(STAR) && !this.columns.contains(keyStr)) {
|
if (!this.columns.contains(STAR) && !this.columns.contains(keyStr)) {
|
||||||
|
@ -147,6 +152,10 @@ public class SelectCommand extends BasicCommand {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(count == 0 && Shell.HTML_OPTION != null) {
|
||||||
|
formatter.header(isMultiple() ? HEADER_COLUMN_CELL : null);
|
||||||
|
}
|
||||||
formatter.footer();
|
formatter.footer();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -209,8 +218,10 @@ public class SelectCommand extends BasicCommand {
|
||||||
HStoreKey key = new HStoreKey();
|
HStoreKey key = new HStoreKey();
|
||||||
TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
|
TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
|
||||||
// If only one column in query, then don't print out the column.
|
// If only one column in query, then don't print out the column.
|
||||||
formatter.header((parsedColumns.isMultiple()) ? HEADER : HEADER_ROW_CELL);
|
|
||||||
while (scan.next(key, results) && checkLimit(count)) {
|
while (scan.next(key, results) && checkLimit(count)) {
|
||||||
|
if(count == 0) {
|
||||||
|
formatter.header((parsedColumns.isMultiple()) ? HEADER : HEADER_ROW_CELL);
|
||||||
|
}
|
||||||
Text r = key.getRow();
|
Text r = key.getRow();
|
||||||
for (Text columnKey : results.keySet()) {
|
for (Text columnKey : results.keySet()) {
|
||||||
String cellData = toString(columnKey, results.get(columnKey));
|
String cellData = toString(columnKey, results.get(columnKey));
|
||||||
|
@ -229,6 +240,11 @@ public class SelectCommand extends BasicCommand {
|
||||||
// Clear results else subsequent results polluted w/ previous finds.
|
// Clear results else subsequent results polluted w/ previous finds.
|
||||||
results.clear();
|
results.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(count == 0 && Shell.HTML_OPTION != null) {
|
||||||
|
formatter.header((parsedColumns.isMultiple()) ? HEADER : HEADER_ROW_CELL);
|
||||||
|
}
|
||||||
|
|
||||||
formatter.footer();
|
formatter.footer();
|
||||||
scan.close();
|
scan.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.apache.hadoop.hbase.shell;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.Permission;
|
import java.security.Permission;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.Shell;
|
import org.apache.hadoop.hbase.Shell;
|
||||||
|
|
||||||
|
@ -47,9 +49,16 @@ public class ShellSecurityManager extends SecurityManager {
|
||||||
// I didn't figure out How can catch the ExitException in shell main.
|
// I didn't figure out How can catch the ExitException in shell main.
|
||||||
// So, I just Re-launching the shell.
|
// So, I just Re-launching the shell.
|
||||||
Shell shell = new Shell();
|
Shell shell = new Shell();
|
||||||
String[] args = new String[] { String.valueOf(7) };
|
|
||||||
|
List<String> argList = new ArrayList<String>();
|
||||||
|
argList.add(String.valueOf(Shell.RELAUNCH_FLAG));
|
||||||
|
if(Shell.HTML_OPTION != null)
|
||||||
|
argList.add(Shell.HTML_OPTION);
|
||||||
|
if(Shell.MASTER_ADDRESS != null)
|
||||||
|
argList.add(Shell.MASTER_ADDRESS);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shell.main(args);
|
shell.main(argList.toArray(new String[] {}));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue