You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2008/02/07 23:49:39 UTC
svn commit: r619678 - in /hadoop/hbase/trunk: ./
src/java/org/apache/hadoop/hbase/ src/java/org/apache/hadoop/hbase/hql/
Author: stack
Date: Thu Feb 7 14:49:37 2008
New Revision: 619678
URL: http://svn.apache.org/viewvc?rev=619678&view=rev
Log:
HBASE-56 Unnecessary HQLClient Object creation in a shell loop
Added:
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/Constants.java
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/build.xml
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Shell.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/ExitCommand.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLClient.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLSecurityManager.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HelpCommand.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=619678&r1=619677&r2=619678&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Feb 7 14:49:37 2008
@@ -25,6 +25,7 @@
HBASE-410 Speed up the test suite (make test timeout 5 instead of 15 mins).
HBASE-281 Shell should allow deletions in .META. and -ROOT- tables
(Edward Yoon & Bryan Duxbury via Stack)
+ HBASE-56 Unnecessary HQLClient Object creation in a shell loop
Branch 0.1
Modified: hadoop/hbase/trunk/build.xml
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/build.xml?rev=619678&r1=619677&r2=619678&view=diff
==============================================================================
--- hadoop/hbase/trunk/build.xml (original)
+++ hadoop/hbase/trunk/build.xml Thu Feb 7 14:49:37 2008
@@ -51,6 +51,7 @@
<property name="build.docs" value="${build.dir}/docs"/>
<property name="build.javadoc" value="${build.docs}/api"/>
<property name="build.encoding" value="ISO-8859-1"/>
+ <property name="build.src" value="${build.dir}/src"/>
<property name="test.build.dir" value="${build.dir}/test"/>
<property name="test.log.dir" value="${test.build.dir}/logs"/>
@@ -136,7 +137,7 @@
<!--Compile whats under src and generated java classes made from jsp-->
<javac
encoding="${build.encoding}"
- srcdir="${src.dir}"
+ srcdir="${src.dir};${build.src}"
includes="**/*.java"
destdir="${build.classes}"
debug="${javac.debug}"
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Shell.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Shell.java?rev=619678&r1=619677&r2=619678&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Shell.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Shell.java Thu Feb 7 14:49:37 2008
@@ -25,10 +25,11 @@
import jline.ConsoleReader;
+import org.apache.hadoop.hbase.hql.Constants;
import org.apache.hadoop.hbase.hql.HQLClient;
+import org.apache.hadoop.hbase.hql.HQLSecurityManager;
import org.apache.hadoop.hbase.hql.HelpCommand;
import org.apache.hadoop.hbase.hql.ReturnMsg;
-import org.apache.hadoop.hbase.hql.HQLSecurityManager;
import org.apache.hadoop.hbase.hql.TableFormatter;
import org.apache.hadoop.hbase.hql.TableFormatterFactory;
import org.apache.hadoop.hbase.hql.formatter.HtmlTableFormatter;
@@ -42,10 +43,9 @@
public class Shell {
/** audible keyboard bells */
public static final boolean DEFAULT_BELL_ENABLED = true;
- public static String MASTER_ADDRESS = null;
+ public static String IP = null;
+ public static int PORT = -1;
public static String HTML_OPTION = null;
- public static int RELAUNCH_FLAG = 7;
- public static int EXIT_FLAG = 9999;
/** Return the boolean value indicating whether end of command or not */
static boolean isEndOfCommand(String line) {
@@ -84,33 +84,33 @@
System.exit(1);
}
}
-
+
HBaseConfiguration conf = new HBaseConfiguration();
ConsoleReader reader = new ConsoleReader();
System.setSecurityManager(new HQLSecurityManager());
reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled",
DEFAULT_BELL_ENABLED));
Writer out = new OutputStreamWriter(System.out, "UTF-8");
- TableFormatter tableFormater = new TableFormatterFactory(out, conf).get();
- if (MASTER_ADDRESS != null) {
- conf.set("hbase.master", MASTER_ADDRESS.substring(9, MASTER_ADDRESS.length()));
- }
+ TableFormatter tableFormatter = new TableFormatterFactory(out, conf).get();
+
if (HTML_OPTION != null) {
- tableFormater = new HtmlTableFormatter(out);
+ tableFormatter = new HtmlTableFormatter(out);
}
- HelpCommand help = new HelpCommand(out, tableFormater);
- if (args.length == 0 || !args[0].equals(String.valueOf(Shell.RELAUNCH_FLAG))) {
+ HelpCommand help = new HelpCommand(out, tableFormatter);
+ if (args.length == 0 || !args[0].equals(String.valueOf(Constants.FLAG_RELAUNCH))) {
help.printVersion();
}
+
StringBuilder queryStr = new StringBuilder();
String extendedLine;
+ HQLClient hql = new HQLClient(conf, IP, PORT, out, tableFormatter);
+
while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) {
if (isEndOfCommand(extendedLine)) {
queryStr.append(" " + extendedLine);
long start = System.currentTimeMillis();
- HQLClient hql = new HQLClient(conf, MASTER_ADDRESS, out, tableFormater);
ReturnMsg rs = hql.executeQuery(queryStr.toString());
long end = System.currentTimeMillis();
@@ -132,7 +132,9 @@
private static void argumentParsing(String[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i].toLowerCase().startsWith("--master:")) {
- MASTER_ADDRESS = args[i];
+ String[] address = args[i].substring(9, args[i].length()).split(":");
+ IP = address[0];
+ PORT = Integer.valueOf(address[1]);
} else if (args[i].toLowerCase().startsWith("--html")) {
HTML_OPTION = args[i];
}
Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/Constants.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/Constants.java?rev=619678&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/Constants.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/Constants.java Thu Feb 7 14:49:37 2008
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.hql;
+
+/**
+ * Some constants used in the hql.
+ */
+public class Constants {
+ public static final int FLAG_RELAUNCH = 7;
+ public static final int FLAG_EXIT = 9999;
+
+ public static final int ERROR_CODE = -1;
+}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/ExitCommand.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/ExitCommand.java?rev=619678&r1=619677&r2=619678&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/ExitCommand.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/ExitCommand.java Thu Feb 7 14:49:37 2008
@@ -33,7 +33,7 @@
HBaseConfiguration conf) {
// TOD: Is this the best way to exit? Would be a problem if shell is run
// inside another program -- St.Ack 09/11/2007
- System.exit(Shell.EXIT_FLAG);
+ System.exit(Constants.FLAG_EXIT);
return null;
}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLClient.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLClient.java?rev=619678&r1=619677&r2=619678&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLClient.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLClient.java Thu Feb 7 14:49:37 2008
@@ -26,37 +26,55 @@
import org.apache.hadoop.hbase.hql.generated.ParseException;
import org.apache.hadoop.hbase.hql.generated.TokenMgrError;
+/**
+ * HQL query language service client interfaces.
+ */
public class HQLClient {
- public static String MASTER_ADDRESS = null;
static HBaseConfiguration conf;
- static TableFormatter tableFormater;
- static Writer out;
+ static TableFormatter tableFormatter = null;
+ static Writer out = null;
- public HQLClient(HBaseConfiguration config, String master, Writer output,
+ /**
+ * Constructor
+ *
+ * @param config HBaseConfiguration
+ * @param ip IP Address
+ * @param port port number
+ * @param writer writer
+ * @param formatter table formatter
+ */
+ public HQLClient(HBaseConfiguration config, String ip, int port, Writer writer,
TableFormatter formatter) {
conf = config;
- out = output;
- tableFormater = formatter;
- MASTER_ADDRESS = master;
+ if (ip != null && port != -1)
+ conf.set("hbase.master", ip + ":" + port);
+ out = writer;
+ tableFormatter = formatter;
}
+ /**
+ * Executes query.
+ *
+ * @param query
+ * @return ReturnMsg object
+ */
public ReturnMsg executeQuery(String query) {
- HQLParser parser = new HQLParser(query, out, tableFormater);
- ReturnMsg rs = null;
+ HQLParser parser = new HQLParser(query, out, tableFormatter);
+ ReturnMsg msg = null;
try {
Command cmd = parser.terminatedCommand();
if (cmd != null) {
- rs = cmd.execute(conf);
+ msg = cmd.execute(conf);
}
} catch (ParseException pe) {
- String[] msg = pe.getMessage().split("[\n]");
- rs = new ReturnMsg(-9, "Syntax error : Type 'help;' for usage.\nMessage : " + msg[0]);
+ msg = new ReturnMsg(Constants.ERROR_CODE,
+ "Syntax error : Type 'help;' for usage.");
} catch (TokenMgrError te) {
- String[] msg = te.getMessage().split("[\n]");
- rs = new ReturnMsg(-9, "Lexical error : Type 'help;' for usage.\nMessage : " + msg[0]);
+ msg = new ReturnMsg(Constants.ERROR_CODE,
+ "Lexical error : Type 'help;' for usage.");
}
- return rs;
+ return msg;
}
-}
\ No newline at end of file
+}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLSecurityManager.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLSecurityManager.java?rev=619678&r1=619677&r2=619678&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLSecurityManager.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HQLSecurityManager.java Thu Feb 7 14:49:37 2008
@@ -43,7 +43,7 @@
*/
@SuppressWarnings("static-access")
public void checkExit(int status) {
- if (status != Shell.EXIT_FLAG) {
+ if (status != Constants.FLAG_EXIT) {
// throw new ExitException(status);
// I didn't figure out How can catch the ExitException in shell main.
@@ -51,11 +51,11 @@
Shell shell = new Shell();
List<String> argList = new ArrayList<String>();
- argList.add(String.valueOf(Shell.RELAUNCH_FLAG));
+ argList.add(String.valueOf(Constants.FLAG_RELAUNCH));
if(Shell.HTML_OPTION != null)
argList.add(Shell.HTML_OPTION);
- if(Shell.MASTER_ADDRESS != null)
- argList.add(Shell.MASTER_ADDRESS);
+ if(Shell.IP != null && Shell.PORT != -1)
+ argList.add("--master:" + Shell.IP + ":" + Shell.PORT);
try {
shell.main(argList.toArray(new String[] {}));
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HelpCommand.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HelpCommand.java?rev=619678&r1=619677&r2=619678&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HelpCommand.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/hql/HelpCommand.java Thu Feb 7 14:49:37 2008
@@ -27,6 +27,7 @@
import java.util.Map;
import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.util.VersionInfo;
public class HelpCommand extends BasicCommand {
private String argument;
@@ -34,10 +35,7 @@
"Description", "Example" };
/** application name */
- public static final String APP_NAME = "Hbase Shell";
-
- /** version of the code */
- public static final String APP_VERSION = "0.0.2";
+ public static final String APP_NAME = "HQL";
/** help contents map */
public final Map<String, String[]> help = new HashMap<String, String[]>();
@@ -135,8 +133,8 @@
* @throws IOException
*/
public void printVersion() throws IOException {
- println(APP_NAME + ", " + APP_VERSION + " version.\n"
- + "Copyright (c) 2007 by udanax, "
+ println(APP_NAME + ", " + VersionInfo.getVersion() + " version.\n"
+ + "Copyright (c) 2008 by udanax, "
+ "licensed to Apache Software Foundation.\n"
+ "Type 'help;' for usage.\n");
}