$HIVE_HOME/bin/hive is a shell utility which can be used to run Hive queries in either interactive or batch mode.
Deprecation in favor of Beeline CLI
HiveServer2 (introduced in Hive 0.11) has its own CLI called Beeline, which is a JDBC client based on SQLLine. Due to new development being focused on HiveServer2, Hive CLI will soon be deprecated in favor of Beeline.
See Beeline – New Command Line Shell in the HiveServer2 documentation.
Hive Command Line Options
To get help, run "
hive -H" or "
Usage (as it is in Hive 0.9.0):
Note: The variant "
-hiveconf" is supported as well as "
See Variable Substitution for examples of using the
Example of running a query from the command line
Example of setting Hive configuration variables
Example of dumping data out from a query into a file using silent mode
Example of running a script non-interactively from local disk
Example of running a script non-interactively from a Hadoop supported filesystem (starting in Hive 0.14)
Example of running an initialization script before entering interactive mode
The hiverc File
The CLI when invoked without the
-i option will attempt to load $HIVE_HOME/bin/.hiverc and $HOME/.hiverc as initialization files.
Hive Batch Mode Commands
$HIVE_HOME/bin/hive is run with the
-f option, it executes SQL commands in batch mode.
hive -e '<query-string>'executes the query string.
hive -f <filepath>executes one or more SQL queries from a file.
Hive Interactive Shell Commands
$HIVE_HOME/bin/hive is run without either the
-f option, it enters interactive shell mode.
Use ";" (semicolon) to terminate commands. Comments in scripts can be specified using the "--" prefix.
Use quit or exit to leave the interactive shell.
Resets the configuration to the default values (as of Hive 0.10: see HIVE-3202).
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 below for more information.
Lists the resources already added to the distributed cache. See Hive Resources below for more information.
list FILE[S] <filepath>*
Checks whether the given resources are already added to the distributed cache or not. See Hive Resources below for more information.
delete FILE[S] <filepath>*
Removes the resource(s) from the distributed cache.
Executes a shell command from the Hive shell.
dfs <dfs command>
Executes a dfs command from the Hive shell.
Executes a Hive query and prints results to standard output.
source FILE <filepath>
Executes a script file inside the CLI.
Hive uses log4j for logging. These logs are not emitted to the standard output by default but are instead captured to a log file specified by Hive's log4j properties file. By default Hive will use
hive-log4j.default in the
conf/ directory of the Hive installation which writes out logs to
/tmp/<userid>/hive.log and uses the
It is often desirable to emit the logs to the standard output and/or change the logging level for debugging purposes. These can be done from the command line as follows:
hive.root.logger specifies the logging level as well as the log destination. Specifying
console as the target sends the logs to the standard error (instead of the log file).
Hive can manage the addition of resources to a session where those resources need to be made available at query execution time. The resources can be files, jars, or archives. Any locally accessible file can be added to the session.
Once a resource is added to a session, Hive queries can refer to it by its name (in map/reduce/transform clauses) and the resource is available locally at execution time on the entire Hadoop cluster. Hive uses Hadoop's Distributed Cache to distribute the added resources to all the machines in the cluster at query execution time.
- FILE resources are just added to the distributed cache. Typically, this might be something like a transform script to be executed.
- JAR resources are also added to the Java classpath. This is required in order to reference objects they contain such as UDFs. See Hive Plugins for more information about custom UDFs.
- ARCHIVE resources are automatically unarchived as part of distributing them.
It is not neccessary to add files to the session if the files used in a transform script are already available on all machines in the Hadoop cluster using the same path name. For example:
... MAP a.networkid USING 'wc -l' ...
wcis an executable available on all machines.
... MAP a.networkid USING '/home/nfsserv1/hadoopscripts/tt.py' ...
tt.pymay be accessible via an NFS mount point that's configured identically on all the cluster nodes.
Note that Hive configuration parameters can also specify jars, files, and archives. See Configuration Variables for more information.