很多人會認為Hive指令行隻是一個執行HQL語句的控制台,其實它沒你想的那麼簡單,還有很多實用的用法,這裡就簡單介紹一下。
檢視Hive的幫助文檔
[[email protected] ~]$ hive -H
usage: hive
-d,--define <key=value> Variable subsitution to apply to hive
commands. e.g. -d A=B or --define A=B
--database <databasename> Specify the database to use
-e <quoted-query-string> SQL from command line
-f <filename> SQL from files
-H,--help Print help information
--hiveconf <property=value> Use value for given property
--hivevar <key=value> Variable subsitution to apply to hive
commands. e.g. --hivevar A=B
-i <filename> Initialization SQL file
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the
console)
[[email protected] ~]$ hive --help
Usage ./hive <parameters> --service serviceName <service parameters>
Service List: beeline cleardanglingscratchdir cli help hiveburninclient hiveserver2 hiveserver hwi jar lineage metastore metatool orcfiledump rcfilecat schemaTool version
Parameters parsed:
--auxpath : Auxillary jars
--config : Hive configuration directory
--service : Starts specific service/component. cli is default
Parameters used:
HADOOP_HOME or HADOOP_PREFIX : Hadoop install directory
HIVE_OPT : Hive options
For help on a particular service:
./hive --service serviceName --help
Debug help: ./hive --debug --help
使用hive -H和hive --help檢視的幫助文檔不一樣,hive --help檢視的是使用hive啟動服務的幫助文檔,hive -H是使用hive指令行的文檔。
Hive啟動服務
–auxpath是指定服務需要的擴充jar包,–config指定服務需要的配置參數,–service服務名
通過啟動服務進入hive指令行
[[email protected] ~]$ hive --service cli
hive>
進入beeline指令行
[[email protected] ~]$ hive --service beeline
beeline>
Hive指令行
-f是用來執行hql腳本,執行完成傳回結果
-i進入hive指令行前先初始化hql腳本
-e用來執行在hive指令行能夠執行的所有指令,包括下面介紹的shell指令,hdfs指令等
–database指定進入hive指令所通路的資料庫
-S用于忽略執行hive指令時一些日志輸出
–hiveconf、–hivevar和–define類型,都是用于初始化hive變量
Hive執行Shell指令
Hive指令行是可以執行shell指令的,感歎号後面加上shell指令就可以執行了
[[email protected] ~]$ hive
hive> !pwd;
/var/lib/hadoop-hdfs
hive> !ls /var/lib/hadoop-hdfs;
100
death
presto-server-0.152
presto-server-0.152.zip
t_passenger.java
Hive執行HDFS指令
Hive指令行是可以執行HDFS指令的,直接使用dfs指令即可:
hive> dfs -ls /;
Found 11 items
drwxr-xr-x - hdfs supergroup 0 2019-07-31 17:29 /etl-shell
drwxr-xr-x - hdfs supergroup 0 2019-06-18 17:59 /logs
drwxr-xr-x - hdfs supergroup 0 2019-06-21 11:47 /test
drwxrwxrwt - hdfs supergroup 0 2019-08-30 10:46 /tmp
drwxrwxrwx - hdfs supergroup 0 2019-08-28 11:38 /user