Return-Path: Delivered-To: apmail-lucene-hadoop-commits-archive@locus.apache.org Received: (qmail 8036 invoked from network); 11 Jul 2007 21:54:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Jul 2007 21:54:42 -0000 Received: (qmail 29336 invoked by uid 500); 11 Jul 2007 21:54:44 -0000 Delivered-To: apmail-lucene-hadoop-commits-archive@lucene.apache.org Received: (qmail 29299 invoked by uid 500); 11 Jul 2007 21:54:44 -0000 Mailing-List: contact hadoop-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hadoop-dev@lucene.apache.org Delivered-To: mailing list hadoop-commits@lucene.apache.org Received: (qmail 29203 invoked by uid 99); 11 Jul 2007 21:54:44 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jul 2007 14:54:44 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jul 2007 14:54:38 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 42FBC1A981A; Wed, 11 Jul 2007 14:54:18 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r555415 [1/2] - in /lucene/hadoop/trunk/src/contrib/hbase: ./ bin/ conf/ src/java/org/apache/hadoop/hbase/ src/java/org/apache/hadoop/hbase/shell/ src/java/org/apache/hadoop/hbase/shell/generated/ src/test/org/apache/hadoop/hbase/shell/ Date: Wed, 11 Jul 2007 21:54:17 -0000 To: hadoop-commits@lucene.apache.org From: stack@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070711215418.42FBC1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: stack Date: Wed Jul 11 14:54:15 2007 New Revision: 555415 URL: http://svn.apache.org/viewvc?view=rev&rev=555415 Log: HADOOP-1375 a simple parser for hbase M src/contrib/hbase/NOTICE.txt Add notice of udanax contributions. Msrc/contrib/hbase/conf/hbase-default.xml (hbaseshell.jline.bell.enabled): Added. M src/contrib/hbase/CHANGES.txt (hadoop-1375) Added. M src/contrib/hbase/src/java/org/apache/hadoop/hbase/package.html Add note on how to start up hbase shell M src/contrib/hbase/bin/hbase Add 'shell'. Remove 'client' (shell does what it used do and more). Removed all reader and logreader until better developed. Starting up a reader or logreader on a running hbase system could do damage). M src/contrib/hbase/build.xml Add a javacc target to generate content of shell/generated subpackage. A src/contrib/hbase/src/test/org/apache/hadoop/hbase/shell/TestHBaseShell.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpContents.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShowCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpManager.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ReturnMsg.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpCommand.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj Added. A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Token.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/TokenMgrError.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/SimpleCharStream.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserTokenManager.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParseException.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserConstants.java A src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Parser.java Added javacc generated files. Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpContents.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HelpManager.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ReturnMsg.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ShowCommand.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParseException.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Parser.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserConstants.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/ParserTokenManager.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/SimpleCharStream.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/Token.java lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/generated/TokenMgrError.java lucene/hadoop/trunk/src/contrib/hbase/src/test/org/apache/hadoop/hbase/shell/ lucene/hadoop/trunk/src/contrib/hbase/src/test/org/apache/hadoop/hbase/shell/TestHBaseShell.java Modified: lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt lucene/hadoop/trunk/src/contrib/hbase/NOTICE.txt lucene/hadoop/trunk/src/contrib/hbase/bin/hbase lucene/hadoop/trunk/src/contrib/hbase/build.xml lucene/hadoop/trunk/src/contrib/hbase/conf/hbase-default.xml lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/package.html Modified: lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt?view=diff&rev=555415&r1=555414&r2=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt (original) +++ lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt Wed Jul 11 14:54:15 2007 @@ -56,5 +56,4 @@ 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) Modified: lucene/hadoop/trunk/src/contrib/hbase/NOTICE.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/NOTICE.txt?view=diff&rev=555415&r1=555414&r2=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/NOTICE.txt (original) +++ lucene/hadoop/trunk/src/contrib/hbase/NOTICE.txt Wed Jul 11 14:54:15 2007 @@ -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) Modified: lucene/hadoop/trunk/src/contrib/hbase/bin/hbase URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/bin/hbase?view=diff&rev=555415&r1=555414&r2=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/bin/hbase (original) +++ lucene/hadoop/trunk/src/contrib/hbase/bin/hbase Wed Jul 11 14:54:15 2007 @@ -38,9 +38,7 @@ 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 @@ 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 Modified: lucene/hadoop/trunk/src/contrib/hbase/build.xml URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/build.xml?view=diff&rev=555415&r1=555414&r2=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/build.xml (original) +++ lucene/hadoop/trunk/src/contrib/hbase/build.xml Wed Jul 11 14:54:15 2007 @@ -5,9 +5,34 @@ 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. + + Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/Shell.java Wed Jul 11 14:54:15 2007 @@ -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)" : ""; + } +} Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/package.html URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/package.html?view=diff&rev=555415&r1=555414&r2=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/package.html (original) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/package.html Wed Jul 11 14:54:15 2007 @@ -37,6 +37,10 @@ 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

Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/BasicCommand.java Wed Jul 11 14:54:15 2007 @@ -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; + } + +} Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/Command.java Wed Jul 11 14:54:15 2007 @@ -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 Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CommandFactory.java Wed Jul 11 14:54:15 2007 @@ -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 Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java Wed Jul 11 14:54:15 2007 @@ -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(); + } +} Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java Wed Jul 11 14:54:15 2007 @@ -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; + } +} Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java Wed Jul 11 14:54:15 2007 @@ -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; + } + } +} Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DescCommand.java Wed Jul 11 14:54:15 2007 @@ -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; + } +} Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/DropCommand.java Wed Jul 11 14:54:15 2007 @@ -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; + } +} Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ExitCommand.java Wed Jul 11 14:54:15 2007 @@ -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; + } + +} Added: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj?view=auto&rev=555415 ============================================================================== --- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj (added) +++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/HBaseShell.jj Wed Jul 11 14:54:15 2007 @@ -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= + argument = getString() + { + select.setTable(argument); + } + + [ cond = WhereClause() { + try{ + select.setCondition(cond); + }catch(ClassCastException ce) { + throw generateParseException(); + } + } ] + + [ limit = getInt() { + try{ + select.setLimit(limit); + }catch(ClassCastException ce) { + throw generateParseException(); + } + } ] + { return select; } +} + +/** +* TODO : expressions codes need more love. +*/ + +String getString(): +{ Token t = null; } +{ + ( t= + | t= + ) + { return t.image.toString(); } +} + +int getInt(): +{ Token t = null; } +{ + t = + { return Integer.parseInt(t.image.toString()); } +} + +Map> WhereClause() : +{ + Map> result = + new HashMap>(); + List exception = + new ArrayList(); +} +{ + { + try{ + result.putAll(ConditionExpression()); + }catch(ParseException pe) { + exception.add(pe.toString()); + result.put("error", exception); + } + } + ( + { + try{ + result.putAll(ConditionExpression()); + }catch(ParseException pe) { + exception.add(pe.toString()); + result.put("error", exception); + } + } + )* + + { return result; } +} + +Map> ConditionExpression() : +{ + Token tSearchName, tComparator, tComparand; + Map> tmp = + new HashMap>(); + List values = + new ArrayList(); +} +{ + ( + tSearchName= + | tSearchName= + | tSearchName=