LinuxCommandLibrary

hive

Execute SQL-like queries on Hadoop data

TLDR

Start a Hive interactive shell

$ hive
copy

Run HiveQL
$ hive -e "[hiveql_query]"
copy

Run a HiveQL file with a variable substitution
$ hive [[-d|--define]] [key]=[value] -f [path/to/file.sql]
copy

Run a HiveQL with HiveConfig (e.g. mapred.reduce.tasks=32)
$ hive --hiveconf [conf_name]=[conf_value]
copy

SYNOPSIS

hive [options] [query_string] | hive -e 'sql_query' | hive -f file.sql

PARAMETERS

-e 'query_string'
    Execute HiveQL query from command line

-f filename
    Execute HiveQL from file

-d, --define key=value
    Define Hive variable for substitution

--hiveconf key=value
    Set Hive configuration property

--hivevar name=value
    Set Hive variable (user-defined)

-H, --silent
    Silent mode: suppress output headers

--service service_name
    Start named Hive service (e.g., cli, metastore)

-h, --help
    Display help

--version
    Print Hive version

--auxpath path
    Append path to classpath

DESCRIPTION

The hive command provides an interactive command-line interface (CLI) to Apache Hive, a data warehousing solution built on top of Hadoop. It enables users to run HiveQL queries—a SQL-like language—against large datasets stored in HDFS, supporting complex analytics, ETL processes, and ad-hoc querying without writing MapReduce code.

In interactive mode (default), it launches a REPL shell for entering commands directly. Non-interactive modes allow executing queries from strings (-e) or files (-f). Hive CLI handles session management, variable substitution, and configuration overrides via options like --hiveconf. It integrates with HiveServer for remote execution but embeds the Hive driver.

Note: Hive CLI is legacy in Hive 2+ versions; use beeline for modern JDBC-based access. Requires Hadoop and Hive installation with proper HDFS/YARN setup.

CAVEATS

Deprecated in Hive 4.0+; migrate to beeline for security.
Embeds old Hive driver; vulnerable in multi-user setups.
Requires HDFS/Hive Metastore access and JAVA_HOME.

INTERACTIVE USAGE

Run hive for shell; use exit;, quit; or Ctrl+C to exit.
Supports multiline queries and !commands (e.g., !sh).

OUTPUT FORMATS

Default: tabular. Use SET hive.cli.print.header=true; for headers.
Redirect with | to files.

HISTORY

Developed by Facebook in 2007 for petabyte-scale data querying; donated to Apache in 2008. Hive CLI stabilized in early releases; evolved with Hive versions but phased out post-Hive 2.0 favoring thin clients.

SEE ALSO

beeline(1), hdfs(1), hadoop(1), hiveserver2(1)

Copied to clipboard