天天看點

hive、impala的用戶端,cli、beeline、WebHCathive-cli和beeline差別 官網說明一、hive cli二、hive beeline三、WebHCat

連接配接hive有2種形式,hive cli 和 beeline

hive提供了以表的形式通路hdfs檔案的功能,metastore對外提供表的中繼資料資訊。有了中繼資料,就可以結構化的表的形式通路hdfs上的檔案了

cli模式是通過metaStroe來通路中繼資料;beeline模式是通過hiveServer2==》metastore通路中繼資料。

hs2依賴于metastore。

官方建議使用beeline模式連接配接hive執行操作。

hive-cli和beeline差別 官網說明

1.在使用hive指令的時候,會提示CLI已經過期,建議用beeline

hive、impala的用戶端,cli、beeline、WebHCathive-cli和beeline差別 官網說明一、hive cli二、hive beeline三、WebHCat

通過hadoop version 找到hive的home,發現有一個hive-old 的檔案,通過檢查測試發現這就是原來hive cli的檔案。hive3.0隻支援beeline

2.cli連接配接不需要hs2,而beeline需要啟動hs2服務

将hs2關閉後

hive、impala的用戶端,cli、beeline、WebHCathive-cli和beeline差別 官網說明一、hive cli二、hive beeline三、WebHCat

hive可以正常連,但beeline連不上

hive、impala的用戶端,cli、beeline、WebHCathive-cli和beeline差別 官網說明一、hive cli二、hive beeline三、WebHCat
hive、impala的用戶端,cli、beeline、WebHCathive-cli和beeline差別 官網說明一、hive cli二、hive beeline三、WebHCat

3.CDH的beeline在運作load data local inpath的時候總是提示找不到檔案的錯誤(可以用hdfs上的位址),但在同一節點使用hive卻可以。這是因為啟動hivecli的時候,是會在本地啟動一個metastore的服務,但hs2可以遠端的,自然加載不到本地的檔案。

可以使用 hive -e ‘load data local inpath’ 和 hive -f

hive cli 之于hive 就相當于sql plus之于oracle. 需要和server安裝在一起。

而beeline隻需要一個jdbc jar包就可以了,可以不需要與hive server 2裝在一台server.

他們認證的方式也不同,hive cli可以直接通路hdfs和hive meta store,感覺更穩定快捷一些。

而beeline 則需要把請求送出到hive server2,通過安全驗證,然後在隊列中等待。

beeline的并發性和安全性得到了提高。

4.beeline的功能更強大,支援jdbc,并發性和安全性更高,cs架構,更輕。但速度理論上更慢。

hs2提供了代理功能,能夠以一個更安全的使用者通路hive。

本身是基于jdbc的,并發性能有保障。

beeline功能更多,比如,可以設定輸出資料的分隔符、高亮顯示、資料轉換等功能

一、hive cli

二、hive beeline

1. overview

beeline 可以連接配接hive和impala,基于SQLLine CLI的JDBC用戶端,beeline 要與HiveServer2配合使用,支援嵌入模式和遠端模式兩種,也即既可以像hive client一樣通路本機的hive服務,也可以通過指定ip和端口遠端通路某個hive服務。

metaStroe是提供中繼資料通路服務,hiveServer2是提供jdbc的方式通路hive。

Beeline支援嵌入模式(embedded mode)和遠端模式(remote mode)。在嵌入式模式下,運作嵌入式的Hive(類似Hive CLI),而遠端模式可以通過Thrift連接配接到獨立的HiveServer2程序上。從Hive 0.14版本開始,Beeline使用HiveServer2工作時,它也會從HiveServer2輸出日志資訊到STDERR。

hive 官網是推薦使用beeline,它還提供了更為友好的顯示方式(類似mysql client)。Beeline是從 Hive 0.11版本引入的,它是基于SQLLine CLI的JDBC用戶端。後續将使用Beeline 替代HiveCLI ,并且後續版本也會廢棄掉HiveCLI 用戶端工具。

2. usage

nohup beeline 
-u jdbc:hive2://10.180.0.26:10000;principal=hive/[email protected]  
-n hive -p hive
--color=true 
--silent=false  
--hivevar p_date=${partitionDate} --hivevar f_date=${fileLocDate} 
-f hdfs_add_partition_dmp_clearlog.hql  
>> $logdir/load_${curDate}.log
&
           
指定要連接配接的hiveserver2的主機、端口
beeline -u jdbc:hive2://hd1:10000
如果是本機的hiveserver2,則可省略主機、端口
beeline -u jdbc:hive2://
           

整合kerberos時設定要principal是hive服務的,登入使用者是krb認證的,krb認證誰beeline目前使用者就是誰。

如果principal這個單詞寫錯了

beeline -u “jdbc:hive2://n105:10000/;principal=hive/[email protected]”

hive、impala的用戶端,cli、beeline、WebHCathive-cli和beeline差別 官網說明一、hive cli二、hive beeline三、WebHCat

3.beeline的使用

官網參數詳解,注意版本号

