Saturday, 8 February 2014

Hive Shell is run on two modes

The shell is the primary way that we will interact with Hive, by issuing commands in HiveQL. HiveQL is Hive’s query language, a dialect of SQL. It is heavily influenced by MySQL, so if you are familiar with MySQL you should feel at home using Hive.

Like SQL, HiveQL is generally case insensitive (except for string comparisons),
The tab key will autocomplete Hive keywords and functions.

You can use the up and down arrow keys to scroll through previous commands. Hive saves the last  100,00 lines into a file $HOME/.hivehistory.

If required we should tell the CLI to print column headers, which is disabled by default. We can enable this feature by setting the hiveconf property hive.cli.print.header to true

hive> set hive.cli.print.header=true;

Hive Shell is run on two modes:

1. Non-Interactive mode
2. Interactive mode

Hive Non-Interactive mode:

You can also run the Hive shell in non-interactive mode.
The -f option runs the commands in the specified file, script.q, in this

Input file: 

$cat >abc
^d(ctrl+d) --save the file

create table testdata(id int,str string) row format delimited fields terminated by ',';
load data local inpath '/home/training/abc' into table testdata(tablename);
^d(Ctrl+d)-- save the file

Execute the above script.q file by using -f option

$hive -f script.q

Then one directory(testdata) is create into /user/hive/warehouse directory.

For short scripts, you can use the -e option to specify the commands inline, in which case the final semicolon is not required:

$hive -e 'SELECT * FROM testdata'

In both interactive and non-interactive mode, Hive will print information to standard Error. You can suppress these messages using the -S option at launch time, which has the effect of only showing the output result for queries:

$ hive -S -e 'SELECT * FROM dummy'

we are storing Hive tables on the local filesystem ( is set to its default value of file:///). Tables are stored as directories under Hive’s warehouse directory, which is controlled by the hive.metastore.warehouse.dir, and defaults to /user/hive/warehouse.

Thus, the files for the records table are found in the /user/hive/warehouse/records directory on the local filesystem:
$ls  /user/hive/warehouse/records/

Hive Interactive mode:

Directly goto the hive mode and run the queries


$hive --enter, goto hive mode



create file

$cat >abc


create the hive table in interactive mode:

hive>create table testdata1(id int, name string) row format delimited fields terminated by ',';

load the data into table:

hive>load data local inpath '/home/training/abc' into table testdata1;


No comments:

Post a comment