Permalink
Browse files

HIVE-3100. Add HiveCLI that runs over JDBC (Prasad Mujumdar via cws)

git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1356516 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent bf339f7 commit ca6980d326ab86171dfba262ea1efa01c0002676 Carl Steinbach committed Jul 2, 2012
View
@@ -416,6 +416,21 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
+For the SQLLine package:
+
+Copyright (c) 2002, 2003, 2004, 2005 Marc Prud'hommeaux
+
+From: http://sqlline.sourceforge.net/#license
+
+"SQLLine is distributed under the BSD License, meaning that you are free to redistribute, modify, or sell the software with almost no restrictions."
+
+Statement from Marc Prud'hommeaux regarding inconsistent licenses in some SQLLine source files:
+
+> SQLLine was once GPL, but it was changed to be BSD a few years back.
+> Any references to the GPL are vestigial. Hopefully the license
+> declaration at http://sqlline.sourceforge.net/#license is sufficiently
+> authoritative in this regard.
+
For the SLF4J library:
@@ -465,4 +480,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-
+
View
@@ -22,11 +22,14 @@ Copyright (c) 2002 JSON.org
This product includes/uses JLine (http://jline.sourceforge.net/),
Copyright (c) 2002-2006, Marc Prud'hommeaux <mwp1@cornell.edu>.
+This product includes/uses SQLLine (http://sqlline.sourceforge.net),
+Copyright (c) 2002, 2003, 2004, 2005 Marc Prud'hommeaux <mwp1@cornell.edu>.
+
This product includes/uses SLF4J (http://www.slf4j.org/),
Copyright (c) 2004-2008 QOS.ch
This product includes/uses Bootstrap (http://twitter.github.com/bootstrap/),
Copyright (c) 2012 Twitter, Inc.
This product includes/uses Glyphicons (http://glyphicons.com/),
-Copyright (c) 2010 - 2012 Jan Kovarík
+Copyright (c) 2010 - 2012 Jan Kovarík
View
@@ -0,0 +1,30 @@
+# 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.
+
+# Need arguments [host [port [db]]]
+THISSERVICE=beeline
+export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} "
+
+beeline () {
+
+ CLASS=org.apache.hive.jdbc.beeline.HiveBeeline;
+ execHiveCmd $CLASS "$@"
+}
+
+beeline_help () {
+ CLASS=org.apache.hive.jdbc.beeline.HiveBeeline;
+ execHiveCmd $CLASS "--help"
+}
+
@@ -49,6 +49,7 @@
<classpathentry kind="lib" path="build/ivy/lib/default/avro-@avro.version@.jar"/>
<classpathentry kind="lib" path="build/ivy/lib/default/avro-mapred-@avro.version@.jar"/>
<classpathentry kind="lib" path="build/ivy/lib/default/jline-@jline.version@.jar"/>
+ <classpathentry kind="lib" path="build/ivy/lib/default/sqlline-@sqlline.version@.jar"/>
<classpathentry kind="lib" path="build/ivy/lib/default/json-@json.version@.jar"/>
<classpathentry kind="lib" path="build/ivy/lib/default/asm-@asm.version@.jar"/>
<classpathentry kind="lib" path="build/ivy/lib/default/commons-compress-@commons-compress.version@.jar"/>
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ 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.
+-->
+<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
+ <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="false"/>
+ <mapAttribute key="org.eclipse.debug.core.environmentVariables">
+ <mapEntry key="JAVA_HOME" value="${system_property:java.home}"/>
+ <mapEntry key="HIVE_HADOOP_TEST_CLASSPATH" value="@HIVE_HADOOP_TEST_CLASSPATH@"/>
+ </mapAttribute>
+
+ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+ <listEntry value="/hive/cli/src/java/org/apache/hive/jdbc/HiveBeeline.java"/>
+ </listAttribute>
+
+ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+ <listEntry value="1"/>
+ </listAttribute>
+
+ <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
+ <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;@PROJECT@&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
+ <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@PROJECT@/conf&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
+ <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@PROJECT@/common/src/java/conf&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
+ <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@PROJECT@/build/metastore/hive-metastore-@HIVE_VERSION@.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
+ <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;@PROJECT@&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
+ <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@PROJECT@/build/ql/hive-exec-@HIVE_VERSION@.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
+ </listAttribute>
+
+
+ <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
+ <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.hive.jdbc.beeline.HiveBeeline"/>
+ <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="@PROJECT@"/>
+ <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS"
+ value="@JVM_ARGS@ -Dhive.root.logger=INFO,console -Dhadoop.bin.path=@HADOOP_BIN_PATH@"/>
+
+</launchConfiguration>
View
@@ -35,6 +35,7 @@
<property name="maven2.pattern" value="[organisation]/[module]/[revision]/[module]-[revision](-[classifier])"/>
<property name="repo.dir" value="${user.home}/.m2/repository"/>
<property name="maven2.pattern.ext" value="${maven2.pattern}.[ext]"/>
+ <property name="sourceforge-repo" value="http://www.sourceforge.net/projects"/>
<property name="resolvers" value="default" override="false"/>
<!-- pull in the local repository -->
<include url="${ivy.default.conf.dir}/ivyconf-local.xml"/>
@@ -50,6 +51,10 @@
<artifact pattern="${datanucleus.repo}/[organisation]/[module]/[revision]/[module]-[revision].[ext]"/>
</url>
+ <url name="sourceforge" m2compatible="false" checksums="">
+ <artifact pattern="${sourceforge-repo}/[module]/files/[module]/[branch]/[module]-[revision].[ext]"/>
+ </url>
+
<filesystem name="fs" m2compatible="true" force="true">
<artifact pattern="${repo.dir}/org/apache/hadoop/[module]/[revision]/[module]-[revision].[ext]"/>
<ivy pattern="${repo.dir}/org/apache/hadoop/[module]/[revision]/[module]-[revision].pom"/>
@@ -62,6 +67,7 @@
<resolver ref="apache-snapshot"/>
<resolver ref="maven2"/>
<resolver ref="datanucleus-repo"/>
+ <resolver ref="sourceforge"/>
</chain>
<chain name="internal" dual="true">
@@ -50,6 +50,8 @@ jdo-api.version=2.3-ec
jdom.version=1.1
jetty.version=6.1.26
jline.version=0.9.94
+sqlline.version=1_0_2
+sqlline.branch=1.0.2
json.version=20090211
junit.version=4.10
libfb303.version=0.7.0
View
@@ -33,6 +33,8 @@
transitive="false"/>
<dependency org="commons-logging" name="commons-logging" rev="${commons-logging.version}"
transitive="false"/>
+ <dependency org="sqlline" name="sqlline" rev="${sqlline.version}" branch="${sqlline.branch}"
+ transitive="false"/>
<!-- Test Dependencies -->
<dependency org="junit" name="junit" rev="${junit.version}" conf="test->default" />
@@ -0,0 +1,112 @@
+/**
+ * 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.hive.jdbc.beeline;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hive.jdbc.beeline.OptionsProcessor.PrintMode;
+import sqlline.SqlLine;
+
+public class HiveBeeline {
+
+ // TODO: expose from the JDBC connection class
+ private static final String URI_PREFIX = "jdbc:hive://";
+ private static final String SQLLINE_CLASS = "sqlline.SqlLine";
+ private static final String HIVE_JDBC_DRIVER = "org.apache.hadoop.hive.jdbc.HiveDriver";
+ private static final String SQLLINE_SILENT = "--silent=true";
+ private static final String SQLLINE_VERBOSE = "--verbose=true";
+ private static final String SQLLINE_SCRIPT_CMD = "!run";
+ private static final String URL_DB_MARKER = "/";
+ private static final String URL_HIVE_CONF_MARKER = "?";
+ private static final String URL_HIVE_VAR_MARKER = "#";
+ private static final String URL_SESS_VAR_MARKER = ";";
+
+ public static void main(String[] args) throws Exception {
+ OptionsProcessor oproc = new OptionsProcessor();
+ if (!oproc.processArgs(args)) {
+ System.exit(1);
+ }
+
+ // assemble connection URL
+ String jdbcURL = URI_PREFIX;
+ if (oproc.getHost() != null) {
+ // no, host name indicates an embbeded hive invocation
+ jdbcURL += oproc.getHost() + ":" + oproc.getPort();
+ }
+
+ if (!oproc.getDatabase().isEmpty()) {
+ jdbcURL += URL_DB_MARKER + oproc.getDatabase();
+ }
+ if (!oproc.getSessVars().isEmpty()) {
+ jdbcURL += URL_SESS_VAR_MARKER + oproc.getSessVars();
+ }
+ if (!oproc.getHiveConfs().isEmpty()) {
+ jdbcURL += URL_HIVE_CONF_MARKER + oproc.getHiveConfs();
+ }
+ if (!oproc.getHiveVars().isEmpty()) {
+ jdbcURL += URL_HIVE_VAR_MARKER + oproc.getHiveVars();
+ }
+
+ // setup input file or string
+ InputStream sqlLineInput = null;
+ if (oproc.getFileName() != null) {
+ String scriptCmd = SQLLINE_SCRIPT_CMD + " " + oproc.getFileName().trim() + "\n";
+ sqlLineInput = new ByteArrayInputStream(scriptCmd.getBytes());
+ } else if (oproc.getExecString() != null) {
+ // process the string to make each stmt a separate line
+ String execString = oproc.getExecString().trim();
+ String execCommand = "";
+ String command = "";
+ for (String oneCmd : execString.split(";")) {
+ if (StringUtils.endsWith(oneCmd, "\\")) {
+ command += StringUtils.chop(oneCmd) + ";";
+ continue;
+ } else {
+ command += oneCmd;
+ }
+ if (StringUtils.isBlank(command)) {
+ continue;
+ }
+ execCommand += command + ";\n"; // stmt should end with ';' for sqlLine
+ command = "";
+ }
+ sqlLineInput = new ByteArrayInputStream(execCommand.getBytes());
+ }
+
+ // setup SQLLine args
+ List<String> argList = new ArrayList<String> ();
+ argList.add("-u");
+ argList.add(jdbcURL);
+ argList.add("-d");
+ argList.add(HIVE_JDBC_DRIVER); // TODO: make it configurable for HS or HS2
+ if (oproc.getpMode() == PrintMode.SILENT) {
+ argList.add(SQLLINE_SILENT);
+ } else if (oproc.getpMode() == PrintMode.VERBOSE) {
+ argList.add(SQLLINE_VERBOSE);
+ }
+
+ // Invoke sqlline
+ SqlLine.mainWithInputRedirection(argList.toArray(new String[0]), sqlLineInput);
+ }
+}
Oops, something went wrong.

0 comments on commit ca6980d

Please sign in to comment.