The full systemHive
Hive gives SQL access to large data files. The files are in HDFS or S3.
Hive has two server parts: HiveServer2 and the Metastore service. The Metastore service keeps its catalog in a backing database.
Hive does not keep the data rows. HDFS or S3 keeps the data files.
Server · runs queriesHiveServer2
HiveServer2 is a server. It gets SQL from clients and runs it.
- It checks the user and the permissions.
- It gets table information from the Metastore service.
- It runs a job on the cluster (Tez or MapReduce). For a very simple query, it reads the files without a job.
- It sends the result to the client.
Address: jdbc:hive2://host:10000
Execution engineTez
Tez does the work for HiveServer2. HiveServer2 changes the SQL into a Tez job.
The job is a graph of steps (a DAG). Tez runs the steps in YARN containers. It sends data between steps without a write to HDFS.
Tez is faster than MapReduce. PySpark jobs do not use Tez.
Setting: hive.execution.engine = tez
Service · catalog brokerMetastore service
The Metastore service is a broker for the table catalog. The catalog itself is in the backing database.
Clients send Thrift requests to the service. The service reads or writes the backing database. Then it sends the answer to the client.
The service does not keep data rows. It does not run queries.
HiveServer2, Spark, Impala and Trino use this service.
Address: thrift://host:9083
Setting: hive.metastore.uris
Relational database · the catalogBacking database
This is a normal database, for example MySQL, PostgreSQL or Oracle. People also call it the Metastore database.
This database is the catalog. For each table, it keeps the name, columns, file location, file format and partitions.
Only the Metastore service connects to it. Clients must not connect to it.
Setting: javax.jdo.option.ConnectionURL
Example: jdbc:mysql://dbhost/metastore
Protocol · not a serverThrift
Thrift lets a program call a function on a different computer.
Thrift is not a server. It is the method that two programs use to talk on the network.
The Metastore service uses Thrift. Spark and HiveServer2 call functions such as get_table through Thrift.
The HiveServer2 JDBC driver also uses Thrift inside.
Seen as: thrift:// in an address
Client toolBeeline
Beeline is a command-line SQL client.
It connects to HiveServer2 through JDBC. It accepts typed SQL or an .hql file.
Beeline does not run the query. HiveServer2 runs the query.
Example: beeline -u jdbc:hive2://host:10000 -f load.hql
Workflow stepOozie hive2 action
Oozie is a workflow scheduler. A hive2 action is one step in an Oozie workflow.
The step starts a launcher job on YARN. The launcher runs Beeline. Beeline sends the .hql script to HiveServer2.
On a Kerberos cluster, the step needs a hive2 credential.
Setting: <jdbc-url> = the HiveServer2 address
Compute engineSpark with Hive support
enableHiveSupport() connects Spark to the Metastore service.
Spark does not use HiveServer2 or Beeline. Spark gets the table information. Then Spark reads the files itself.
If hive.metastore.uris is empty, Spark uses a local Derby database. Then the cluster tables are not visible.
Temp views and spark.sql() on temp views do not need Hive.
Main setting: hive.metastore.uris
File storageHDFS / S3
HDFS and S3 keep the data files.
The Metastore service tells tools where the files are. Spark then reads the files directly. HiveServer2 starts a Tez job that reads the files.
Remember: the backing database keeps metadata. HDFS keeps data.
Example: hdfs://namenode:8020/user/hive/warehouse/mydb.db/mytable