Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ca6980d
Showing
10 changed files
with
489 additions
and
2 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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" | |||
} | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="@PROJECT@" path="1" type="4"/> "/> | |||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@PROJECT@/conf" path="3" type="2"/> "/> | |||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@PROJECT@/common/src/java/conf" path="3" type="2"/> "/> | |||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@PROJECT@/build/metastore/hive-metastore-@HIVE_VERSION@.jar" path="3" type="2"/> "/> | |||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="@PROJECT@"/> </runtimeClasspathEntry> "/> | |||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@PROJECT@/build/ql/hive-exec-@HIVE_VERSION@.jar" path="3" type="2"/> "/> | |||
</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> |
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
112 changes: 112 additions & 0 deletions
112
jdbc/src/java/org/apache/hive/jdbc/beeline/HiveBeeline.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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.