初识beeline客户端,初识beeline


Hive提供了两种客户端访问工具,分别是通过Hive命令行和beeline客户端。
命令行方式即通过hive进入命令模式后通过执行不同的HQL命令得到对应的结果;相当于胖客户端模式,即客户机中需要安装JRE环境和Hive程序。
beeline客户端方式相当于瘦客户端模式,采用JDBC方式借助于Hive Thrift服务访问Hive数据仓库。

Beeline工作模式有两种,即本地嵌入模式和远程模式。嵌入模式情况下,它返回一个嵌入式的Hive(类似于Hive CLI)。而远程模式则是通过Thrift协议与某个单独的HiveServer2进程进行连接通信。
HiveThrift(HiveServer)是Hive中的组件之一,设计目的是为了实现跨语言轻量级访问Hive数据仓库,有Hiveserver和Hiveserver2两个版本,两者不兼容,要注意区分;体现在启动HiveServer的参数和jdbc:hiveX的参数上。
后台服务启动:
# nohup hive –service hiveserver2 & 
ps -ef | grep Hive
beeline启动和hive连接
[hadoop@emr-header-1 ~]$ beeline 
Beeline version 1.6.1 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000/default
Connecting to jdbc:hive2://localhost:10000/default
Enter username for jdbc:hive2://localhost:10000/default: 
Enter password for jdbc:hive2://localhost:10000/default: 
18/01/18 13:49:37 INFO jdbc.Utils: Supplied authorities: localhost:10000
18/01/18 13:49:37 INFO jdbc.Utils: Resolved authority: localhost:10000
18/01/18 13:49:37 INFO jdbc.HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
Connected to: Apache Hive (version 2.0.1)
Driver: Spark Project Core (version 1.6.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000/default> 
进入beeline之后,连接Hive客户端的方式。
!connect jdbc:hive2://localhost:10000/default
!connect jdbc:hive2://内外网地址:10000/default
退出beeline命令行则是!quit, 很多命令都是前面需要加一个感叹号, 但对于登录了后的DDL,DML,则直接运行SQL语句即可,语句后带上一个分号,然后回车执行。
Beeline和其他工具有一些不同,执行查询都是正常的SQL输入,但是如果是一些管理的命令,比如进行连接,中断,退出,执行Beeline命令需要带上“!”,不需要终止符。如:
1、!connect url –连接不同的Hive2服务器
2、!exit –退出shell
3、!help –显示全部命令列表
Beeline与Hive CLI不同的几点说明:
The primary difference between the two involves how the clients connect to Hive.
The Hive CLI connects directly to the Hive Driver and requires that Hive be installed on the same machine as the client. 
Beeline connects to HiveServer2 and does not require the installation of Hive libraries on the same machine as the client. Beeline is a thin client that also uses the Hive JDBC driver but instead executes queries through HiveServer2, which allows multiple concurrent client connections and supports authentication.

hive cli 之于hive 就相当于sql plus之于oracle. 需要和server安装在一起。
而beeline只需要一个jdbc jar包就可以了,可以不需要与hive server 2装在一台server。

涉及本地的两个操作在beeline上不被支持:
1.load data local inpath is not support in beeline.
2.insert overwrite local directory is not support in beeline.


查看评论

相关内容