Using the Hive command

Hive first started with hiveserver1. However, this version of Hive server was not very stable. It sometimes suspended or blocked the client's connection quietly. Since v0.11.0, Hive has included a new thrift server called hivesever2 to replace hiveserver1. hiveserver2 has an enhanced server designed for multiple client concurrency and improved authentication. It also recommends using beeline as the major Hive command-line interface instead of the hive command. The primary difference between the two versions of servers is how the clients connect to them. hive is an Apache-Thrift-based client, and beeline is a JDBC client. The hive command directly connects to the Hive drivers, so we need to install the Hive library on the client. However, beeline connects to hiveserver2 through JDBC connections without installing Hive libraries on the client. That means we can run beeline remotely from outside the cluster. For more usage of hiveserver2 and its API access, refer to https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients.

The following two tables list the commonly-used commands in different command modes considering different user preferences:

Purpose

hiveserver2 - beeline

hiveserver1 - hive

Connect server

beeline –u <jdbc_url>

hive -h <hostname> -p <port>

Help

beeline -h

hive -H

Run query

beeline -e "hql query"
beeline -f hql_query_file.hql
beeline -i hql_init_file.hql

hive -e "hql query"
hive -f hql_query_file.hql
hive -i hql_init_file.hql

Set

variable

beeline --hivevar var_name=var_value

hive --hivevar var_name=var_value

Purpose

hiveserver2 - beeline

hiveserver1 - hive

Enter mode

beeline

hive

Connect server

!connect <jdbc_url>

N/A

List tables

!table
show tables; --also support

show tables;

List columns

!column table_name
desc table_name;

desc table_name;

Run query

select * from table_name;

select * from table_name;

Save result

!record result_file.dat
!record

N/A

Run shell cmd

!sh ls

!ls;

Run dfs cmd

dfs -ls;

dfs -ls;

Run hql file

!run hql_query_file.hql

source hql_query_file.hql;

Quit mode

!quit

quit;

In addition, Hive configuration settings and properties can be accessed and overwritten by the SET keyword in the interactive mode. For more details, refer to the Apache Hive wiki at https://cwiki.apache.org/confluence/display/Hive/Configuration+Properties.
For beeline, ; is not needed after the command that starts with !. Both commands do not support running a pasted query with <tab> inside, because <tab> is used for auto-complete by default in the environment. Alternatively, running the query from files has no such issues. In interactive mode, we can use the keyboard's up and down arrow keys to retrieve the previous commands. The !history command can be used in beeline to show the command's history.  In addition, the dfs command may be disabled in beeline for permissions control in some Hadoop distributions. Both commands support variable substitution, which refers to https://cwiki.apache.org/confluence/display/Hive/LanguageManual+VariableSubstitution.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.229.111