The Two Ways of Connecting Hive For Developing or Testing

hive

Hive CLI

Hive CLI a legacy tool that had two main use cases. The first is that it served as a thick client for SQL on Hadoop. And the second is that it served as a command-line tool for Hiver Server. Hive Server had been deprecated and removed from Hive. So, it is not an ideal way to connect Hive by using Hive CLI.

Command below for using Hive CLI.

1
hive

Beeline CLI

It is a client tool for connecting Hive Server2 through JDBC. Then you can use SQL to obtain or process data.
Because of using JDBC, there are two tunnels for transmitting data. The first way is zookeeper which is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. The second way is the apache thrift server which is RPC framework for scalable cross-language service development.

Before we use beeline, we need to get TGT from TGS for using hive service when your Hadoop clusters using Kerberos authorization. After that, you can use Hive directly.

1
kinit -kt [your hive service keytab file path] [your hive service principal]

You can checkout your kerberos.csv file to get a specific service keytab file path and service principal.

  1. Zookeeper
1
2
3
beeline 

!connect jdbc:hive2://bigdata.com:2181/sephora;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;principal=hive/bigdata.com@CONNEXT.COM

So, you maybe want to get your own JDBC connection URL by using zookeeper. You can visit your own Ambari UI, then click “[Services]->[Hive]”. In your hive dashboard, you can get your own URL.

JDBC URL by using zookeeper

After this, we may be encounter a bug that needs to input username and password. So, just click “Enter” two times because of owning the authorization for hive service.

https://issues.apache.org/jira/browse/HIVE-9144

zookeeper

  1. Thrift Server
1
2
3
beeline

!connect jdbc:hive2://bigdata.com:10001/sephora;transportMode=http;httpPath=cliservice;principal=hive/bigdata.com@CONNEXT.COM

We can get parameter values by visiting Ambari UI and checking the configuration of Hive.

jdbc url by using thrift

Just like using zookeeper, we also encounter that bug. So, just click “Enter” two times.

thrift