hive & hive beeline常用參數


Hive 1
參數如下:
usage: hive
-d,--define <key=value>          Variable substitution 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 substitution 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)

hive2
Beeline和其他工具有一些不同,執行查詢都是正常的SQL輸入,但是如果是一些管理的命令, 比如進行連接,中斷,退出,執行Beeline命令需要帶上“!”,不需要終止符。常用命令介紹: 1、!connect url –連接不同的Hive2服務器 2、!exit –退出shell 3、!help –顯示全部命令列表 4、!verbose –顯示查詢追加的明細

The Beeline CLI 支持以下命令行參數,也可以在客戶端通過幫助命令查詢beeline --help:
Option Description  
--autoCommit=[true/false] ---進入一個自動提交模式:beeline --autoCommit=true  
--autosave=[true/false]   ---進入一個自動保存模式:beeline --autosave=true  
--color=[true/false]    ---顯示用到的顏色:beeline --color=true  
--delimiterForDSV= DELIMITER ---分隔值輸出格式的分隔符。默認是“|”字符。  
--fastConnect=[true/false]  ---在連接時,跳過組建表等對象:beeline --fastConnect=false  
--force=[true/false]    ---是否強制運行腳本:beeline--force=true  
--headerInterval=ROWS   ---輸出的表間隔格式,默認是100: beeline --headerInterval=50  
--help ---幫助  beeline --help  
--hiveconf property=value  ---設置屬性值,以防被hive.conf.restricted.list重置:beeline --hiveconf prop1=value1   
--hivevar name=value   ---設置變量名:beeline --hivevar var1=value1  
--incremental=[true/false]  ---輸出增量
--isolation=LEVEL  ---設置事務隔離級別:beeline --isolation=TRANSACTION_SERIALIZABLE  
--maxColumnWidth=MAXCOLWIDTH ---設置字符串列的最大寬度:beeline --maxColumnWidth=25  
--maxWidth=MAXWIDTH ---設置截斷數據的最大寬度:beeline --maxWidth=150  
--nullemptystring=[true/false]  ---打印空字符串:beeline --nullemptystring=false  
--numberFormat=[pattern]     ---數字使用DecimalFormat:beeline --numberFormat="#,###,##0.00"  
--outputformat=[table/vertical/csv/tsv/dsv/csv2/tsv2] ---輸出格式:beeline --outputformat=tsv   
--showHeader=[true/false]   ---顯示查詢結果的列名:beeline --showHeader=false  
--showNestedErrs=[true/false] ---顯示嵌套錯誤:beeline --showNestedErrs=true  
--showWarnings=[true/false] ---顯示警告:beeline --showWarnings=true  
--silent=[true/false]  ---靜默方式執行,不顯示執行過程信息:beeline --silent=true  
--truncateTable=[true/false] ---是否在客戶端截斷表的列     
--verbose=[true/false]  ---顯示詳細錯誤信息和調試信息:beeline --verbose=true  
-d <driver class>  ---使用一個驅動類:beeline -d driver_class  
-e <query>  ---使用一個查詢語句:beeline -e "query_string"  
-f <file>  ---加載一個文件:beeline -f filepath  多個文件用-e file1 -e file2
-n <username>  ---加載一個用戶名:beeline -n valid_user  
-p <password>  ---加載一個密碼:beeline -p valid_password  
-u <database URL> ---加載一個JDBC連接字符串:beeline -u db_URL

 

beeline常用操作:

1. 將查詢結果輸出到臨時文件中

beeline -u "jdbc:hive2://dwtest-name1:10000/default" -n root --silent=true --outputformat=csv2  -hivevar logdate=${dt}  -f script.q > ${file_tmp}

-f 對應查詢的腳本 script.q

--outputformat=csv2 以逗號分隔

--silent=true  靜默方式執行,注意:輸出文件的時候必須以靜默方式運行,否則輸出的文本中帶有很多程序執行信息。

上述命令執行完成后發現輸出的文件中仍然有許多空白行,好像沒有參數控制,無奈之下又使用shell命令來過濾空白行。

通過下面任意一行命令來過濾空白行,最后輸出結果正常。

#方式一:
#cat ${file_tmp} | sed -e '/^$/d' > ${file}

#方式二:
grep -a -v "^$"  ${file_tmp} > ${file}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM