SQL on Hadoop,
with ACID tables and interactive queries.
Hive reads, writes, and manages large volumes of data in distributed storage using SQL, with ACID transactions and interactive queries through LLAP. Follow a client query all the way down to the files.
Apache Hive is a data warehouse infrastructure built on Hadoop: it defines tables over files in HDFS and turns each SQL query into a plan of stages that runs on the cluster.
HiveServer2 receives the queries, and the Hive Metastore stores the table definitions.
In SQL
Tables over distributed files
Familiar SQL syntax serves data warehouse tasks, such as extract, transform, and load, reporting, and data analysis, over data that lives in distributed storage.
Plan and engine
Each query becomes a DAG of stages
The compiler generates the plan, and the execution engine hands it to Apache Tez, Apache Spark, or MapReduce, which run it on the cluster.
ACID and LLAP
Transactions and interactive queries
Transactional tables accept inserts, updates, and deletes, and LLAP brings interactive, sub-second SQL queries.
On this page
- Watch a query happen
- Architecture
- The address of a connection
- From the table to the file
- When the table is updated
- Execution engines and LLAP
- Why Hive
- In the TDP editions
Watch a query happen
Press Play or step through one at a time. Underlined names lead to the Glossary.
1 The client sends the query
A Beeline, JDBC, or ODBC client sends the SQL query to the HiveServer2 Thrift service, which serves several clients at the same time.
In the Glossary: Client · Thrift service · Beeline · HiveServer2
- The client sends the query. A Beeline, JDBC, or ODBC client sends the SQL query to the HiveServer2 Thrift service, which serves several clients at the same time.
- The Driver opens a session. The Driver creates the session handle for the query and passes it to the compiler, which parses it and performs semantic analysis on the query blocks and expressions.
- The compiler queries the Metastore. To generate the plan, the compiler fetches from the Metastore the metadata of the referenced tables and partitions. It uses this metadata to type-check the expressions and to prune partitions based on the query predicates.
- The plan is a DAG of stages. The generated plan is a DAG of stages: map or reduce jobs, metadata operations, or HDFS operations. The execution engine manages the dependencies between the stages.
- The stages go to the cluster. The execution engine submits the stages to the appropriate component: Apache Tez, Apache Spark, or MapReduce. In each task, the table's deserializer reads the rows from the HDFS files.
- The output goes to a temporary file. The serializer writes the output to a temporary file in HDFS, and the temporary files feed the next stages of the plan.
- The result returns to the client. For a query, the execution engine reads the contents of the temporary file directly from HDFS, as part of the Driver's fetch call, and the result returns to the client. For a DML operation, the final temporary file is moved to the table's location.
Architecture
HiveServer2 receives and compiles; the Metastore describes; the cluster executes; HDFS stores.
What the figure shows:
- The Beeline, JDBC, and ODBC clients talk to HiveServer2.
- The HiveServer2 Thrift service serves several clients at the same time, in TCP mode or HTTP mode.
- The compiler, which the Driver brings together, queries the Metastore and generates the plan.
- The execution engine, also brought together by the Driver, executes the plan and submits the stages to the cluster engines, Tez, Spark, or MapReduce.
- The Hive Metastore is a Thrift service backed by a metadata database, and it stores the structure of the tables and partitions and the location of the files in HDFS.
- The metadata database is part of the Metastore, together with the Thrift service.
- The YARN containers run the tasks of the plan.
- The LLAP daemons are optional and perform caching and fragment execution.
- HDFS stores the table files, read and written through the SerDe.
The address of a connection
A JDBC client reaches HiveServer2 through a URL with five parts.
Click each part of the address.
Prefix
The Hive JDBC connection URL format starts with this prefix. The rest of the URL indicates the host, the port, the database, and the HiveServer2 session options.
See in the Glossaryjdbc:hive2://— Prefix- The Hive JDBC connection URL format starts with this prefix. The rest of the URL indicates the host, the port, the database, and the HiveServer2 session options.
server— Server- The host where the HiveServer2 process runs.
:port— Port- The HiveServer2 port the client connects to.
/database— Database- The session's database: the namespace that avoids naming conflicts between tables, views, partitions, and columns.
;options— Session options- The session options, which complete the URL.
From the table to the file
Hive data is organized in levels: each level contains the next.
Level 1 of 5
Database
A namespace that avoids naming conflicts between tables, views, partitions, and columns.
- MetastoreStores the structure of all the tables and partitions in the warehouse: the columns and types, the serializers and deserializers needed, and the HDFS files where the data resides.
- Database. A namespace that avoids naming conflicts between tables, views, partitions, and columns.
- Metastore. Stores the structure of all the tables and partitions in the warehouse: the columns and types, the serializers and deserializers needed, and the HDFS files where the data resides.
- Table. A homogeneous unit of data, with a single schema, analogous to a table in a relational database. The data of each table lives in its own HDFS directory.
- Managed table. Hive manages the data: dropping the table removes both the definition and the data.
- External table. Created over files or directories that already exist, with the location given at creation. Dropping it removes only the definition.
- Transactional table. Supports ACID transactions: inserts, updates, and deletes, and a consistent snapshot for each query.
- Partition. Each table can have one or more partition keys, which determine how the data is stored. Each distinct combination of values in the partition columns gets its own data directory.
- Bucket. The data in each partition can be divided into buckets, by the hash of a table column. Each bucket is a file in the partition directory.
- File. The file where the data lives, in the storage format chosen when the table is created, such as text, ORC, Parquet, or Avro.
- SerDe. The piece that converts the table rows into files and back. A table uses a native SerDe or a custom one.
When the table is updated
In a transactional table, changes go to delta files, and compaction merges them later.
1 The table receives an update
A table with the transactional property can receive inserts, updates, and deletes. The transaction manager controls the locks and transactions in the Metastore.
In the Glossary: HiveServer2 · Transaction manager · Transactional table
- The table receives an update. A table with the transactional property can receive inserts, updates, and deletes. The transaction manager controls the locks and transactions in the Metastore.
- Changes go to delta files. New records, updates, and deletes are written to delta files. The table or partition data lives in the base files, each in its own directory.
- The read combines base and delta. When a query starts, it is given a consistent snapshot of the data. At read time, Hive merges the base and delta files, applying the updates and deletes.
- The Initiator notices the accumulated deltas. The Initiator discovers which tables and partitions are due for compaction. One of the criteria is the number of delta directories in a table or partition, which triggers a minor compaction.
- A Worker compacts. Each Worker handles a single compaction task. Minor compaction rewrites a set of deltas into a single delta per bucket, and major compaction is more expensive but more effective.
- The Cleaner deletes the leftovers. After compaction, and once they are no longer needed, the Cleaner deletes the old delta files.
Execution engines and LLAP
The plan belongs to Hive. A cluster engine executes the stages, and LLAP is an optional layer of daemons.
The execution engine hands the stages of the plan to one of these engines, which run them on the cluster.
In Tez, built on YARN, several reduce sinks are linked directly, the entire query plan is sent at once, and small datasets can be handled entirely in memory. In MapReduce, each job in the chain rereads the output of the previous job from HDFS.
LLAP daemons are long-lived, optional, stateless processes that replace direct interaction with the HDFS DataNode. Each request to a daemon carries the location and metadata of the data. On failure, any data node can process any fragment of the input.
Caching, pre-fetching, part of the query processing, and access control move into the daemon, which executes query fragments, such as filters, projections, and transformations. The unit of data in the cache is the column-chunk.
LLAP is not an execution engine, like MapReduce or Tez: it is aware of transactions and is a natural place to enforce access control at a finer level than per file.
Why Hive
SQL
Distributed data, familiar syntax
Reading, writing, and managing large volumes of data in distributed storage with SQL syntax, and extending Hive with user-defined functions (UDFs).
ACID
Transactions on tables
Full ACID support for ORC tables and insert-only support for all other formats, with data compaction.
LLAP
Interactive queries
Interactive, sub-second SQL queries through a persistent query infrastructure.
HiveServer2
Several clients at the same time
HiveServer2 serves JDBC and ODBC clients with concurrency and authentication.
Optimizer
Cost-based
The Apache Calcite optimizer and execution framework handle the plan of each query.
Sources and engines
HDFS, HBase, Tez, Spark, and MapReduce
Hive accesses files in HDFS or in other systems, such as Apache HBase, runs queries through Tez, Spark, or MapReduce, and offers the HPL-SQL procedural language.
Hive is a data warehouse infrastructure based on Apache Hadoop, designed to make data summarization, ad hoc querying, and analysis of large volumes easy. Its table catalog, the Hive Metastore, is now also used by other engines.
In the TDP editions
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 4.0.0 | TDP Datacenter components |
| TDP Kubernetes · Hive Metastore | 4.0.0 · chart tdp-hive-metastore 3.0.3 | Configuration in TDP Kubernetes |
In TDP Datacenter
In TDP Datacenter, Hive is the HIVE service, installed and managed by Ambari. The Hive Metastore is a component of that service, and it has its own page.
HIVE_CLIENT (client, one or more), HIVE_METASTORE (master, one or more), HIVE_SERVER (master, one or more), HIVE_SERVER_INTERACTIVE (master, optional) and MYSQL_SERVER (master, optional, one instance). The HIVE_SERVER requires ZOOKEEPER_SERVER (ZooKeeper), TEZ_CLIENT (Tez), YARN_CLIENT (YARN), MAPREDUCE2_CLIENT (MapReduce) and ZOOKEEPER_CLIENT (ZooKeeper). The HIVE_SERVER_INTERACTIVE requires ZOOKEEPER_SERVER (ZooKeeper), YARN_CLIENT (YARN), HDFS_CLIENT (HDFS), MAPREDUCE2_CLIENT (MapReduce) and TEZ_CLIENT (Tez). Component category.
The transport mode is configurable in hive.server2.transport.mode, and the ports in hive.server2.thrift.port and hive.server2.thrift.http.port, in the hive-site configuration. SSL usage is configurable in hive.server2.use.SSL.
The mechanism is configurable in hive.server2.authentication, with dedicated properties for Kerberos, such as hive.server2.authentication.kerberos.principal, for LDAP, such as hive.server2.authentication.ldap.url, for PAM, in hive.server2.authentication.pam.services, and for a custom class, in hive.server2.custom.authentication.class.
The Ranger plugin can be enabled in ranger-hive-plugin-enabled, in the ranger-env configuration. Authorization is configurable in hive.security.authorization.enabled and hive.security.authorization.manager. See Security in TDP Datacenter.
The cost-based optimizer is configurable in hive.cbo.enable, and vectorized execution in hive.vectorized.execution.enabled. The service memory is configurable in hive.heapsize (hive-env).
The transaction manager and concurrency are configurable in hive.txn.manager and hive.support.concurrency. Compaction is configurable in hive.compactor.initiator.on and hive.compactor.worker.threads (hivemetastore-site), and the number of delta directories that triggers it in hive.compactor.delta.num.threshold.
The LLAP configuration lives in the service's hive-interactive-site and hive-interactive-env configurations, such as hive.llap.io.enabled, hive.llap.io.memory.size, num_llap_nodes, and llap_heap_size.
The directories of managed and external tables are configurable in hive.metastore.warehouse.dir and hive.metastore.warehouse.external.dir.
Sending metadata to Atlas can be enabled in hive.atlas.hook (hive-env).
These services require this one in the cluster: Spark.
Trino accesses it through the Hive connector, which can be enabled in use.hive (connectors-properties). Airflow reaches it through the apache-airflow-providers-apache-hive provider, JupyterLab through the impyla library, and NiFi through the Hive components, in nifi-hive3-nar.
In TDP Kubernetes
In TDP Kubernetes, the Hive table catalog is delivered by the Hive Metastore, installed by its own chart. Its page describes the chart, the metadata database, the warehouse, and the engines that query it.
Next steps
TDP Datacenter
TDP Datacenter Architecture
The services of the cluster managed by Ambari and how they relate to each other.
Concept
Hive Metastore
The catalog that stores the table definitions and serves them to several engines.
Sources
Apache Hive - HiveServer2 Overview