diff --git a/CHANGES.txt b/CHANGES.txt
index fc4c5ee1bec..1e7b2cb5a8f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -56,5 +56,4 @@ Trunk (unreleased changes)
33. HADOOP-1538 Provide capability for client specified time stamps in HBase
HADOOP-1466 Clean up visibility and javadoc issues in HBase.
34. HADOOP-1589 Exception handling in HBase is broken over client server connections
-
-
+ 35. HADOOP-1375 a simple parser for hbase (Edward Yoon via Stack)
diff --git a/NOTICE.txt b/NOTICE.txt
index 9b5e6e0401f..22f9107d7b6 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,8 @@
This product includes software developed by The Apache Software
Foundation (http://www.apache.org/).
-In addition, this product includes software developed by European Commission
-project OneLab (http://www.one-lab.org)
+In addition, this product includes software developed by:
+
+European Commission project OneLab (http://www.one-lab.org)
+
+Udanax (http://www.udanax.org)
diff --git a/bin/hbase b/bin/hbase
index e92697b6cdb..b9559236b69 100755
--- a/bin/hbase
+++ b/bin/hbase
@@ -38,9 +38,7 @@ esac
if [ $# = 0 ]; then
echo "Usage: hbase [--hadoop=hadoopdir] "
echo "where is one of:"
- echo " client run a hbase client"
- echo " reader run a hbase region directory reader"
- echo " logreader output content of a logfile"
+ echo " shell run the hbase shell"
echo " master run a hbase HMaster node"
echo " regionserver run a hbase HRegionServer node"
echo " or"
@@ -181,12 +179,8 @@ fi
unset IFS
# figure out which class to run
-if [ "$COMMAND" = "client" ] ; then
- CLASS='org.apache.hadoop.hbase.HClient'
-elif [ "$COMMAND" = "reader" ] ; then
- CLASS='org.apache.hadoop.hbase.HRegiondirReader'
-elif [ "$COMMAND" = "logreader" ] ; then
- CLASS='org.apache.hadoop.hbase.HLog'
+if [ "$COMMAND" = "shell" ] ; then
+ CLASS='org.apache.hadoop.hbase.Shell'
elif [ "$COMMAND" = "master" ] ; then
CLASS='org.apache.hadoop.hbase.HMaster'
elif [ "$COMMAND" = "regionserver" ] ; then
diff --git a/build.xml b/build.xml
index 6235079b0bd..6b171284dac 100644
--- a/build.xml
+++ b/build.xml
@@ -5,9 +5,34 @@ Before you can run these subtargets directly, you need
to call at top-level: ant deploy-contrib compile-core-test
-->
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ hbaseshell.jline.bell.enabled
+ true
+
+ if true, enable audible keyboard bells if an alert is required.
+
+
diff --git a/src/java/org/apache/hadoop/hbase/Shell.java b/src/java/org/apache/hadoop/hbase/Shell.java
new file mode 100644
index 00000000000..0e1e089a3a7
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/Shell.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.io.IOException;
+
+import jline.ConsoleReader;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.shell.Command;
+import org.apache.hadoop.hbase.shell.HelpManager;
+import org.apache.hadoop.hbase.shell.ReturnMsg;
+import org.apache.hadoop.hbase.shell.generated.ParseException;
+import org.apache.hadoop.hbase.shell.generated.Parser;
+import org.apache.hadoop.hbase.shell.generated.TokenMgrError;
+
+/**
+ * An hbase shell.
+ *
+ * @see HBaseShell
+ */
+public class Shell {
+ /** audible keyboard bells */
+ public static final boolean DEFAULT_BELL_ENABLED = true;
+
+ /** Main method */
+ public static void main(String args[]) throws IOException {
+ Configuration conf = new HBaseConfiguration();
+ HClient client = new HClient(conf);
+ ConsoleReader reader = new ConsoleReader();
+ reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled",
+ DEFAULT_BELL_ENABLED));
+ HelpManager help = new HelpManager();
+ help.printVersion();
+ StringBuilder queryStr = new StringBuilder();
+ String extendedLine;
+ while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) {
+ if (isEndOfCommand(extendedLine)) {
+ queryStr.append(" " + extendedLine);
+ long start = System.currentTimeMillis();
+ Parser parser = new Parser(queryStr.toString());
+ ReturnMsg rs = null;
+ try {
+ Command cmd = parser.terminatedCommand();
+ if (cmd != null) {
+ rs = cmd.execute(client);
+ }
+ } catch (ParseException pe) {
+ String[] msg = pe.getMessage().split("[\n]");
+ System.out.println("Syntax error : Type 'help' for usage: " + msg[0]);
+ } catch (TokenMgrError te) {
+ System.out.println("Lexical error : Type 'help' for usage.");
+ }
+
+ long end = System.currentTimeMillis();
+
+ if (rs != null && rs.getType() > -1)
+ System.out.println(rs.getMsg()
+ + executeTime((rs.getType() == 1), start, end));
+ queryStr = new StringBuilder();
+ } else {
+ queryStr.append(" " + extendedLine);
+ }
+ }
+ System.out.println();
+ }
+
+ /** Return the boolean value indicating whether end of command or not */
+ static boolean isEndOfCommand(String line) {
+ return (line.lastIndexOf(';') > -1) ? true : false;
+ }
+
+ /** Return the string of prompt start string */
+ private static String getPrompt(final StringBuilder queryStr) {
+ return (queryStr.toString().equals("")) ? "HBase > " : " --> ";
+ }
+
+ /** return a string of code execution time. */
+ public static String executeTime(boolean watch, long start, long end) {
+ return (watch) ? "(" + String.format("%.2f", (end - start) * 0.001) + " sec)" : "";
+ }
+}
diff --git a/src/java/org/apache/hadoop/hbase/package.html b/src/java/org/apache/hadoop/hbase/package.html
index 77ab48ab4f7..7e5b84826c9 100644
--- a/src/java/org/apache/hadoop/hbase/package.html
+++ b/src/java/org/apache/hadoop/hbase/package.html
@@ -37,6 +37,10 @@ ${HBASE_HOME}/bin/stop-hbase.sh
Logs can be found in ${HADOOP_LOG_DIR}.
+To obtain a shell against a running hbase instance, run:
+
${HBASE_HOME}/bin/hbase shell
+Once the shell is up, type help;
to see list of supported commands.
+
Related Documentation
diff --git a/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java b/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java
new file mode 100644
index 00000000000..7ffdf5f01c7
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+/**
+ * @see HBaseShell
+ */
+public abstract class BasicCommand implements Command, CommandFactory {
+
+ public BasicCommand getBasicCommand() {
+ return this;
+ }
+
+ /** basic commands are their own factories. */
+ public Command getCommand() {
+ return this;
+ }
+
+}
diff --git a/src/java/org/apache/hadoop/hbase/shell/Command.java b/src/java/org/apache/hadoop/hbase/shell/Command.java
new file mode 100644
index 00000000000..e986001bf2f
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/Command.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+import org.apache.hadoop.hbase.HClient;
+
+public interface Command {
+ /** family indicator */
+ public static final String FAMILY_INDICATOR = ":";
+
+ /** Execute a command */
+ public ReturnMsg execute(HClient client);
+}
\ No newline at end of file
diff --git a/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java b/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java
new file mode 100644
index 00000000000..6b1f3a9f4f8
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java
@@ -0,0 +1,23 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+/**
+ * Parser uses command factories to create command.
+ */
+public interface CommandFactory {
+ Command getCommand();
+}
\ No newline at end of file
diff --git a/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java b/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java
new file mode 100644
index 00000000000..6b2a0d13f46
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java
@@ -0,0 +1,186 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+/**
+ * Manufactures console table, but stupid.
+ */
+public class ConsoleTable {
+ public static void printHead(String name) {
+ System.out.println("+------+----------------------+");
+ System.out.print("| No. | ");
+ System.out.printf("%-20s", name);
+ System.out.println(" |");
+ }
+
+ public static void printFoot() {
+ System.out.println("+------+----------------------+");
+ System.out.println();
+ }
+
+ public static void printTable(int count, String name) {
+ System.out.println("+------+----------------------+");
+
+ if (name.length() > 20) {
+ int interval = 20;
+
+ System.out.print("| ");
+ System.out.printf("%-4s", count + 1);
+ System.out.print(" | ");
+ System.out.printf("%-20s", name.substring(0, interval));
+ System.out.println(" |");
+
+ for (int i = 0; i < name.length() / interval; i++) {
+ System.out.print("| ");
+ System.out.printf("%-4s", "");
+ System.out.print(" | ");
+
+ int end = ((interval * i) + interval + interval);
+ if (end > name.length()) {
+ System.out.printf("%-20s", name.substring(end - interval,
+ name.length()));
+ } else {
+ System.out.printf("%-20s", name.substring(end - interval, end));
+ }
+ System.out.println(" |");
+ }
+
+ } else {
+ System.out.print("| ");
+ System.out.printf("%-4s", count + 1);
+ System.out.print(" | ");
+ System.out.printf("%-20s", name);
+ System.out.println(" |");
+ }
+ }
+
+ public static void selectHead() {
+ System.out.println("+------+----------------------+" +
+ "----------------------+----------------------+");
+ System.out.print("| No. | ");
+ System.out.printf("%-20s", "Row");
+ System.out.printf(" | ");
+ System.out.printf("%-20s", "Column");
+ System.out.printf(" | ");
+ System.out.printf("%-20s", "Cell");
+ System.out.println(" | ");
+ }
+
+ public static void printLine(int count, String key, String column,
+ String cellData) {
+ System.out.println("+------+----------------------+" +
+ "----------------------+----------------------+");
+
+ if (key.length() > 20 || column.length() > 20 || cellData.length() > 20) {
+ int interval = 20;
+ System.out.print("| ");
+ System.out.printf("%-4s", count + 1);
+ System.out.print(" | ");
+ if (key.length() > 20)
+ System.out.printf("%-20s", key.substring(0, interval));
+ else
+ System.out.printf("%-20s", key);
+ System.out.print(" | ");
+ if (column.length() > 20)
+ System.out.printf("%-20s", column.substring(0, interval));
+ else
+ System.out.printf("%-20s", column);
+ System.out.print(" | ");
+ if (cellData.length() > 20)
+ System.out.printf("%-20s", cellData.substring(0, interval));
+ else
+ System.out.printf("%-20s", cellData);
+ System.out.println(" |");
+
+ // System.out.println(getBiggerInt(new int[]{ 3, 1, 9}));
+ int biggerStrLength = getBiggerInt(new int[] { key.length(),
+ column.length(), cellData.length() });
+
+ for (int i = 0; i < (biggerStrLength / interval); i++) {
+ System.out.print("| ");
+ System.out.printf("%-4s", "");
+ System.out.print(" | ");
+
+ int end = ((interval * i) + interval + interval);
+
+ if (end > key.length()) {
+ if (key.length() > interval && end - interval < key.length()) {
+ System.out.printf("%-20s", key.substring(end - interval,
+ key.length()));
+ } else {
+ System.out.printf("%-20s", "");
+ }
+ } else {
+ System.out.printf("%-20s", key.substring(end - interval, end));
+ }
+
+ System.out.print(" | ");
+
+ if (end > column.length()) {
+ if (column.length() > interval && end - interval < column.length()) {
+ System.out.printf("%-20s", column.substring(end - interval,
+ column.length()));
+ } else {
+ System.out.printf("%-20s", "");
+ }
+ } else {
+ System.out.printf("%-20s", column.substring(end - interval, end));
+ }
+
+ System.out.print(" | ");
+ if (end > cellData.length()) {
+ if (cellData.length() > interval &&
+ end - interval < cellData.length()) {
+ System.out.printf("%-20s",
+ cellData.substring(end - interval, cellData.length()));
+ } else {
+ System.out.printf("%-20s", "");
+ }
+ } else {
+ System.out.printf("%-20s", cellData.substring(end - interval, end));
+ }
+ System.out.println(" |");
+ }
+
+ } else {
+ System.out.print("| ");
+ System.out.printf("%-4s", count + 1);
+ System.out.print(" | ");
+ System.out.printf("%-20s", key);
+ System.out.print(" | ");
+ System.out.printf("%-20s", column);
+ System.out.print(" | ");
+ System.out.printf("%-20s", cellData);
+ System.out.println(" |");
+ }
+ }
+
+ public static int getBiggerInt(int[] integers) {
+ int result = -1;
+ for (int i = 0; i < integers.length; i++) {
+ if (integers[i] > result) {
+ result = integers[i];
+ }
+ }
+ return result;
+ }
+
+ public static void selectFoot() {
+ System.out.println("+------+----------------------+" +
+ "----------------------+----------------------+");
+ System.out.println();
+ }
+}
diff --git a/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java b/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java
new file mode 100644
index 00000000000..88d745a2be7
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java
@@ -0,0 +1,68 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.hadoop.hbase.HClient;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+
+public class CreateCommand extends BasicCommand {
+ String table;
+
+ List columnfamilies;
+
+ int limit;
+
+ public ReturnMsg execute(HClient client) {
+ if (this.table == null || this.columnfamilies == null)
+ return new ReturnMsg(0, "Syntax error : Please check 'Create' syntax.");
+
+ try {
+ HTableDescriptor desc = new HTableDescriptor(this.table);
+
+ for (int i = 0; i < this.columnfamilies.size(); i++) {
+
+ String columnFamily = columnfamilies.get(i);
+ if (columnFamily.lastIndexOf(':') == (columnFamily.length() - 1)) {
+ columnFamily = columnFamily.substring(0, columnFamily.length() - 1);
+ }
+ desc.addFamily(new HColumnDescriptor(columnFamily + FAMILY_INDICATOR));
+
+ }
+
+ client.createTable(desc);
+
+ return new ReturnMsg(1, "Table created successfully.");
+ } catch (IOException e) {
+ return new ReturnMsg(0, "error msg : " + e.toString());
+ }
+ }
+
+ public void setTable(String table) {
+ this.table = table;
+ }
+
+ public void setColumnfamilies(List columnfamilies) {
+ this.columnfamilies = columnfamilies;
+ }
+
+ public void setLimit(int limit) {
+ this.limit = limit;
+ }
+}
diff --git a/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java b/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java
new file mode 100644
index 00000000000..93dd8a29573
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.hbase.HClient;
+import org.apache.hadoop.io.Text;
+
+public class DeleteCommand extends BasicCommand {
+ String table;
+
+ Map> condition;
+
+ public ReturnMsg execute(HClient client) {
+ if (this.table == null || condition == null)
+ return new ReturnMsg(0, "Syntax error : Please check 'Delete' syntax.");
+
+ try {
+ client.openTable(new Text(this.table));
+ long lockId = client.startUpdate(getRow());
+
+ if (getColumn() != null) {
+
+ client.delete(lockId, getColumn());
+
+ } else {
+ Set keySet = client.getRow(getRow()).keySet();
+ Text[] columnKey = keySet.toArray(new Text[keySet.size()]);
+
+ for (int i = 0; i < columnKey.length; i++) {
+ client.delete(lockId, columnKey[i]);
+ }
+ }
+
+ client.commit(lockId);
+
+ return new ReturnMsg(1, "1 deleted successfully. ");
+ } catch (IOException e) {
+ return new ReturnMsg(0, "error msg : " + e.toString());
+ }
+ }
+
+ public void setTable(String table) {
+ this.table = table;
+ }
+
+ public void setCondition(Map> cond) {
+ this.condition = cond;
+ }
+
+ public Text getRow() {
+ return new Text(this.condition.get("row").get(1));
+ }
+
+ public Text getColumn() {
+ if (this.condition.containsKey("column")) {
+ return new Text(this.condition.get("column").get(1));
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/src/java/org/apache/hadoop/hbase/shell/DescCommand.java b/src/java/org/apache/hadoop/hbase/shell/DescCommand.java
new file mode 100644
index 00000000000..07bbad066e4
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/DescCommand.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.HClient;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.io.Text;
+
+public class DescCommand extends BasicCommand {
+ String argument;
+
+ public ReturnMsg execute(HClient client) {
+ if (this.argument == null)
+ return new ReturnMsg(0, "Syntax error : Please check 'Describe' syntax.");
+
+ try {
+ HTableDescriptor[] tables = client.listTables();
+ Text[] columns = null;
+
+ for (int i = 0; i < tables.length; i++) {
+ if (tables[i].getName().toString().equals(this.argument)) {
+ columns = tables[i].families().keySet().toArray(new Text[] {});
+ }
+ }
+
+ if (columns == null) {
+ return new ReturnMsg(0, "Table not found.");
+ }
+
+ ConsoleTable.printHead("ColumnFamily Name");
+ for (int ii = 0; ii < columns.length; ii++) {
+ String familyName = columns[ii].toString().replace(FAMILY_INDICATOR, "");
+ ConsoleTable.printTable(ii, familyName);
+ }
+ ConsoleTable.printFoot();
+
+ return new ReturnMsg(1, columns.length + " columnfamilie(s) found.");
+ } catch (IOException e) {
+ return new ReturnMsg(0, "error msg : " + e.toString());
+ }
+ }
+
+ public void setArgument(String argument) {
+ this.argument = argument;
+ }
+}
diff --git a/src/java/org/apache/hadoop/hbase/shell/DropCommand.java b/src/java/org/apache/hadoop/hbase/shell/DropCommand.java
new file mode 100644
index 00000000000..4acbbcf0cf0
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/DropCommand.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.HClient;
+import org.apache.hadoop.io.Text;
+
+public class DropCommand extends BasicCommand {
+ String argument;
+
+ public ReturnMsg execute(HClient client) {
+ if (this.argument == null)
+ return new ReturnMsg(0, "Syntax error : Please check 'Drop' syntax.");
+
+ try {
+ client.deleteTable(new Text(this.argument));
+
+ return new ReturnMsg(1, "Table droped successfully.");
+ } catch (IOException e) {
+ return new ReturnMsg(0, "error msg : " + e.toString());
+ }
+ }
+
+ public void setArgument(String argument) {
+ this.argument = argument;
+ }
+}
diff --git a/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java b/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java
new file mode 100644
index 00000000000..5aa9b07152f
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell;
+
+import org.apache.hadoop.hbase.HClient;
+
+public class ExitCommand extends BasicCommand {
+
+ public ReturnMsg execute(HClient client) {
+ System.exit(1);
+ return null;
+ }
+
+}
diff --git a/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj b/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj
new file mode 100644
index 00000000000..2f0846a2f58
--- /dev/null
+++ b/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj
@@ -0,0 +1,474 @@
+options {
+ STATIC = false;
+ IGNORE_CASE = true;
+}
+
+PARSER_BEGIN(Parser)
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.shell.generated;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.StringReader;
+import java.io.Reader;
+
+import org.apache.hadoop.hbase.shell.*;
+
+/**
+ * Parsing command line.
+ */
+public class Parser {
+ private static String QueryString;
+
+ public Parser(String query) {
+ this((Reader)(new StringReader(query)));
+ this.QueryString = query;
+ }
+
+ public String getQueryStr() {
+ return this.QueryString;
+ }
+}
+
+PARSER_END(Parser)
+
+SKIP :
+{
+ " "
+ | "\t"
+ | "\r"
+ | "\n"
+}
+
+TOKEN:
+{
+
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ | ">
+ |
+}
+
+TOKEN :
+{
+
+ |
+ |
+ |
+ |
+}
+
+/**
+ * Parses the given array of command line arguments.
+ */
+Command terminatedCommand() :
+{
+ Command statement = null;
+}
+{
+ ([statement = cmdStatement()] ";" | )
+ {
+ return statement;
+ }
+}
+
+Command cmdStatement() :
+{
+ Command cmd = null;
+}
+{
+ (
+ cmd = exitCommand()
+ | cmd = helpCommand()
+ | cmd = showCommand()
+ | cmd = descCommand()
+ | cmd = createCommand()
+ | cmd = dropCommand()
+ | cmd = insertCommand()
+ | cmd = deleteCommand()
+ | cmd = selectCommand()
+ )
+ {
+ return cmd;
+ }
+}
+
+ExitCommand exitCommand() :
+{
+ ExitCommand exit = new ExitCommand();
+}
+{
+ { return exit; }
+}
+
+HelpCommand helpCommand() :
+{
+ Token t = null;
+ HelpCommand help = new HelpCommand();
+ String argument = "";
+}
+{
+
+ [
+ (
+ t=
+ | t=
+ | t=
+ | t=
+ | t=
+ | t=
+ | t=
+ | t=