HADOOP-2297 System.exit() Handling in hbase shell jar command
git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@599713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a465ae05b
commit
05d4458b47
|
@ -66,6 +66,7 @@ Trunk (unreleased changes)
|
|||
(Edward Yoon via Stack)
|
||||
HADOOP-2198 HTable should have method to return table metadata
|
||||
HADOOP-2296 hbase shell: phantom columns show up from select command
|
||||
HADOOP-2297 System.exit() Handling in hbase shell jar command
|
||||
|
||||
|
||||
Release 0.15.1
|
||||
|
|
|
@ -27,6 +27,7 @@ import jline.ConsoleReader;
|
|||
|
||||
import org.apache.hadoop.hbase.shell.Command;
|
||||
import org.apache.hadoop.hbase.shell.HelpCommand;
|
||||
import org.apache.hadoop.hbase.shell.ShellSecurityManager;
|
||||
import org.apache.hadoop.hbase.shell.ReturnMsg;
|
||||
import org.apache.hadoop.hbase.shell.TableFormatterFactory;
|
||||
import org.apache.hadoop.hbase.shell.generated.ParseException;
|
||||
|
@ -64,22 +65,21 @@ public class Shell {
|
|||
"";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Main method
|
||||
* @param args not used
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void main(@SuppressWarnings("unused") String args[])
|
||||
throws IOException {
|
||||
public static void main(String args[]) throws IOException {
|
||||
HBaseConfiguration conf = new HBaseConfiguration();
|
||||
ConsoleReader reader = new ConsoleReader();
|
||||
System.setSecurityManager(new ShellSecurityManager());
|
||||
reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled",
|
||||
DEFAULT_BELL_ENABLED));
|
||||
Writer out = new OutputStreamWriter(System.out, "UTF-8");
|
||||
TableFormatterFactory tff = new TableFormatterFactory(out, conf);
|
||||
HelpCommand help = new HelpCommand(out, tff.get());
|
||||
help.printVersion();
|
||||
if(args.length == 0) help.printVersion();
|
||||
StringBuilder queryStr = new StringBuilder();
|
||||
String extendedLine;
|
||||
while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) {
|
||||
|
|
|
@ -36,10 +36,12 @@ import org.apache.hadoop.io.Text;
|
|||
* Alters tables.
|
||||
*/
|
||||
public class AlterCommand extends SchemaModificationCommand {
|
||||
public enum OperationType {ADD, DROP, CHANGE, NOOP}
|
||||
public enum OperationType {
|
||||
ADD, DROP, CHANGE, NOOP
|
||||
}
|
||||
|
||||
private OperationType operationType = OperationType.NOOP;
|
||||
private Map<String, Map<String, Object>> columnSpecMap =
|
||||
new HashMap<String, Map<String, Object>>();
|
||||
private Map<String, Map<String, Object>> columnSpecMap = new HashMap<String, Map<String, Object>>();
|
||||
private String tableName;
|
||||
private String column; // column to be dropped
|
||||
|
||||
|
@ -51,7 +53,7 @@ public class AlterCommand extends SchemaModificationCommand {
|
|||
try {
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (!conn.tableExists(new Text(this.tableName))) {
|
||||
return new ReturnMsg(0, "'" + this.tableName + "' Table not found");
|
||||
return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
|
@ -63,16 +65,15 @@ public class AlterCommand extends SchemaModificationCommand {
|
|||
columns = columnSpecMap.keySet();
|
||||
for (String c : columns) {
|
||||
columnDesc = getColumnDescriptor(c, columnSpecMap.get(c));
|
||||
println("Adding " + c + " to " + tableName +
|
||||
"... Please wait.");
|
||||
println("Adding " + c + " to " + tableName + "... Please wait.");
|
||||
admin.addColumn(new Text(tableName), columnDesc);
|
||||
}
|
||||
enableTable(admin, tableName);
|
||||
break;
|
||||
case DROP:
|
||||
disableTable(admin, tableName);
|
||||
println("Dropping " + column + " from " + tableName +
|
||||
"... Please wait.");
|
||||
println("Dropping " + column + " from " + tableName
|
||||
+ "... Please wait.");
|
||||
column = appendDelimiter(column);
|
||||
admin.deleteColumn(new Text(tableName), new Text(column));
|
||||
enableTable(admin, tableName);
|
||||
|
|
|
@ -25,11 +25,14 @@ import java.io.Writer;
|
|||
/**
|
||||
* Takes the lowest-common-denominator {@link Writer} doing its own printlns,
|
||||
* etc.
|
||||
* @see <a href="http://wiki.apache.org/lucene-hadoop/Hbase/HbaseShell">HBaseShell</a>
|
||||
*
|
||||
* @see <a
|
||||
* href="http://wiki.apache.org/lucene-hadoop/Hbase/HbaseShell">HBaseShell</a>
|
||||
*/
|
||||
public abstract class BasicCommand implements Command, CommandFactory {
|
||||
private final Writer out;
|
||||
public final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
public final String TABLE_NOT_FOUND = " is non-existant table.";
|
||||
|
||||
// Shutdown constructor.
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -39,6 +42,7 @@ public abstract class BasicCommand implements Command, CommandFactory {
|
|||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param o A Writer.
|
||||
*/
|
||||
public BasicCommand(final Writer o) {
|
||||
|
@ -65,12 +69,12 @@ public abstract class BasicCommand implements Command, CommandFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* Appends, if it does not exist, a delimiter (colon)
|
||||
* at the end of the column name.
|
||||
* Appends, if it does not exist, a delimiter (colon) at the end of the column
|
||||
* name.
|
||||
*/
|
||||
protected String appendDelimiter(String column) {
|
||||
return (!column.endsWith(FAMILY_INDICATOR) && column.indexOf(FAMILY_INDICATOR) == -1)?
|
||||
column + FAMILY_INDICATOR: column;
|
||||
return (!column.endsWith(FAMILY_INDICATOR) && column
|
||||
.indexOf(FAMILY_INDICATOR) == -1) ? column + FAMILY_INDICATOR : column;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,8 @@ public class ClearCommand extends BasicCommand {
|
|||
super(o);
|
||||
}
|
||||
|
||||
public ReturnMsg execute(@SuppressWarnings("unused") HBaseConfiguration conf) {
|
||||
public ReturnMsg execute(@SuppressWarnings("unused")
|
||||
HBaseConfiguration conf) {
|
||||
clear();
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,13 @@ public interface Command {
|
|||
/** family indicator */
|
||||
public static final String FAMILY_INDICATOR = ":";
|
||||
|
||||
public enum CommandType {DDL, UPDATE, SELECT, INSERT, DELETE, SHELL}
|
||||
public enum CommandType {
|
||||
DDL, UPDATE, SELECT, INSERT, DELETE, SHELL
|
||||
}
|
||||
|
||||
/** Execute a command
|
||||
/**
|
||||
* Execute a command
|
||||
*
|
||||
* @param conf Configuration
|
||||
* @return Result of command execution
|
||||
*/
|
||||
|
|
|
@ -37,8 +37,7 @@ import org.apache.hadoop.io.Text;
|
|||
*/
|
||||
public class CreateCommand extends SchemaModificationCommand {
|
||||
private Text tableName;
|
||||
private Map<String, Map<String, Object>> columnSpecMap =
|
||||
new HashMap<String, Map<String, Object>>();
|
||||
private Map<String, Map<String, Object>> columnSpecMap = new HashMap<String, Map<String, Object>>();
|
||||
|
||||
public CreateCommand(Writer o) {
|
||||
super(o);
|
||||
|
@ -48,7 +47,7 @@ public class CreateCommand extends SchemaModificationCommand {
|
|||
try {
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (conn.tableExists(this.tableName)) {
|
||||
return new ReturnMsg(0, "'" + this.tableName + "' Table already exist");
|
||||
return new ReturnMsg(0, "'" + this.tableName + "' table already exist.");
|
||||
}
|
||||
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
|
@ -64,14 +63,14 @@ public class CreateCommand extends SchemaModificationCommand {
|
|||
|
||||
admin.createTable(tableDesc);
|
||||
return new ReturnMsg(0, "Table created successfully.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
return new ReturnMsg(0, extractErrMsg(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table to be created.
|
||||
*
|
||||
* @param tableName Table to be created
|
||||
*/
|
||||
public void setTable(String tableName) {
|
||||
|
@ -80,6 +79,7 @@ public class CreateCommand extends SchemaModificationCommand {
|
|||
|
||||
/**
|
||||
* Adds a column specification.
|
||||
*
|
||||
* @param columnSpec Column specification
|
||||
*/
|
||||
public void addColumnSpec(String column, Map<String, Object> columnSpec) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class DeleteCommand extends BasicCommand {
|
|||
try {
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (!conn.tableExists(new Text(this.tableName))) {
|
||||
return new ReturnMsg(0, "'" + this.tableName + "' Table not found");
|
||||
return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
|
@ -77,6 +77,7 @@ public class DeleteCommand extends BasicCommand {
|
|||
|
||||
/**
|
||||
* Sets the column list.
|
||||
*
|
||||
* @param columnList
|
||||
*/
|
||||
public void setColumnList(List<String> columnList) {
|
||||
|
@ -92,7 +93,8 @@ public class DeleteCommand extends BasicCommand {
|
|||
Text[] columns = null;
|
||||
try {
|
||||
if (this.columnList.contains("*")) {
|
||||
columns = hTable.getRow(new Text(this.rowKey)).keySet().toArray(new Text[] {});
|
||||
columns = hTable.getRow(new Text(this.rowKey)).keySet().toArray(
|
||||
new Text[] {});
|
||||
} else {
|
||||
List<Text> tmpList = new ArrayList<Text>();
|
||||
for (int i = 0; i < this.columnList.size(); i++) {
|
||||
|
|
|
@ -33,8 +33,7 @@ import org.apache.hadoop.io.Text;
|
|||
* Prints information about tables.
|
||||
*/
|
||||
public class DescCommand extends BasicCommand {
|
||||
private static final String [] HEADER =
|
||||
new String [] {"Column Family Descriptor"};
|
||||
private static final String[] HEADER = new String[] { "Column Family Descriptor" };
|
||||
private Text tableName;
|
||||
private final TableFormatter formatter;
|
||||
|
||||
|
@ -51,18 +50,18 @@ public class DescCommand extends BasicCommand {
|
|||
|
||||
public ReturnMsg execute(final HBaseConfiguration conf) {
|
||||
if (this.tableName == null)
|
||||
return new ReturnMsg(0, "Syntax error : Please check 'Describe' syntax");
|
||||
return new ReturnMsg(0, "Syntax error : Please check 'Describe' syntax.");
|
||||
try {
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (!conn.tableExists(this.tableName)) {
|
||||
return new ReturnMsg(0, "Table not found");
|
||||
return new ReturnMsg(0, "Table not found.");
|
||||
}
|
||||
HTableDescriptor[] tables = conn.listTables();
|
||||
HColumnDescriptor[] columns = null;
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
if (tables[i].getName().equals(this.tableName)) {
|
||||
columns = tables[i].getFamilies().values().
|
||||
toArray(new HColumnDescriptor [] {});
|
||||
columns = tables[i].getFamilies().values().toArray(
|
||||
new HColumnDescriptor[] {});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +78,7 @@ public class DescCommand extends BasicCommand {
|
|||
formatter.row(new String[] { columnStrs[i] });
|
||||
}
|
||||
formatter.footer();
|
||||
return new ReturnMsg(1, columns.length + " columnfamily(s) in set");
|
||||
return new ReturnMsg(1, columns.length + " columnfamily(s) in set.");
|
||||
} catch (IOException e) {
|
||||
return new ReturnMsg(0, "error msg : " + e.toString());
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.io.Writer;
|
|||
|
||||
import org.apache.hadoop.hbase.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
import org.apache.hadoop.hbase.HConnection;
|
||||
import org.apache.hadoop.hbase.HConnectionManager;
|
||||
import org.apache.hadoop.io.Text;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +42,11 @@ public class DisableCommand extends BasicCommand {
|
|||
assert tableName != null;
|
||||
|
||||
try {
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (!conn.tableExists(new Text(this.tableName))) {
|
||||
return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
admin.disableTable(new Text(tableName));
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.List;
|
|||
|
||||
import org.apache.hadoop.hbase.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
import org.apache.hadoop.hbase.HConnection;
|
||||
import org.apache.hadoop.hbase.HConnectionManager;
|
||||
import org.apache.hadoop.io.Text;
|
||||
|
||||
/**
|
||||
|
@ -39,18 +41,29 @@ public class DropCommand extends BasicCommand {
|
|||
|
||||
public ReturnMsg execute(HBaseConfiguration conf) {
|
||||
if (tableList == null) {
|
||||
throw new IllegalArgumentException("List of tables is null");
|
||||
throw new IllegalArgumentException("List of tables is null.");
|
||||
}
|
||||
|
||||
try {
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
|
||||
int count = 0;
|
||||
for (String table : tableList) {
|
||||
if (!conn.tableExists(new Text(table))) {
|
||||
println("'" + table + "' table not found.");
|
||||
} else {
|
||||
println("Dropping " + table + "... Please wait.");
|
||||
admin.deleteTable(new Text(table));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return new ReturnMsg(1, "Table(s) dropped successfully.");
|
||||
if (count > 0) {
|
||||
return new ReturnMsg(1, count + " table(s) dropped successfully.");
|
||||
} else {
|
||||
return new ReturnMsg(0, count + " table(s) dropped.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return new ReturnMsg(0, extractErrMsg(e));
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class EnableCommand extends BasicCommand {
|
|||
try {
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (!conn.tableExists(new Text(this.tableName))) {
|
||||
return new ReturnMsg(0, "'" + this.tableName + "' Table not found");
|
||||
return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
|
|
|
@ -28,10 +28,11 @@ public class ExitCommand extends BasicCommand {
|
|||
super(o);
|
||||
}
|
||||
|
||||
public ReturnMsg execute(@SuppressWarnings("unused") HBaseConfiguration conf) {
|
||||
public ReturnMsg execute(@SuppressWarnings("unused")
|
||||
HBaseConfiguration conf) {
|
||||
// TOD: Is this the best way to exit? Would be a problem if shell is run
|
||||
// inside another program -- St.Ack 09/11/2007
|
||||
System.exit(1);
|
||||
System.exit(9999);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ public class FsCommand extends BasicCommand {
|
|||
super(o);
|
||||
}
|
||||
|
||||
public ReturnMsg execute(@SuppressWarnings("unused") HBaseConfiguration conf) {
|
||||
public ReturnMsg execute(@SuppressWarnings("unused")
|
||||
HBaseConfiguration conf) {
|
||||
// This commmand will write the
|
||||
FsShell shell = new FsShell();
|
||||
try {
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.apache.hadoop.hbase.HBaseConfiguration;
|
|||
|
||||
public class HelpCommand extends BasicCommand {
|
||||
private String argument;
|
||||
private static final String[] HEADER = new String[] { "Command",
|
||||
"Description", "Example" };
|
||||
private static final String[] HEADER = new String[] { "Command", "Description",
|
||||
"Example" };
|
||||
|
||||
/** application name */
|
||||
public static final String APP_NAME = "Hbase Shell";
|
||||
|
@ -74,10 +74,10 @@ public class HelpCommand extends BasicCommand {
|
|||
|
||||
load.put("FS", new String[] {
|
||||
"Hadoop FsShell; entering a lone 'FS;' " + "will emit usage",
|
||||
"FS -copyFromLocal /home/user/backup.dat fs/user/backup;" });
|
||||
"FS [-option] arguments..;" });
|
||||
|
||||
load.put("JAR", new String[] { "Hadoop RunJar util",
|
||||
"JAR ./build/hadoop-examples.jar pi 10 10;" });
|
||||
"JAR jarFile [mainClass] arguments...;" });
|
||||
load.put("CLEAR", new String[] { "Clear the screen", "CLEAR;" });
|
||||
|
||||
load.put("DESCRIBE", new String[] { "Print table information",
|
||||
|
@ -125,11 +125,12 @@ public class HelpCommand extends BasicCommand {
|
|||
// model of
|
||||
// data.
|
||||
|
||||
load.put("TABLE",
|
||||
new String[] { "Load a table", "A = table('table_name');" });
|
||||
load
|
||||
.put("TABLE", new String[] { "Load a table", "A = table('table_name');" });
|
||||
load.put("SUBSTITUTE", new String[] { "Substitute expression to [A~Z]",
|
||||
"D = A.projection('cf_name1'[, 'cf_name2']);" });
|
||||
load.put("SAVE", new String[] { "Save results into specified table (It runs a mapreduce job)",
|
||||
load.put("SAVE", new String[] {
|
||||
"Save results into specified table (It runs a mapreduce job)",
|
||||
"SAVE A INTO table('table_name');" });
|
||||
|
||||
// Relational Operations
|
||||
|
@ -147,10 +148,7 @@ public class HelpCommand extends BasicCommand {
|
|||
|
||||
// Aggregation Functions
|
||||
// TODO : and apply aggregate function independently to each group of rows
|
||||
load
|
||||
.put(
|
||||
"GROUP",
|
||||
new String[] {
|
||||
load.put("GROUP", new String[] {
|
||||
"Group rows by value of an attribute",
|
||||
"A = Table('table_name');"
|
||||
+ " B = Group A by ('cf_name1'[, 'cf_name2']);" });
|
||||
|
|
|
@ -48,12 +48,12 @@ public class InsertCommand extends BasicCommand {
|
|||
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (!conn.tableExists(this.tableName)) {
|
||||
return new ReturnMsg(0, "'" + this.tableName + "' Table not found");
|
||||
return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (this.columnfamilies.size() != this.values.size())
|
||||
return new ReturnMsg(0,
|
||||
"Mismatch between values list and columnfamilies list");
|
||||
"Mismatch between values list and columnfamilies list.");
|
||||
|
||||
try {
|
||||
HTable table = new HTable(conf, this.tableName);
|
||||
|
|
|
@ -49,7 +49,8 @@ public class JarCommand extends BasicCommand {
|
|||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public ReturnMsg execute(@SuppressWarnings("unused") HBaseConfiguration conf) {
|
||||
public ReturnMsg execute(@SuppressWarnings("unused")
|
||||
HBaseConfiguration conf) {
|
||||
|
||||
try {
|
||||
String[] args = getQuery();
|
||||
|
@ -120,22 +121,19 @@ public class JarCommand extends BasicCommand {
|
|||
classPath.add(libs[i].toURL());
|
||||
}
|
||||
}
|
||||
ClassLoader loader =
|
||||
new URLClassLoader(classPath.toArray(new URL[0]));
|
||||
ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0]));
|
||||
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
Class<?> mainClass = Class.forName(mainClassName, true, loader);
|
||||
Method main = mainClass.getMethod("main", new Class[] {
|
||||
Array.newInstance(String.class, 0).getClass()
|
||||
});
|
||||
String[] newArgs = Arrays.asList(args)
|
||||
.subList(firstArg, args.length).toArray(new String[0]);
|
||||
Method main = mainClass.getMethod("main", new Class[] { Array.newInstance(
|
||||
String.class, 0).getClass() });
|
||||
String[] newArgs = Arrays.asList(args).subList(firstArg, args.length)
|
||||
.toArray(new String[0]);
|
||||
try {
|
||||
main.invoke(null, new Object[] { newArgs });
|
||||
} catch (InvocationTargetException e) {
|
||||
throw e.getTargetException();
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -77,8 +77,8 @@ public abstract class SchemaModificationCommand extends BasicCommand {
|
|||
} else if (spec.equals("IN_MEMORY")) {
|
||||
inMemory = (Boolean) columnSpec.get(spec);
|
||||
} else if (spec.equals("BLOOMFILTER")) {
|
||||
bloomFilterType = BloomFilterType.valueOf(((String) columnSpec
|
||||
.get(spec)).toUpperCase());
|
||||
bloomFilterType = BloomFilterType.valueOf(((String) columnSpec.get(spec))
|
||||
.toUpperCase());
|
||||
} else if (spec.equals("VECTOR_SIZE")) {
|
||||
vectorSize = (Integer) columnSpec.get(spec);
|
||||
} else if (spec.equals("NUM_HASH")) {
|
||||
|
@ -95,8 +95,8 @@ public abstract class SchemaModificationCommand extends BasicCommand {
|
|||
if (specs.contains("NUM_ENTRIES")) {
|
||||
bloomFilterDesc = new BloomFilterDescriptor(bloomFilterType, numEntries);
|
||||
} else {
|
||||
bloomFilterDesc = new BloomFilterDescriptor(bloomFilterType,
|
||||
vectorSize, numHash);
|
||||
bloomFilterDesc = new BloomFilterDescriptor(bloomFilterType, vectorSize,
|
||||
numHash);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,12 +55,10 @@ public class SelectCommand extends BasicCommand {
|
|||
// Count of versions to return.
|
||||
private int version;
|
||||
private boolean whereClause = false;
|
||||
private static final String [] HEADER_ROW_CELL =
|
||||
new String [] {"Row", "Cell"};
|
||||
private static final String [] HEADER_COLUMN_CELL =
|
||||
new String [] {"Column", "Cell"};
|
||||
private static final String [] HEADER =
|
||||
new String [] {"Row", "Column", "Cell"};
|
||||
private static final String[] HEADER_ROW_CELL = new String[] { "Row", "Cell" };
|
||||
private static final String[] HEADER_COLUMN_CELL = new String[] { "Column",
|
||||
"Cell" };
|
||||
private static final String[] HEADER = new String[] { "Row", "Column", "Cell" };
|
||||
private static final String STAR = "*";
|
||||
|
||||
private final TableFormatter formatter;
|
||||
|
@ -77,14 +75,14 @@ public class SelectCommand extends BasicCommand {
|
|||
}
|
||||
|
||||
public ReturnMsg execute(final HBaseConfiguration conf) {
|
||||
if (this.tableName.equals("") || this.rowKey == null ||
|
||||
this.columns.size() == 0) {
|
||||
if (this.tableName.equals("") || this.rowKey == null
|
||||
|| this.columns.size() == 0) {
|
||||
return new ReturnMsg(0, "Syntax error : Please check 'Select' syntax.");
|
||||
}
|
||||
try {
|
||||
HConnection conn = HConnectionManager.getConnection(conf);
|
||||
if (!conn.tableExists(this.tableName)) {
|
||||
return new ReturnMsg(0, "'" + this.tableName + "' Table not found");
|
||||
return new ReturnMsg(0, "'" + this.tableName + "'" + TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
HTable table = new HTable(conf, this.tableName);
|
||||
|
@ -95,7 +93,7 @@ public class SelectCommand extends BasicCommand {
|
|||
} else {
|
||||
count = scanPrint(table, admin);
|
||||
}
|
||||
return new ReturnMsg(1, Integer.toString(count) + " row(s) in set");
|
||||
return new ReturnMsg(1, Integer.toString(count) + " row(s) in set.");
|
||||
} catch (IOException e) {
|
||||
String[] msg = e.getMessage().split("[,]");
|
||||
return new ReturnMsg(0, msg[0]);
|
||||
|
@ -113,8 +111,7 @@ public class SelectCommand extends BasicCommand {
|
|||
formatter.header(multiple ? HEADER_COLUMN_CELL : null);
|
||||
for (Text column : parsedColumns.getColumns()) {
|
||||
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 {
|
||||
result = table.get(this.rowKey, column, this.version);
|
||||
}
|
||||
|
@ -155,9 +152,9 @@ public class SelectCommand extends BasicCommand {
|
|||
private String toString(final Text columnName, final byte[] cell)
|
||||
throws IOException {
|
||||
String result = null;
|
||||
if (columnName.equals(HConstants.COL_REGIONINFO) ||
|
||||
columnName.equals(HConstants.COL_SPLITA) ||
|
||||
columnName.equals(HConstants.COL_SPLITA)) {
|
||||
if (columnName.equals(HConstants.COL_REGIONINFO)
|
||||
|| columnName.equals(HConstants.COL_SPLITA)
|
||||
|| columnName.equals(HConstants.COL_SPLITA)) {
|
||||
result = Writables.getHRegionInfoOrNull(cell).toString();
|
||||
} else if (columnName.equals(HConstants.COL_STARTCODE)) {
|
||||
result = Long.toString(Writables.bytesToLong(cell));
|
||||
|
@ -168,8 +165,8 @@ public class SelectCommand extends BasicCommand {
|
|||
}
|
||||
|
||||
/**
|
||||
* Data structure with columns to use scanning and whether or not the
|
||||
* scan could return more than one column.
|
||||
* Data structure with columns to use scanning and whether or not the scan
|
||||
* could return more than one column.
|
||||
*/
|
||||
class ParsedColumns {
|
||||
private final List<Text> cols;
|
||||
|
@ -193,8 +190,7 @@ public class SelectCommand extends BasicCommand {
|
|||
}
|
||||
}
|
||||
|
||||
private int scanPrint(HTable table,
|
||||
HBaseAdmin admin) {
|
||||
private int scanPrint(HTable table, HBaseAdmin admin) {
|
||||
int count = 0;
|
||||
HScannerInterface scan = null;
|
||||
try {
|
||||
|
@ -238,24 +234,24 @@ public class SelectCommand extends BasicCommand {
|
|||
|
||||
/**
|
||||
* Make sense of the supplied list of columns.
|
||||
*
|
||||
* @param admin Admin to use.
|
||||
* @return Interpretation of supplied list of columns.
|
||||
*/
|
||||
public ParsedColumns getColumns(final HBaseAdmin admin,
|
||||
final boolean scanning) {
|
||||
public ParsedColumns getColumns(final HBaseAdmin admin, final boolean scanning) {
|
||||
ParsedColumns result = null;
|
||||
try {
|
||||
if (this.columns.contains("*")) {
|
||||
if (this.tableName.equals(HConstants.ROOT_TABLE_NAME)
|
||||
|| this.tableName.equals(HConstants.META_TABLE_NAME)) {
|
||||
result =
|
||||
new ParsedColumns(Arrays.asList(HConstants.COLUMN_FAMILY_ARRAY));
|
||||
result = new ParsedColumns(Arrays
|
||||
.asList(HConstants.COLUMN_FAMILY_ARRAY));
|
||||
} else {
|
||||
HTableDescriptor[] tables = admin.listTables();
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
if (tables[i].getName().equals(this.tableName)) {
|
||||
result = new ParsedColumns(new ArrayList<Text>(tables[i].
|
||||
families().keySet()));
|
||||
result = new ParsedColumns(new ArrayList<Text>(tables[i].families()
|
||||
.keySet()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -270,9 +266,10 @@ public class SelectCommand extends BasicCommand {
|
|||
// Otherwise, if the specified column is a column family, then
|
||||
// default behavior is to fetch all columns that have a matching
|
||||
// column family.
|
||||
column = (this.columns.get(i).contains(":"))?
|
||||
new Text(this.columns.get(i) + (scanning? "$": "")):
|
||||
new Text(this.columns.get(i) + ":" + (scanning? "$": ""));
|
||||
column = (this.columns.get(i).contains(":")) ? new Text(this.columns
|
||||
.get(i)
|
||||
+ (scanning ? "$" : "")) : new Text(this.columns.get(i) + ":"
|
||||
+ (scanning ? "$" : ""));
|
||||
tmpList.add(column);
|
||||
}
|
||||
result = new ParsedColumns(tmpList, tmpList.size() > 1);
|
||||
|
@ -333,8 +330,7 @@ public class SelectCommand extends BasicCommand {
|
|||
Writer out = new OutputStreamWriter(System.out, "UTF-8");
|
||||
HBaseConfiguration c = new HBaseConfiguration();
|
||||
// For debugging
|
||||
TableFormatterFactory tff =
|
||||
new TableFormatterFactory(out, c);
|
||||
TableFormatterFactory tff = new TableFormatterFactory(out, c);
|
||||
Parser parser = new Parser("select * from 'x' where row='x';", out, tff.get());
|
||||
Command cmd = parser.terminatedCommand();
|
||||
|
||||
|
|
|
@ -45,8 +45,7 @@ public class ShowCommand extends BasicCommand {
|
|||
this(o, f, null);
|
||||
}
|
||||
|
||||
public ShowCommand(final Writer o, final TableFormatter f,
|
||||
final String argument) {
|
||||
public ShowCommand(final Writer o, final TableFormatter f, final String argument) {
|
||||
super(o);
|
||||
this.formatter = f;
|
||||
this.command = argument;
|
||||
|
@ -54,7 +53,7 @@ public class ShowCommand extends BasicCommand {
|
|||
|
||||
public ReturnMsg execute(final HBaseConfiguration conf) {
|
||||
if (this.command == null) {
|
||||
return new ReturnMsg(0, "Syntax error : Please check 'Show' syntax");
|
||||
return new ReturnMsg(0, "Syntax error : Please check 'Show' syntax.");
|
||||
}
|
||||
try {
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
|
@ -63,7 +62,7 @@ public class ShowCommand extends BasicCommand {
|
|||
HTableDescriptor[] tables = admin.listTables();
|
||||
tableLength = tables.length;
|
||||
if (tableLength == 0) {
|
||||
return new ReturnMsg(0, "No tables found");
|
||||
return new ReturnMsg(0, "No tables found.");
|
||||
}
|
||||
formatter.header(HEADER);
|
||||
for (int i = 0; i < tableLength; i++) {
|
||||
|
@ -71,7 +70,7 @@ public class ShowCommand extends BasicCommand {
|
|||
formatter.row(new String[] { tableName, tables[i].toString() });
|
||||
}
|
||||
formatter.footer();
|
||||
return new ReturnMsg(1, tableLength + " table(s) in set");
|
||||
return new ReturnMsg(1, tableLength + " table(s) in set.");
|
||||
} else {
|
||||
Map<String, VariableRef> refer = VariablesPool.get(command);
|
||||
if (refer == null) {
|
||||
|
|
|
@ -67,7 +67,8 @@ public class SubstituteCommand extends BasicCommand {
|
|||
public void resetVariableRelation(String r1, String r2) {
|
||||
setChainKey(r1);
|
||||
String tableName = VariablesPool.get(r1).get(null).getArgument();
|
||||
VariableRef formula = new VariableRef(Constants.JOIN_SECOND_RELATION, tableName);
|
||||
VariableRef formula = new VariableRef(Constants.JOIN_SECOND_RELATION,
|
||||
tableName);
|
||||
VariablesPool.put(r1, r2, formula);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,13 @@ import org.apache.hadoop.hbase.shell.formatter.AsciiTableFormatter;
|
|||
/**
|
||||
* Interface implemented by table formatters outputting select results.
|
||||
* Implementations must have a constructor that takes a Writer.
|
||||
*
|
||||
* @see AsciiTableFormatter
|
||||
*/
|
||||
public interface TableFormatter {
|
||||
/**
|
||||
* Output header.
|
||||
*
|
||||
* @param titles Titles to emit.
|
||||
* @throws IOException
|
||||
*/
|
||||
|
@ -39,20 +41,22 @@ public interface TableFormatter {
|
|||
|
||||
/**
|
||||
* Output footer.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void footer() throws IOException;
|
||||
|
||||
/**
|
||||
* Output a row.
|
||||
*
|
||||
* @param cells
|
||||
* @throws IOException
|
||||
*/
|
||||
public void row(final String[] cells) throws IOException;
|
||||
|
||||
/**
|
||||
* @return Output stream being used (This is in interface to enforce fact
|
||||
* that formatters use Writers -- that they operate on character streams
|
||||
* @return Output stream being used (This is in interface to enforce fact that
|
||||
* formatters use Writers -- that they operate on character streams
|
||||
* rather than on byte streams).
|
||||
*/
|
||||
public Writer getOut();
|
||||
|
|
|
@ -28,23 +28,23 @@ import org.apache.hadoop.conf.Configuration;
|
|||
import org.apache.hadoop.hbase.shell.formatter.AsciiTableFormatter;
|
||||
|
||||
/**
|
||||
* Table formatter.
|
||||
* Specify formatter by setting "hbaseshell.formatter" property in
|
||||
* <code>hbase-site.xml</code> or by setting system property
|
||||
* <code>hbaseshell.formatter</code>. System property setting prevails over all
|
||||
* other configurations. Outputs UTF-8 encoded Strings even if
|
||||
* original data is binary. On static initialization, changes System.out to be
|
||||
* a UTF-8 output stream.
|
||||
* .
|
||||
* <p>TODO: Mysql has --skip-column-names and --silent which inserts a tab as
|
||||
* Table formatter. Specify formatter by setting "hbaseshell.formatter" property
|
||||
* in <code>hbase-site.xml</code> or by setting system property
|
||||
* <code>hbaseshell.formatter</code>. System property setting prevails over
|
||||
* all other configurations. Outputs UTF-8 encoded Strings even if original data
|
||||
* is binary. On static initialization, changes System.out to be a UTF-8 output
|
||||
* stream. .
|
||||
* <p>
|
||||
* TODO: Mysql has --skip-column-names and --silent which inserts a tab as
|
||||
* separator. Also has --html and --xml.
|
||||
* <p>To use the html formatter, currently set HBASE_OPTS as in:
|
||||
* <p>
|
||||
* To use the html formatter, currently set HBASE_OPTS as in:
|
||||
* <code>$ HBASE_OPTS="-Dhbaseshell.formatter=org.apache.hadoop.hbase.shell.formatter.HtmlTableFormatter" ./bin/hbase shell</code>
|
||||
* </p>
|
||||
*/
|
||||
public class TableFormatterFactory {
|
||||
private static final Log LOG =
|
||||
LogFactory.getLog(TableFormatterFactory.class.getName());
|
||||
private static final Log LOG = LogFactory.getLog(TableFormatterFactory.class
|
||||
.getName());
|
||||
private static final String FORMATTER_KEY = "hbaseshell.formatter";
|
||||
private final TableFormatter formatter;
|
||||
|
||||
|
@ -64,8 +64,8 @@ public class TableFormatterFactory {
|
|||
}
|
||||
LOG.debug("Table formatter class: " + className);
|
||||
try {
|
||||
Class<TableFormatter> clazz =
|
||||
(Class<TableFormatter>) Class.forName(className);
|
||||
Class<TableFormatter> clazz = (Class<TableFormatter>) Class
|
||||
.forName(className);
|
||||
Constructor<?> constructor = clazz.getConstructor(Writer.class);
|
||||
this.formatter = (TableFormatter) constructor.newInstance(out);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -34,6 +34,7 @@ public class VariableRef {
|
|||
|
||||
/**
|
||||
* Return argument of an operation
|
||||
*
|
||||
* @return argument
|
||||
*/
|
||||
public String getArgument() {
|
||||
|
@ -42,6 +43,7 @@ public class VariableRef {
|
|||
|
||||
/**
|
||||
* Return operation
|
||||
*
|
||||
* @return operation
|
||||
*/
|
||||
public String getOperation() {
|
||||
|
|
Loading…
Reference in New Issue