Beeline is developed to interact with new server. Hive CLI is an Apache Thrift based client, whereas Beeline is JDBC client, based on SQLLine CLI. In this article, we will check difference between Hive CLI and Beeline client – Hive vs Beeline.
Difference Between Hive CLI and Beeline Client – Hive vs Beeline
Below are the some of the difference between Hive CLI and Beeline client. These some of differences will help you in case if you are migrating from old Hive CLI to new Beeline client.
Server Connection
Hive CLI
Hive CLI uses HiveServer1. Hive CLI connects to a remote HiveServer1 instance using the Thrift protocol. To connect to a server, you must specify the host name. The port number is optional.
$hive -h <host_name> -p <port>
Beeline
Beeline connects to a remote HiveServer2 instance using JDBC. The connection parameter includes JDBC URL.
$ beeline -u <url> -n <username> -p <password>
For more information on connection parameters and URL read:
Interactive Mode
Hive CLI
In Hive CLI interactive mode, you can execute any HiveQL query:
hive> show databases; OK Default test_db
You can also execute shell commands from Hive CLI:
hive> !more myfile.txt; This is a test file.hive>
Beeline
You can execute HiveQL same as Hive CLI:
https://gist.github.com/cb05183a779487cc2a92c7bee02078ec
You can use “!” to execute Beeline commands instead of shell commands.
For examples, !connect is used to connect to database:
https://gist.github.com/913d57c9949d9eedb2680b70866f401d
And !quit is another command that can be used to exit Beeline client.
0: jdbc:hive2://> !q Closing: 0: jdbc:hive2:// $
Embedded Mode
Embedded mode is one of the convenient and best way to test your code. Both Hive CLI and Beeline support embedded mode.
Hive CLI
To start Hive CLI in embedded mode, you just should type start Hive client without any parameters:
$ hive
Beeline
To start Beeline in embedded mode, a connection URL of jdbc:hive2:// needs to be specified:
$ beeline -u jdbc:hive2://
HiveQL Query Execution
Query execution in both Hive CLI and Beeline is same.
Hive CLI
$ hive -e <query in quotes>$ hive -f <query file name>
Beeline
$ beeline -e <query in quotes>$ beeline -f <query file name>
In both cases, if you miss to provide -e and -f options, client will enter interactive mode.
Variable Substitution
Both Hive CLI and Beeline support variable substitution.
Hive CLI
You can use set command to set variables and pass that as parameter to script:
$ hive --hiveconf var=value -e 'set var; set hiveconf:var; select * from table where col = ${hiveconf:var}'
For more information read:
Beeline
You can use –hivevar variable to pass value to script file:
$ beeline -u jdbc:hive2://hive_server:10000/test_db -n username -p password --hivevar var1=value -f file.sql
For more information read: