forked from apache/hbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@555415 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
1 parent
f613907
commit 87f5d5d
Showing
32 changed files
with
4,543 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" : ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
src/java/org/apache/hadoop/hbase/shell/CommandFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.