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