- Beeline – New Command Line Shell
- Connection URLs
- Using JDBC
- JDBC Data Types
- JDBC Client Setup for a Secure Cluster
- Python Client
- Ruby Client
- Integration with SQuirrel SQL Client
This page describes the different clients supported by HiveServer2.
Beeline – New Command Line Shell
HiveServer2 supports a new command shell Beeline that works with HiveServer2. It's a JDBC client that is based on the SQLLine CLI (http://sqlline.sourceforge.net/). There’s detailed documentation of SQLLine which is applicable to Beeline as well.
The Beeline shell works in both embedded mode as well as remote mode. In the embedded mode, it runs an embedded Hive (similar to Hive CLI) whereas remote mode is for connecting to a separate HiveServer2 process over Thrift. Starting in Hive 0.14, when Beeline is used with HiveServer2, it also prints the log messages from HiveServer2 for queries it executes to STDERR.
List of SQLLine commands available at http://sqlline.sourceforge.net/.
Beeline Hive Commands
Hive specific commands (same as Hive CLI commands) can be run from Beeline, when the Hive JDBC driver is used.
;" (semicolon) to terminate commands. Comments in scripts can be specified using the "
Resets the configuration to the default values.
Sets the value of a particular configuration variable (key).
Prints a list of configuration variables that are overridden by the user or Hive.
Prints all Hadoop and Hive configuration variables.
add FILE[S] <filepath> <filepath>*
Adds one or more files, jars, or archives to the list of resources in the distributed cache. See Hive Resources for more information.
list FILE[S] <filepath>*
Checks whether the given resources are already added to the distributed cache or not. See Hive Resources for more information.
delete FILE[S] <filepath>*
Removes the resource(s) from the distributed cache.
dfs <dfs command>
Executes a dfs command.
Executes a Hive query and prints results to standard output.
Beeline Command Options
The Beeline CLI supports these command line options:
-u <database URL>
The JDBC URL to connect to.
The username to connect as.
The password to connect as.
-d <driver class>
The driver class to use.
Query that should be executed. Double or single quotes enclose the query string. This option can be specified multiple times.
Bug fix (null pointer exception): 0.13.0 (HIVE-5765)
Bug fix (--headerInterval not honored): 0.14.0 (HIVE-7647)
Script file that should be executed.
Use value for the given configuration property. Properties that are listed in hive.conf.restricted.list cannot be reset with hiveconf (see Restricted List and Whitelist).
Version: 0.13.0 (HIVE-6173)
Hive variable name and value. This is a Hive-specific setting in which variables can be set
Control whether color is used for display. Default is false.
(Not supported for Separated-Value Output formats. See HIVE-9770)
Show column names in query results (true) or not (false). Default is true.
The interval for redisplaying column headers, in number of rows, when outputformat is table.
(Not supported for Separated-Value Output formats. See HIVE-9770)
When connecting, skip building a list of all tables and columns for tab-completion of
Enable/disable automatic transaction commit. Default is false.
Show verbose error messages and debug information (true) or do not show (false).
Display warnings that are reported on the connection after issuing any HiveQL commands.
Display nested errors. Default is false.
Format numbers using a DecimalFormat pattern.
Continue running script even after errors (true) or do not continue (false). Default is false.
The maximum width to display before truncating data, in characters, when outputformat is table.
The maximum column width, in characters, when outputformat is table. Default is 15.
Reduce the amount of informational messages displayed (true) or not (false). It also stops displaying the log messages for the query from HiveServer2 (Hive 0.14 and later) and the HiveQL commands (Hive 1.2.0 and later). Default is false.
Automatically save preferences (true) or do not autosave (false). Default is false.
Format mode for result display. Default is table. See Separated-Value Output Formats below for description of recommended sv options.
Version: dsv/csv2/tsv2 added in 0.14.0 (HIVE-8615)
If true, truncates table column in the console when it exceeds console length.
Version: 0.14.0 (HIVE-6928)
The delimiter for delimiter-separated values output format. Default is '|' character.
Version: 0.14.0 (HIVE-7390)
Set the transaction isolation level to TRANSACTION_READ_COMMITTED
Use historic behavior of printing null as empty string (true) or use current behavior of printing
Version: 0.13.0 (HIVE-4485)
Print output incrementally.
Display a usage message.
Separated-Value Output Formats
Starting with Hive 0.14, there are improved SV output formats available, namely DSV, CSV2 and TSV2. These conform better to standard CSV convention, which adds quotes around a cell value only if it contains special characters (such as the delimiter character or a quote character) or spans multiple lines. These three formats differ only with the delimiter between cells, which is comma for CSV2, tab for TSV2, and configurable for DSV (delimiterForDSV property).
CSV and TSV output formats are maintained for backward compatibility, but beware as they add additional single-quote characters around all cell values contrary to this convention.
HiveServer2 has a new JDBC driver. It supports both embedded and remote access to HiveServer2.
Connection URL for Remote or Embedded Mode
The JDBC connection URL format has the prefix
jdbc:hive2:// and the Driver class is
org.apache.hive.jdbc.HiveDriver. Note that this is different from the old HiveServer.
- For a remote server, the URL format is
jdbc:hive2://<host>:<port>/<db>(default port for HiveServer2 is 10000).
- For an embedded server, the URL format is
jdbc:hive2://(no host or port).
Connection URL When HiveServer2 Is Running in HTTP Mode
JDBC connection URL:
- <http_endpoint> is the corresponding HTTP endpoint configured in hive-site.xml. Default value is cliservice.
- Default port for HTTP transport mode is 10001
Supporting cookie replay in HTTP mode
HIVE-9709 introduced support to JDBC driver to enable cookie replay. This is turned to on by default so that incoming cookies can be send back to the server for authentication purpose.
The JDBC connection URL when enabled should look like :
- cookieAuth is set to default as true
- cookieName : If any of the incoming cookies' key matches the value of cookieName, the JDBC driver will not send any login credentials/kerberos ticket to the server. i.e. the client will just send the cookie alone back to the server for authentication purpose. The default value of cookieName is hive.server2.auth (this is the HiveServer2 cookie name).
- To turn off cookie replay, cookieAuth=false must be used in the JDBC url.
- Important Note : As part of HIVE-9709, we upgraded Apache http-client and http-core components of Hive to 4.4. To avoid any collision between this upgraded version of HttpComponents and other any versions that might be present in your system (such as the one provided by Apache Hadoop 2.6 which uses http-client and http-core components version of 4.2.5), the client is expected to set HADOOP_USER_CLASSPATH_FIRST=true before using hive-jdbc. Infact, in bin/beeline.sh we do this!
Connection URL When SSL Is Enabled in HiveServer2
JDBC connection URL:
- <trust_store_path> is the path where client's truststore file lives.
- <trust_store_password> is the password to access the truststore.
In HTTP mode:
You can use JDBC to access data stored in a relational database or other tabular format.
Load the HiveServer2 JDBC driver. As of 1.2.0 applications no longer need to explicitly load JDBC drivers using Class.forName().
Connect to the database by creating a
Connectionobject with the JDBC driver.
<port>is 10000. In non-secure configurations, specify a
<user>for the query to run as. The
<password>field value is ignored in non-secure mode.
In Kerberos secure mode, the user information is based on the Kerberos credentials.
Submit SQL to the database by creating a
Statementobject and using its
- Process the result set, if necessary.
These steps are illustrated in the sample code below.
JDBC Client Sample Code
Running the JDBC Sample Code
Alternatively, you can run the following bash script, which will seed the data file and build your classpath before invoking the client. The script adds all the additional jars needed for using HiveServer2 in embedded mode as well.
JDBC Data Types
The following table lists the data types implemented for HiveServer2 JDBC.
signed or unsigned 1-byte integer
signed 2-byte integer
signed 4-byte integer
signed 8-byte integer
single-precision number (approximately 7 digits)
double-precision number (approximately 15 digits)
fixed-precision decimal value
a single bit (0 or 1)
character string or variable-length character string
date and time value
String – json encoded
values of one data type
String – json encoded
String – json encoded
JDBC Client Setup for a Secure Cluster
When connecting to HiveServer2 with Kerberos authentication, the URL format is:
The client needs to have a valid Kerberos ticket in the ticket cache before connecting.
NOTE: If you don't have a "/" after the port number, the jdbc driver does not parse the hostname and ends up running HS2 in embedded mode . So if you are specifying a hostname, make sure you have a "/" or "/<dbname>" after the port number.
In the case of LDAP, CUSTOM or PAM authentication, the client needs to pass a valid user name and password to the JDBC connection API.
To use sasl.qop, add the following to the sessionconf part of your Hive JDBC hive connection string, e.g.
For more information, see Setting Up HiveServer2.
Multi-User Scenarios and Programmatic Login to Kerberos KDC
In the current approach of using Kerberos you need to have a valid Kerberos ticket in the ticket cache before connecting. This entails a static login (using kinit, key tab or ticketcache) and the restriction of one Kerberos user per client. These restrictions limit the usage in middleware systems and other multi-user scenarios, and in scenarios where the client wants to login programmatically to Kerberos KDC.
One way to mitigate the problem of multi-user scenarios is with secure proxy users (see HIVE-5155). Starting in Hive 0.13.0, support for secure proxy users has two components:
- Delegation token based connection for Oozie (OOZIE-1457). This is the common mechanism for Hadoop ecosystem components.
- Direct proxy access for privileged Hadoop users (HIVE-5155). This enables a privileged user to directly specify an alternate session user during the connection. If the connecting user has Hadoop level privilege to impersonate the requested userid, then HiveServer2 will run the session as that requested user.
The other way is to use a pre-authenticated Kerberos Subject (see HIVE-6486). In this method, starting with Hive 0.13.0 the Hive JDBC client can use a pre-authenticated subject to authenticate to HiveServer2. This enables a middleware system to run queries as the user running the client.
Using Kerberos with a Pre-Authenticated Subject
To use a pre-authenticated subject you will need the following changes.
- Add hive-exec*.jar to the classpath in addition to the regular Hive JDBC jars (commons-configuration-1.6.jar and hadoop-core*.jar are not required).
- Add auth=kerberos and kerberosAuthType=fromSubject JDBC URL properties in addition to having the “principal" url property.
- Open the connection in Subject.doAs().
A Ruby client driver is available on github at https://github.com/forward3d/rbhive.
Integration with SQuirrel SQL Client
- Download, install and start the SQuirrel SQL Client from the SQuirrel SQL website.
- Select 'Drivers -> New Driver...' to register Hive's JDBC driver that works with HiveServer2.
Enter the driver name and example URL:
Select 'Extra Class Path -> Add' to add the following jars from your local Hive and Hadoop distribution.
Select 'List Drivers'. This will cause SQuirrel to parse your jars for JDBC drivers and might take a few seconds. From the 'Class Name' input box select the Hive driver for working with HiveServer2:
Click 'OK' to complete the driver registration.
- Select 'Aliases -> Add Alias...' to create a connection alias to your HiveServer2 instance.
- Give the connection alias a name in the 'Name' input box.
- Select the Hive driver from the 'Driver' drop-down.
- Modify the example URL as needed to point to your HiveServer2 instance.
- Enter 'User Name' and 'Password' and click 'OK' to save the connection alias.
- To connect to HiveServer2, double-click the Hive alias and click 'Connect'.
When the connection is established you will see errors in the log console and might get a warning that the driver is not JDBC 3.0 compatible. These alerts are due to yet-to-be-implemented parts of the JDBC metadata API and can safely be ignored. To test the connection enter SHOW TABLES in the console and click the run icon.
Also note that when a query is running, support for the 'Cancel' button is not yet available.