Hive Shell

  • Hive shell is a primary way to interact with hive.
  • It is a default service in hive.
  • It is also called as CLI (command line interference).
  • Hive shell is similar to MySQL Shell.
  • Hive users can run HQL queries in hive shell.
  • In hive shell up and down arrow keys used to scroll previous commands.
  • HiveQL is case-insensitive (except for string comparisons).
  • The tab key will autocomplete (provides suggestions while you type into the field) Hive keywords and functions.
  • In hive shell by default print column headers is not working(i.e by default it will not print table columns name like name,age from emp table) , We can enable this feature by using below setting.
hive> set hive.cli.print.header=true;

Hive Shell can run in two modes. They are,

  1. Non-Interactive mode
  2. Interactive mode.

1. Non-Interactive mode

         Non-interactive mode means run shell-scripts in administer zone. Hive Shell can run in the non-interactive mode, with -f option.

Example: $hive -f script.q

Where script.q is a file

2. Interactive mode

          Hive can work in interactive mode by directly typing command “hive” in the terminal.

Example: $hive

Hive> show databases;

Some of the options or arguments allowed hive shells are,

-d,–define <key=value>Defining new variables for Hive Session.
–database <databasename>Specify the database to use in Hive Session
-e <quoted-query-string>Running a Hive Query from the command line.
-f <filename>Execute the hive queries from file
-h <hostname>Connecting to Hive Server on remote host
-p <port>Connecting to Hive Server on port number
–hiveconf <property=value>Setting Configuration Property for current Hive Session
–hivevar <key=value>Same as –define argument
-i <filename> SQL properties file Initializes the Hive Session.
-S,–silentSilent mode in interactive shell, suppresses log messages
-v,–verboseVerbose mode (prints executed SQL to the console)