Hive Beeline 官方文檔學習


Beeline 是什么?

它是一個命令行形式的jdbc客戶端。搞Java開發的同學,看到這里就應該知道這貨是什么了 ── 它是一個連接數據庫的工具。

只不過Beeline連接的數據庫是HiveServer2。

 

Beeline 有兩種工作模式:內嵌、遠程。

內嵌模式中,會運行一個內嵌的Hive(類似於Hive CLI)。

遠程模式中,通過Thrift協議連接到一個不同的HiveServer2。從Hive 0.14起,Beeline連接HiveServer2 時,還會將HiveServer2 執行查詢的日志信息輸出到STDERR。

-- 推薦在生產中使用遠程模式,因為更安全,且無需 HDFS/metastore 的訪問授權。

注意,在遠程模式下,HiveServer2 只接受有效的Thrift 請求 -- 就算是在HTTP模式中,消息體也需要包含Thrift payload。

 

Beeline 的使用示例

[root@elephant ~]# beeline 
Beeline version 1.1.0-cdh5.6.0 by Apache Hive
beeline> help
!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 ???
beeline> !connect jdbc:hive2://localhost:10000
beeline> !tables;
No current connection
beeline> !connect jdbc:hive2://elephant:10000
scan complete in 2ms
Connecting to jdbc:hive2://elephant:10000
Enter username for jdbc:hive2://elephant:10000: hive
Enter password for jdbc:hive2://elephant:10000: **********
Connected to: Apache Hive (version 1.1.0-cdh5.6.0)
Driver: Hive JDBC (version 1.1.0-cdh5.6.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://elephant:10000>

上面,通過help查詢了Beeline 支持的命令,又通過 !connect jdbc:hive2://elephant:10000 連接到 elephant主機上的HiveServer2。

下面就來看看還能執行什么操作。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

參考:

https://cwiki.apache.org//confluence/display/Hive/HiveServer2+Clients

http://blog.csdn.net/huanggang028/article/details/44591663


免責聲明!

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



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