Hive官方使用手冊——新Hive CLI(Beeline CLI)

來源:互聯網
上載者:User

本文為自己翻譯的譯文,原文地址:https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients


Hive官方使用手冊——新Hive CLI(Beeline CLI)

這個頁面描述了HiveServer2支援的不同用戶端。其它的HiveServer2文檔包含: HiveServer2 Overview Setting Up HiveServer2 Hive Configuration Properties:  HiveServer2

Version

Introduced in Hive version 0.11. See HIVE-2935. Beeline – Command Line Shell Beeline-命令列shell

HiveServer2 支援一個命令列shellBeeline。它是一種基於SQLline CLI 的JDBC用戶端(http://sqlline.sourceforge.net/)。SQLLine的細節文檔串連,它同樣也適用於Beeline。

使用Beeline代替Hive CLI實現

同時支援嵌入模式和遠程模式。在嵌入模式中,它運行一個嵌入的Hive(類似舊的Hive CLI)然而遠程模式是通過Thrift串連一個分離的HiveServer2進程。從Hive 0.1.4版本開始,Beeline已經被HiveServer2使用,它也會為它執行的查詢從HiveServer2列印日誌資訊到STDERR。遠程HiveServer2模式是Hive產品使用的推薦模式,它更加安全並且不需要直接為使用者對HDFS/metastore進行賦權。

在遠程模式中HiveServer2隻接受認證的Thrift 串連請求甚至在HTTP模式中也一樣,資訊主體班號Thrift payload Beeline 範例

% bin/beeline Hive version 0.11.0-SNAPSHOT by Apachebeeline> !connect jdbc:hive2://localhost:10000 scott tiger!connect jdbc:hive2://localhost:10000 scott tiger Connecting to jdbc:hive2://localhost:10000Connected to: Hive (version 0.10.0)Driver: Hive (version 0.10.0-SNAPSHOT)Transaction isolation: TRANSACTION_REPEATABLE_READ0: jdbc:hive2://localhost:10000> show tables;show tables;+-------------------+|     tab_name      |+-------------------+| primitives        || src               || src1              || src_json          || src_sequencefile  || src_thrift        || srcbucket         || srcbucket2        || srcpart           |+-------------------+9 rows selected (1.079 seconds)

 

 你也可以在命令列上指定串連參數。這意味著你能夠從你的UNIX Shell history中發現串連時使用的命令。

% beeline -u jdbc:hive2://localhost:10000/default -n scott -w password_fileHive version 0.11.0-SNAPSHOT by ApacheConnecting to jdbc:hive2://localhost:10000/default

Beeline with NoSASL connection

如果你喜歡通過NOSASL模式建立串連,你必須明確的指定認證模式。:

% bin/beelinebeeline> !connect jdbc:hive2://<host>:<port>/<db>;auth=noSasl hiveuser pass 
Beeline Commands

Command

Description

!<SQLLine command>

SQLLine命令清單請訪問http://sqlline.sourceforge.net/

範例:使用 !quit 退出Beeline用戶端。

!delimiter

設定在Beeline中寫查詢的界定符。允許使用多字元界定符,但是引號,斜杠和--是不允許的。預設是分號;

用例: !delimiter $$

Version: 3.0.0 (HIVE-10865)

Beeline Hive Commands

當使用HiveJDBC驅動時Hvie 內建的命令(和Hive CLI 命令列)也能在Beeline中運行,.

使用分號";"來結束命令,指令碼中可以用"--"作為首碼來標識命令。

命令

描述

reset

重設配置為預設值。

set <key>=<value>

為特定的組態變數(key)設定值。
註:如果你們拼字錯了變數名,CLI將不會提示錯誤。

set

列印一個被使用者或者Hive重寫的組態變數清單。

set -v

列印所有的Hadoop和Hive的組態變數。

add FILE[S] <filepath> <filepath>* 
add JAR[S] <filepath> <filepath>* 
add ARCHIVE[S] <filepath> <filepath>*

增加一個或者多個檔案,jar包或者壓縮包到分布式緩衝的資源清單中。查閱Hive Resources擷取更多資訊。

add FILE[S] <ivyurl> <ivyurl>* 
add JAR[S] <ivyurl> <ivyurl>* 
add ARCHIVE[S] <ivyurl> <ivyurl>*
自Hive 1.2.0起,增加一個或者多個檔案,jar包或者壓縮包到分布式緩衝的資源清單中使用類似ivy://group:module:version?query_string的lvy URL。查閱Hive Resources擷取更多資訊。

list FILE[S] 
list JAR[S] 
list ARCHIVE[S]

列出已經增加到分布式緩衝的資源。查閱Hive Resources擷取更多資訊(As of Hive 0.14.0: HIVE-7592)。

list FILE[S] <filepath>* 
list JAR[S] <filepath>* 
list ARCHIVE[S] <filepath>*

檢查是否給定的資源已經被添加到分布式緩衝中。查閱Hive Resources擷取更多資訊。

delete FILE[S] <filepath>* 
delete JAR[S] <filepath>* 
delete ARCHIVE[S] <filepath>*

移除分布式緩衝中的一些資源。

delete FILE[S] <ivyurl> <ivyurl>* 
delete JAR[S] <ivyurl> <ivyurl>* 
delete ARCHIVE[S] <ivyurl> <ivyurl>*

自Hive 1.2.0起,移除通過<ivyurl> 添加到分布式緩衝中的資源。查閱Hive Resources擷取更多資訊。

reload 從Hive 0.14.0起,通過配置參數hive.reloadable.aux.jars.path(不需要重啟HiveServer2)指定路徑使HiveServer2 感知到任意jar包的變化。這裡的變化包括增加,刪除,或者更新jar包。

dfs <dfs command>

通過Hive shell執行一個dfs命令。

<query string>

執行一個Hive查詢語句並且輸出標準輸出。

Beeline 命令列選項

Beeline CLI支援以下這些命令列選項:

選項

描述

-u <database URL>

用於JDBC URL串連。

用例:beeline -u db_URL

-r

重新串連到最近使用過的URL(如果使用者有預先使過的用的,用!connect產生URL,用!save 產生beeline.properties.file)。

用例: beeline -r  

Version: 2.1.0 (HIVE-13670)

-n <username>

串連時使用的使用者名稱。

用例: beeline -n valid_user

-p <password>

串連時使用的密碼。

用例: beeline -p valid_password

可選的Cipher 模式:

從Hive 2.2.0開始參數-p選項是可選的。

用例 : beeline -p [valid_password]

如果密碼不是在-p之後提供的,Beeline將在初始化串連時提示輸入密碼。當密碼提供後Beeline會用它來初始化串連而不提示。

-d <driver class>

配置使用的驅動類

用例: beeline -d driver_class

-e <query>

應該執行的查詢。查詢語句兩端用單引號和雙引號。這個選項被使用多次。

用例: beeline -e "query_string"

支援運行複雜的SQL語句,在一個語句中通過使用分號分隔。 (HIVE-9877)
Bug fix (null pointer exception): 0.13.0 (HIVE-5765)
Bug fix (--headerInterval not honored): 0.14.0 (HIVE-7647)
Bug fix (running -e in background): 1.3.0 and 2.0.0 (HIVE-6758); workaround available for earlier versions 

-f <file>

需要被執行的指令檔。

用例: beeline -f filepath

Version: 0.12.0 (HIVE-4268)
註:如果指令碼裡麵包含tabs,版本0.12.0中查詢編譯失敗,這個bug已經在0.13.0版本修複了。 (HIVE-6359).
Bug fix (running -f in background): 1.3.0 and 2.0.0 (HIVE-6758); workaround available for earlier versions 

-i (or) --init <file or files>

初始化需要的初始檔案。

用例: beeline -i /tmp/initfile

單個檔案:

Version: 0.14.0 (HIVE-6561)

多個檔案:

Version: 2.1.0 (HIVE-11336)

-w (or) --password-file <password file>

從檔案中讀取密碼。

Version: 1.2.0 (HIVE-7175)

-a (or) --authType <auth type>

jdbc的認證類型是一個身份認證屬性。

Version: 0.13.0 (HIVE-5155)

--property-file <file>

讀取配置屬性的檔案

用例: beeline --property-file /tmp/a

Version: 2.2.0 (HIVE-13964)

--hiveconf property=value

為給定的配置屬性賦值。 在hive.conf.restricted.list列表中的屬性不能通過hiveconf的方式重設。 (see Restricted List and Whitelist).

用例: beeline --hiveconf prop1=value1

Version: 0.13.0 (HIVE-6173)

--hivevar name=value

Hive的變數名和變數值。這是一個Hive指定的設定,在這變數能夠在會話層級被設定和被Hive命令和查詢引用。

用例: beeline --hivevar var1=value1

--color=[true/false]

控制顏色是否被用來展示。預設是false

用例: beeline --color=true

(不支援分隔的值輸出方式。See HIVE-9770)

--showHeader=[true/false]

展示列名是否在查詢結果中。預設是true。

用例: beeline --showHeader=false

--headerInterval=ROWS

當輸出為表格時,重新顯示列頭時他們之間的間隔,用行數計算。預設值為100

用例: beeline --headerInterval=50

(不支援分隔的值輸出方式。See HIVE-9770)

--fastConnect=[true/false]

串連時,跳過為HiveQL文法的tab鍵自動補全功能而構建所有表和列的清單,預設為true不構建該列表。

用例: beeline --fastConnect=false

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.