Hive Commands in Hadoop with Example


Hive Commands are UNIX based non-SQL statements such as setting a property or adding a resource. You can use hive commands in HiveQL (Hive Query language) scripts or directly in command line interface or Beeline interface.

The $HIVE_HOME/bin/hive is the gateway to hive services. You should add $HIVE_HOME/bin to environment variable path So that you can directly type hive from your shell environment(bash..etc.).

Hive Interaction Tools

  1. Command Line Interface
  2. Karmasphere (GUI Based)
  3. Hue (GUI Based)
  4. Qubole

In this blog we are listing all hive commands used in Hadoop from interactive shell perspective.

Top Hive Commands in Hadoop are listed below –

Quit/Exit Command –

Use quit or exit hive commands to leave the interactive shell. This is the most useful hive command as during hive programming you will have to switch from Hive shell to local or Hadoop shell. Thus simply typing quit or exit will through from hive shell to local.

Example –

 Reset Command –

Resets the configuration to the default values. Any configuration parameters that were set using the set command or -hiveconf parameter in hive command line will get reset to default value.

Note that this does not apply to configuration parameters that were set in set command using the “hiveconf:” prefix for the key name (for historic reasons).

Apache Explain

 Set Command –

Set hive command Sets the value of a particular configuration variable (key). If you want to set configuration value directly from command shell, you can do this via Set Command. Set command let you give the power of setting configuration for particular session, Without changing to hive-site.xml. Set hive commands give immense power to developer to set variable values directly from hive shell.
Note: If you misspell the variable name, the CLI will not show an error.

Prints a list of configuration variables that are overridden by the user or Hive.

Prints all Hadoop and Hive configuration variables.

Example –

Add Command –

Adds one or more files, jars, or archives to the list of resources in the distributed cache. As during hive programming you have to add resources like -Jar files , Custom UDF’s etc. Add command give you power to add resources for the session.

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.

Add , Delete and List Hive commands are usable when developer deals with Custom file load, UDF’s creation. Like for CSV file load you have to use CSV serde Jar file to support loading process and to let hive know about the file format.

Example –

 List Command –

List Hive Commands lists the resources already added to the distributed cache. If you want to checks whether the given resources are already added to the distributed cache or not then use following hive commands. * is an wildcard which list all the files –

Example –

 Delete Command –

Delete hive command removes the resource(s) from the distributed cache. This is one of the most useful hive command in Hadoop for removing resources from current session. There are many scenarios where you don’t want to include particular jar files or UDF’s, In that case you can simply remove by deleting from user session using delete command.

Example –

Shell Command –

Executes a shell command from the Hive shell. If you want to make use of all shell commands as you were fire on bash or shell. you can simply do it using below command in Hive shell itself. So that you not need to switch over hive shell to another for other shell commands.

Example –

DFS Command –

Executes a dfs command from the Hive shell. If you want to perform all operations on Hadoop Distributed file system (HDFS) using hive command line interface, you can use below command. Which gives immense power of HDFS operations through hive shell.

Example –

Query Command –

Executes a Hive query and prints results to standard output. All Hive Queries can fire directly from hive shell.

Example –

 Execute Script Command –

Executes a script file inside the CLI. Execute script hive commands is useful when you want to run Hive query (HQL) from a file. Like all queries you want to run is stored on a file, extension as  .hql , and then give the path of that file using this command and all queries within that file will be executed.

Above hive commands are more commonly used top hive shell commands on Hadoop infrastructure. They are day to day used command while running an Hadoop project.