Usage: java org.apache.hive.cli.beeline.BeeLine 
   -u <database url>               the JDBC URL to connect to
   -n <username>                   the username to connect as
   -p <password>                   the password to connect as
   -w (or) --password-file <password file>  the password file to read password from
   -d <driver class>               the driver class to use
   -e <query>                      query that should be executed
   -i <init file>                  script file for initialization
                                   一般用來和-f配合,用來給-f中的sql檔案設定變量,值也是一個檔案
   -f <exec file>                  script file that should be executed
   								   可以設定多個 -f sqlFile1 -f sqlFile2  
   --hiveconf property=value       Use value for given property
   --hivevar name=value            hive variable name and value
                                   This is Hive specific settings in which variables
                                   can be set at session level and referenced in Hive
                                   commands or queries.
   --color=[true/false]            control whether color is used for display
                                   用于在beeline中設定多種顔色,便于檢視
   --showHeader=[true/false]       show column names in query results
   --headerInterval=ROWS;          the interval between which heades are displayed
   --fastConnect=[true/false]      skip building table/column list for tab-completion
   --autoCommit=[true/false]       enable/disable automatic transaction commit
   --verbose=[true/false]          show verbose error messages and debug info
                                   顯示詳細錯誤資訊和調試資訊
   --showWarnings=[true/false]     display connection warnings
   --showNestedErrs=[true/false]   display nested errors
   --numberFormat=[pattern]        format numbers using DecimalFormat pattern
   --force=[true/false]            continue running script even after errors
   --maxWidth=MAXWIDTH             the maximum width of the terminal
   --maxColumnWidth=MAXCOLWIDTH    the maximum width to use when displaying columns
   --silent=[true/false]           be more silent
   --autosave=[true/false]         automatically save preferences
   --outputformat=[table/vertical/csv2/tsv2/dsv/csv/tsv]  format mode for result display
                                   Note that csv, and tsv are deprecated - use csv2, tsv2 instead
   --truncateTable=[true/false]    truncate table column when it exceeds length
   --delimiterForDSV=DELIMITER     specify the delimiter for delimiter-separated values output format (default: |)
   --isolation=LEVEL               set the transaction isolation level
   --nullemptystring=[true/false]  set to true to get historic behavior of printing null as empty string
   --addlocaldriverjar=DRIVERJARNAME Add driver jar file in the beeline client side
   --addlocaldrivername=DRIVERNAME Add drvier name needs to be supported in the beeline client side
   --help                          display this message
Beeline version 1.2.1.spark2 by Apache Hive
           

進入beeline後的指令

!addlocaldriverjar  Add driver jar file in the beeline client side.
!addlocaldrivername Add driver name that needs to be supported in the beeline
                    client side.
!all                Execute the specified SQL against all the current connections
!autocommit         Set autocommit mode on or off
!batch              Start or execute a batch of statements
!brief              Set verbose mode off
!call               Execute a callable statement
!close              Close the current connection to the database
!closeall           Close all current open connections
!columns            List all the columns for the specified table
!commit             Commit the current transaction (if autocommit is off)
!connect            Open a new connection to the database.
!dbinfo             Give metadata information about the database
!describe           Describe a table
!dropall            Drop all tables in the current database
!exportedkeys       List all the exported keys for the specified table
!go                 Select the current connection
!help               Print a summary of command usage
!history            Display the command history
!importedkeys       List all the imported keys for the specified table
!indexes            List all the indexes for the specified table
!isolation          Set the transaction isolation for this connection
!list               List the current connections
!manual             Display the BeeLine manual
!metadata           Obtain metadata information
!nativesql          Show the native SQL for the specified statement
!nullemptystring    Set to true to get historic behavior of printing null as
                    empty string. Default is false.
!outputformat       Set the output format for displaying results
                    (table,vertical,csv2,dsv,tsv2,xmlattrs,xmlelements, and
                    deprecated formats(csv, tsv))
!primarykeys        List all the primary keys for the specified table
!procedures         List all the procedures
!properties         Connect to the database specified in the properties file(s)
!quit               Exits the program
!reconnect          Reconnect to the database
!record             Record all output to the specified file
!rehash             Fetch table and column names for command completion
!rollback           Roll back the current transaction (if autocommit is off)
!run                Run a script from the specified file
!save               Save the current variabes and aliases
!scan               Scan for installed JDBC drivers
!script             Start saving a script to a file
                    将一個指令儲存為腳本檔案
!set                Set a beeline variable
!sh                 Execute a shell command
                    執行一個本地指令,就不用在切出去執行了
!sql                Execute a SQL command
!tables             List all the tables in the database
!typeinfo           Display the type map for the current connection
!verbose            Set verbose mode on
 
Comments, bug reports, and patches go to ???
           

三、WebHCat

WebHCat是為HCatalog提供REST API的服務,自hive 0.11.0 版本之後,hive 中也自帶了 webhcat (官網介紹說明),如下圖,通過WebHCat,程式能夠通過REST的API很安全的連結和操作HCatalog提供的服務,友善Hive、Pig、MapReduce等應用使用。(類似于通過WebHDFS以web的方式來操作HDFS)

hive、impala的用戶端,cli、beeline、WebHCathive-cli和beeline差別 官網說明一、hive cli二、hive beeline三、WebHCat

繼續閱讀