Hive CLI Command

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarANKUSH THAVALI
  • 02 Mar, 2022
  • 0 Comments
  • 53 Secs Read

Hive CLI Command

--define or –hivevar Options

hdfs@ubuntu1:~$ hive --define address='country, state, city, post'
hive> select ${address} from temp_hdfs limit 5;
OK
country 	state 	city	     post
AU	      TA    	Leith	    7315
AU	      QL	    Proston	  4613
AU	      WA    	Hame     l	6215
AU	      NS    	Talmalmo 	2640
Time taken: 0.57 seconds, Fetched: 5 row(s)
hive>

-- database Option

hdfs@ubuntu1 $ hive --database testdb
 
           or
 
hive> use testdb;

-s, -e Options, Environment variables & Redirecting Output to File

$ export VAR1='London' 
$ hive -S -e "SELECT firstname, state, city FROM temp_hdfs WHERE city='${VAR1}'" > temp_out.txt

Connecting Remote Hive Server

hdfs@tri03ws-386:~$ hive -h 172.16.3.78 -p 10000
 
Logging initialized using configuration in jar:file:/home/hdfs/bigdata/apache-hive-0.14.0-bin/lib/hive-common-0.14.0.jar!/hive-log4j.properties
...............
[172.16.3.78:10000] hive> show tables;
adapter
mytest
page_view
page_view14
emp

Running Queries from file

 hive -f /home/hdfs/test.hql

Hive Batch Mode Commands

hive -e "<query-string>"
hive -f <filepath>  – executes one or more SQL queries from a file