Skip to content

Commit

Permalink
HADOOP-1375 a simple parser for hbase
Browse files Browse the repository at this point in the history
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.


git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@555415 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
saintstack committed Jul 11, 2007
1 parent f613907 commit 87f5d5d
Show file tree
Hide file tree
Showing 32 changed files with 4,543 additions and 14 deletions.
3 changes: 1 addition & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 5 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 3 additions & 9 deletions bin/hbase
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ esac
if [ $# = 0 ]; then
echo "Usage: hbase [--hadoop=hadoopdir] <command>"
echo "where <command> 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"
Expand Down Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,34 @@ Before you can run these subtargets directly, you need
to call at top-level: ant deploy-contrib compile-core-test
-->
<project name="hbase" default="jar">

<import file="../build-contrib.xml"/>

<target name="javacc" if="javacc.home">
<echo message="javacc.home: ${javacc.home}"/>
<property name="hbaseshell.src.dir"
value="${src.dir}/org/apache/hadoop/hbase/shell" />
<mkdir dir="${hbaseshell.src.dir}/generated" />
<javacc
target="${hbaseshell.src.dir}/HBaseShell.jj"
outputdirectory="${hbaseshell.src.dir}/generated"
javacchome="${javacc.home}"
/>
</target>

<target name="compile" depends="init,javacc">
<echo message="contrib: ${name}"/>
<javac
encoding="${build.encoding}"
srcdir="${src.dir}"
includes="**/*.java"
destdir="${build.classes}"
debug="${javac.debug}"
deprecation="${javac.deprecation}">
<classpath refid="classpath"/>
<classpath path="path"/>
</javac>
</target>

<!-- Override jar target to specify main class -->
<target name="jar" depends="compile">
<jar
Expand Down
9 changes: 9 additions & 0 deletions conf/hbase-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,13 @@
value + (value / 2), the HRegion is split in two. Default: 128M.
</description>
</property>

<!-- HbaseShell Configurations -->
<property>
<name>hbaseshell.jline.bell.enabled</name>
<value>true</value>
<description>
if true, enable audible keyboard bells if an alert is required.
</description>
</property>
</configuration>
95 changes: 95 additions & 0 deletions src/java/org/apache/hadoop/hbase/Shell.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://wiki.apache.org/lucene-hadoop/Hbase/HbaseShell">HBaseShell</a>
*/
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)" : "";
}
}
4 changes: 4 additions & 0 deletions src/java/org/apache/hadoop/hbase/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ <h2>Getting Started</h2>
</pre>
Logs can be found in ${HADOOP_LOG_DIR}.
</p>
<p>To obtain a shell against a running hbase instance, run:
<pre>${HBASE_HOME}/bin/hbase shell</pre>
Once the shell is up, type <code>help;</code> to see list of supported commands.
</p>

<h2>Related Documentation</h2>

Expand Down
32 changes: 32 additions & 0 deletions src/java/org/apache/hadoop/hbase/shell/BasicCommand.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://wiki.apache.org/lucene-hadoop/Hbase/HbaseShell">HBaseShell</a>
*/
public abstract class BasicCommand implements Command, CommandFactory {

public BasicCommand getBasicCommand() {
return this;
}

/** basic commands are their own factories. */
public Command getCommand() {
return this;
}

}
26 changes: 26 additions & 0 deletions src/java/org/apache/hadoop/hbase/shell/Command.java
Original file line number Diff line number Diff line change
@@ -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);
}
23 changes: 23 additions & 0 deletions src/java/org/apache/hadoop/hbase/shell/CommandFactory.java
Original file line number Diff line number Diff line change
@@ -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();
}
Loading

0 comments on commit 87f5d5d

Please sign in to comment.