Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: change {code} to {noformat} because {code} macro is broken

...

Info
titleVersion information

As of Hive 0.10.0 there is one additional command line option:

Code Blocknoformat
--database <dbname>      Specify the database to use

...

  • Example of running a query from the command line
    Code Blocknoformat
       $HIVE_HOME/bin/hive -e 'select a.col from tab1 a'
       
  • Example of setting Hive configuration variables
    Code Blocknoformat
       $HIVE_HOME/bin/hive -e 'select a.col from tab1 a' -hiveconf hive.exec.scratchdir=/home/my/hive_scratch  -hiveconf mapred.reduce.tasks=32
       
  • Example of dumping data out from a query into a file using silent mode
    Code Blocknoformat
       $HIVE_HOME/bin/hive -S -e 'select a.col from tab1 a' > a.txt
       
  • Example of running a script non-interactively
    Code Blocknoformat
       $HIVE_HOME/bin/hive -f /home/my/hive-script.sql
       
  • Example of running an initialization script before entering interactive mode
    Code Blocknoformat
       $HIVE_HOME/bin/hive -i /home/my/hive-init.sql
       

...

Command

Description

quit
exit

Use quit or exit to leave the interactive shell.

reset

Resets the configuration to the default values (as of Hive 0.10: see HIVE-3202).

set <key>=<value>

Sets the value of a particular configuration variable (key).
Note: If you misspell the variable name, the CLI will not show an error.

set

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

set -v

Prints all Hadoop and Hive configuration variables.

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e02a9e5ea7085e40-3360e115-41a04454-9dbab6db-5739b732beaba7a0eb7363ce"><ac:plain-text-body><![CDATA[

add FILE[S] <filepath> <filepath>*
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="38ebb0ceb62eeb54-c1655f92-4a1b4480-ad78b927-d84dbb295f442152fb6b2b62"><ac:plain-text-body><![CDATA[add JAR[S] <filepath> <filepath>*
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="64fca939a40319e0-d1ead162-40254192-9432b94c-075ec2214763b9fc671e340a"><ac:plain-text-body><![CDATA[add ARCHIVE[S] <filepath> <filepath>*

Adds one or more files, jars, or archives to the list of resources in the distributed cache.

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5c3e4c038a931fe0-9a4deca4-4b8f44d1-a1a2952d-320d7c1b4a71c5fabedaa310"><ac:plain-text-body><![CDATA[

list FILE[S]
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c195f70109880e57-4bb17a5d-45284264-bfe69684-3f037c33c4ea173bbeb4a962"><ac:plain-text-body><![CDATA[list JAR[S]
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="15bcd19c4b229537-14a67076-4aa042dd-beada936-691cb358f9b0a795b6c93400"><ac:plain-text-body><![CDATA[list ARCHIVE[S]

Lists the resources already added to the distributed cache.

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="af9d34f7d42a2d20-03558ae8-4f2042fd-beb18e9d-5857a5771f2523a0e4126530"><ac:plain-text-body><![CDATA[

list FILE[S] <filepath>*
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f996d0fd5de05ed0-4c18c156-47f1444b-adc89146-d26cffeac2710e1cd75e4ed7"><ac:plain-text-body><![CDATA[list JAR[S] <filepath>*
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b3c9fb790790dde3-ac1bf946-4a6147ab-8d788693-7673b79c07a2554783546821"><ac:plain-text-body><![CDATA[list ARCHIVE[S] <filepath>*

Checks whether the given resources are already added to the distributed cache or not.

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2ae0da9f18672885-eeb54190-43194a29-bbad9d96-35e5c0384f4a53a176df4753"><ac:plain-text-body><![CDATA[

delete FILE[S] <filepath>*
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ba4f755869feaeb0-d3b325ba-492f471a-8a4c89c8-6dfc68c4d4d21a6ec41b62f8"><ac:plain-text-body><![CDATA[delete JAR[S] <filepath>*
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0e8d5ba19d1cb81b-230b0031-45b744bb-90679797-73d46daf92e85a3f37d680d8"><ac:plain-text-body><![CDATA[delete ARCHIVE[S] <filepath>*

Removes the resource(s) from the distributed cache.

]]></ac:plain-text-body></ac:structured-macro>

! <command>

Executes a shell command from the Hive shell.

dfs <dfs command>

Executes a dfs command from the Hive shell.

<query string>

Executes a Hive query and prints results to standard output.

source FILE <filepath>

Executes a script file inside the CLI.

Sample Usage:

Code Blocknoformat
  hive> set mapred.reduce.tasks=32;
  hive> set;
  hive> select a.* from tab1;
  hive> !ls;
  hive> dfs -ls;

...

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:

Code Blocknoformat
 $HIVE_HOME/bin/hive -hiveconf hive.root.logger=INFO,console

...

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.

Usage:

Code Blocknoformat
   ADD { FILE[S] | JAR[S] | ARCHIVE[S] } <filepath1> [<filepath2>]*
   LIST { FILE[S] | JAR[S] | ARCHIVE[S] } [<filepath1> <filepath2> ..]
   DELETE { FILE[S] | JAR[S] | ARCHIVE[S] } [<filepath1> <filepath2> ..] 
  • 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.
  • ARCHIVE resources are automatically unarchived as part of distributing them.

Example:

Code Blocknoformat
  hive> add FILE /tmp/tt.py;
  hive> list FILES;
  /tmp/tt.py
  hive> select from networks a 
               MAP a.networkid 
               USING 'python tt.py' as nn where a.ds = '2009-01-04' limit 10;

...