HBASE-56 Unnecessary HQLClient Object creation in a shell loop
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@619678 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
93a31f6a16
commit
aa12579a3c
|
@ -25,6 +25,7 @@ HBase Change Log
|
||||||
HBASE-410 Speed up the test suite (make test timeout 5 instead of 15 mins).
|
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
|
HBASE-281 Shell should allow deletions in .META. and -ROOT- tables
|
||||||
(Edward Yoon & Bryan Duxbury via Stack)
|
(Edward Yoon & Bryan Duxbury via Stack)
|
||||||
|
HBASE-56 Unnecessary HQLClient Object creation in a shell loop
|
||||||
|
|
||||||
Branch 0.1
|
Branch 0.1
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
<property name="build.docs" value="${build.dir}/docs"/>
|
<property name="build.docs" value="${build.dir}/docs"/>
|
||||||
<property name="build.javadoc" value="${build.docs}/api"/>
|
<property name="build.javadoc" value="${build.docs}/api"/>
|
||||||
<property name="build.encoding" value="ISO-8859-1"/>
|
<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.build.dir" value="${build.dir}/test"/>
|
||||||
<property name="test.log.dir" value="${test.build.dir}/logs"/>
|
<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-->
|
<!--Compile whats under src and generated java classes made from jsp-->
|
||||||
<javac
|
<javac
|
||||||
encoding="${build.encoding}"
|
encoding="${build.encoding}"
|
||||||
srcdir="${src.dir}"
|
srcdir="${src.dir};${build.src}"
|
||||||
includes="**/*.java"
|
includes="**/*.java"
|
||||||
destdir="${build.classes}"
|
destdir="${build.classes}"
|
||||||
debug="${javac.debug}"
|
debug="${javac.debug}"
|
||||||
|
|
|
@ -25,10 +25,11 @@ import java.io.Writer;
|
||||||
|
|
||||||
import jline.ConsoleReader;
|
import jline.ConsoleReader;
|
||||||
|
|
||||||
|
import org.apache.hadoop.hbase.hql.Constants;
|
||||||
import org.apache.hadoop.hbase.hql.HQLClient;
|
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.HelpCommand;
|
||||||
import org.apache.hadoop.hbase.hql.ReturnMsg;
|
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.TableFormatter;
|
||||||
import org.apache.hadoop.hbase.hql.TableFormatterFactory;
|
import org.apache.hadoop.hbase.hql.TableFormatterFactory;
|
||||||
import org.apache.hadoop.hbase.hql.formatter.HtmlTableFormatter;
|
import org.apache.hadoop.hbase.hql.formatter.HtmlTableFormatter;
|
||||||
|
@ -42,10 +43,9 @@ import org.apache.hadoop.hbase.hql.formatter.HtmlTableFormatter;
|
||||||
public class Shell {
|
public class Shell {
|
||||||
/** audible keyboard bells */
|
/** audible keyboard bells */
|
||||||
public static final boolean DEFAULT_BELL_ENABLED = true;
|
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 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 */
|
/** Return the boolean value indicating whether end of command or not */
|
||||||
static boolean isEndOfCommand(String line) {
|
static boolean isEndOfCommand(String line) {
|
||||||
|
@ -91,26 +91,26 @@ public class Shell {
|
||||||
reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled",
|
reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled",
|
||||||
DEFAULT_BELL_ENABLED));
|
DEFAULT_BELL_ENABLED));
|
||||||
Writer out = new OutputStreamWriter(System.out, "UTF-8");
|
Writer out = new OutputStreamWriter(System.out, "UTF-8");
|
||||||
TableFormatter tableFormater = new TableFormatterFactory(out, conf).get();
|
TableFormatter tableFormatter = new TableFormatterFactory(out, conf).get();
|
||||||
if (MASTER_ADDRESS != null) {
|
|
||||||
conf.set("hbase.master", MASTER_ADDRESS.substring(9, MASTER_ADDRESS.length()));
|
|
||||||
}
|
|
||||||
if (HTML_OPTION != null) {
|
if (HTML_OPTION != null) {
|
||||||
tableFormater = new HtmlTableFormatter(out);
|
tableFormatter = new HtmlTableFormatter(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
HelpCommand help = new HelpCommand(out, tableFormater);
|
HelpCommand help = new HelpCommand(out, tableFormatter);
|
||||||
if (args.length == 0 || !args[0].equals(String.valueOf(Shell.RELAUNCH_FLAG))) {
|
if (args.length == 0 || !args[0].equals(String.valueOf(Constants.FLAG_RELAUNCH))) {
|
||||||
help.printVersion();
|
help.printVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder queryStr = new StringBuilder();
|
StringBuilder queryStr = new StringBuilder();
|
||||||
String extendedLine;
|
String extendedLine;
|
||||||
|
HQLClient hql = new HQLClient(conf, IP, PORT, out, tableFormatter);
|
||||||
|
|
||||||
while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) {
|
while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) {
|
||||||
if (isEndOfCommand(extendedLine)) {
|
if (isEndOfCommand(extendedLine)) {
|
||||||
queryStr.append(" " + extendedLine);
|
queryStr.append(" " + extendedLine);
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
HQLClient hql = new HQLClient(conf, MASTER_ADDRESS, out, tableFormater);
|
|
||||||
ReturnMsg rs = hql.executeQuery(queryStr.toString());
|
ReturnMsg rs = hql.executeQuery(queryStr.toString());
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
|
@ -132,7 +132,9 @@ public class Shell {
|
||||||
private static void argumentParsing(String[] args) {
|
private static void argumentParsing(String[] args) {
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if (args[i].toLowerCase().startsWith("--master:")) {
|
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")) {
|
} else if (args[i].toLowerCase().startsWith("--html")) {
|
||||||
HTML_OPTION = args[i];
|
HTML_OPTION = args[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ public class ExitCommand extends BasicCommand {
|
||||||
HBaseConfiguration conf) {
|
HBaseConfiguration conf) {
|
||||||
// TOD: Is this the best way to exit? Would be a problem if shell is run
|
// TOD: Is this the best way to exit? Would be a problem if shell is run
|
||||||
// inside another program -- St.Ack 09/11/2007
|
// inside another program -- St.Ack 09/11/2007
|
||||||
System.exit(Shell.EXIT_FLAG);
|
System.exit(Constants.FLAG_EXIT);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,37 +26,55 @@ import org.apache.hadoop.hbase.hql.generated.HQLParser;
|
||||||
import org.apache.hadoop.hbase.hql.generated.ParseException;
|
import org.apache.hadoop.hbase.hql.generated.ParseException;
|
||||||
import org.apache.hadoop.hbase.hql.generated.TokenMgrError;
|
import org.apache.hadoop.hbase.hql.generated.TokenMgrError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HQL query language service client interfaces.
|
||||||
|
*/
|
||||||
public class HQLClient {
|
public class HQLClient {
|
||||||
public static String MASTER_ADDRESS = null;
|
|
||||||
static HBaseConfiguration conf;
|
static HBaseConfiguration conf;
|
||||||
static TableFormatter tableFormater;
|
static TableFormatter tableFormatter = null;
|
||||||
static Writer out;
|
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) {
|
TableFormatter formatter) {
|
||||||
conf = config;
|
conf = config;
|
||||||
out = output;
|
if (ip != null && port != -1)
|
||||||
tableFormater = formatter;
|
conf.set("hbase.master", ip + ":" + port);
|
||||||
MASTER_ADDRESS = master;
|
out = writer;
|
||||||
|
tableFormatter = formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes query.
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
* @return ReturnMsg object
|
||||||
|
*/
|
||||||
public ReturnMsg executeQuery(String query) {
|
public ReturnMsg executeQuery(String query) {
|
||||||
HQLParser parser = new HQLParser(query, out, tableFormater);
|
HQLParser parser = new HQLParser(query, out, tableFormatter);
|
||||||
ReturnMsg rs = null;
|
ReturnMsg msg = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Command cmd = parser.terminatedCommand();
|
Command cmd = parser.terminatedCommand();
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
rs = cmd.execute(conf);
|
msg = cmd.execute(conf);
|
||||||
}
|
}
|
||||||
} catch (ParseException pe) {
|
} catch (ParseException pe) {
|
||||||
String[] msg = pe.getMessage().split("[\n]");
|
msg = new ReturnMsg(Constants.ERROR_CODE,
|
||||||
rs = new ReturnMsg(-9, "Syntax error : Type 'help;' for usage.\nMessage : " + msg[0]);
|
"Syntax error : Type 'help;' for usage.");
|
||||||
} catch (TokenMgrError te) {
|
} catch (TokenMgrError te) {
|
||||||
String[] msg = te.getMessage().split("[\n]");
|
msg = new ReturnMsg(Constants.ERROR_CODE,
|
||||||
rs = new ReturnMsg(-9, "Lexical error : Type 'help;' for usage.\nMessage : " + msg[0]);
|
"Lexical error : Type 'help;' for usage.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return rs;
|
return msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,7 @@ public class HQLSecurityManager extends SecurityManager {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
public void checkExit(int status) {
|
public void checkExit(int status) {
|
||||||
if (status != Shell.EXIT_FLAG) {
|
if (status != Constants.FLAG_EXIT) {
|
||||||
// throw new ExitException(status);
|
// throw new ExitException(status);
|
||||||
|
|
||||||
// I didn't figure out How can catch the ExitException in shell main.
|
// I didn't figure out How can catch the ExitException in shell main.
|
||||||
|
@ -51,11 +51,11 @@ public class HQLSecurityManager extends SecurityManager {
|
||||||
Shell shell = new Shell();
|
Shell shell = new Shell();
|
||||||
|
|
||||||
List<String> argList = new ArrayList<String>();
|
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)
|
if(Shell.HTML_OPTION != null)
|
||||||
argList.add(Shell.HTML_OPTION);
|
argList.add(Shell.HTML_OPTION);
|
||||||
if(Shell.MASTER_ADDRESS != null)
|
if(Shell.IP != null && Shell.PORT != -1)
|
||||||
argList.add(Shell.MASTER_ADDRESS);
|
argList.add("--master:" + Shell.IP + ":" + Shell.PORT);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shell.main(argList.toArray(new String[] {}));
|
shell.main(argList.toArray(new String[] {}));
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
|
import org.apache.hadoop.hbase.util.VersionInfo;
|
||||||
|
|
||||||
public class HelpCommand extends BasicCommand {
|
public class HelpCommand extends BasicCommand {
|
||||||
private String argument;
|
private String argument;
|
||||||
|
@ -34,10 +35,7 @@ public class HelpCommand extends BasicCommand {
|
||||||
"Description", "Example" };
|
"Description", "Example" };
|
||||||
|
|
||||||
/** application name */
|
/** application name */
|
||||||
public static final String APP_NAME = "Hbase Shell";
|
public static final String APP_NAME = "HQL";
|
||||||
|
|
||||||
/** version of the code */
|
|
||||||
public static final String APP_VERSION = "0.0.2";
|
|
||||||
|
|
||||||
/** help contents map */
|
/** help contents map */
|
||||||
public final Map<String, String[]> help = new HashMap<String, String[]>();
|
public final Map<String, String[]> help = new HashMap<String, String[]>();
|
||||||
|
@ -135,8 +133,8 @@ public class HelpCommand extends BasicCommand {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void printVersion() throws IOException {
|
public void printVersion() throws IOException {
|
||||||
println(APP_NAME + ", " + APP_VERSION + " version.\n"
|
println(APP_NAME + ", " + VersionInfo.getVersion() + " version.\n"
|
||||||
+ "Copyright (c) 2007 by udanax, "
|
+ "Copyright (c) 2008 by udanax, "
|
||||||
+ "licensed to Apache Software Foundation.\n"
|
+ "licensed to Apache Software Foundation.\n"
|
||||||
+ "Type 'help;' for usage.\n");
|
+ "Type 'help;' for usage.\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue